49 lines
1.5 KiB
Ruby
49 lines
1.5 KiB
Ruby
require "language/node"
|
|
require "json"
|
|
|
|
class Babel < Formula
|
|
desc "Compiler for writing next generation JavaScript"
|
|
homepage "https://babeljs.io/"
|
|
url "https://registry.npmjs.org/@babel/core/-/core-7.15.8.tgz"
|
|
sha256 "33091e6edf24ee719166645ba6807c1d179d28d88965977fe04da9c5ffadf397"
|
|
license "MIT"
|
|
|
|
bottle do
|
|
sha256 cellar: :any_skip_relocation, all: "21de12960426e5e3f5350d6fdddfac2fd93fd2eb21bb5afc1d501241097911ad"
|
|
end
|
|
|
|
depends_on "node"
|
|
|
|
resource "babel-cli" do
|
|
url "https://registry.npmjs.org/@babel/cli/-/cli-7.15.7.tgz"
|
|
sha256 "027d695a5ad68347b6f4fc7aac8ce66fe000576952a9ce38769cf12988f1a34a"
|
|
end
|
|
|
|
def install
|
|
(buildpath/"node_modules/@babel/core").install Dir["*"]
|
|
buildpath.install resource("babel-cli")
|
|
|
|
cd buildpath/"node_modules/@babel/core" do
|
|
system "npm", "install", *Language::Node.local_npm_install_args, "--production"
|
|
end
|
|
|
|
# declare babel-core as a bundledDependency of babel-cli
|
|
pkg_json = JSON.parse(File.read("package.json"))
|
|
pkg_json["dependencies"]["@babel/core"] = version
|
|
pkg_json["bundleDependencies"] = ["@babel/core"]
|
|
File.write("package.json", JSON.pretty_generate(pkg_json))
|
|
|
|
system "npm", "install", *Language::Node.std_npm_install_args(libexec)
|
|
bin.install_symlink Dir["#{libexec}/bin/*"]
|
|
end
|
|
|
|
test do
|
|
(testpath/"script.js").write <<~EOS
|
|
[1,2,3].map(n => n + 1);
|
|
EOS
|
|
|
|
system bin/"babel", "script.js", "--out-file", "script-compiled.js"
|
|
assert_predicate testpath/"script-compiled.js", :exist?, "script-compiled.js was not generated"
|
|
end
|
|
end
|