homebrew-core/Formula/balena-cli.rb

72 lines
2.9 KiB
Ruby

require "language/node"
class BalenaCli < Formula
desc "Command-line tool for interacting with the balenaCloud and balena API"
homepage "https://www.balena.io/docs/reference/cli/"
url "https://registry.npmjs.org/balena-cli/-/balena-cli-14.3.1.tgz"
sha256 "0a1c4034b3a073352f05df9480da5c1afcb430ad252fc41daf5c3a002b9e13b2"
license "Apache-2.0"
livecheck do
url "https://registry.npmjs.org/balena-cli/latest"
regex(/["']version["']:\s*?["']([^"']+)["']/i)
end
bottle do
sha256 arm64_monterey: "c5aaa0a148495be2c172d89c3f3bf32d97e8c56255abc1f5183eb752356cb0e8"
sha256 arm64_big_sur: "7affd060c24c9747fb81a471eaa7391aa330b86f74476a1490382e66b56703d3"
sha256 monterey: "2cf4b356f5a4da29aef99b9c8f7a2fdab128bb1a819a350fa40f830fbc02a2f7"
sha256 big_sur: "3001391c73ec4b489ca14710480dca28c4e028f3f1d73e9c6dbccace2a1af057"
sha256 catalina: "490fcfeef05e5f3addee1cb4e2723ff563f738ed47a2e22644fff2591abe1049"
sha256 cellar: :any_skip_relocation, x86_64_linux: "9831411ab770f3dcd44740b2d7a37bd54ce96f2138efa4ee304fa2a1547d895b"
end
# Node looks for an unversioned `python` at build-time.
depends_on "python@3.10" => :build
depends_on "node@14"
on_macos do
depends_on "macos-term-size"
end
def install
ENV.deparallelize
ENV.prepend_path "PATH", Formula["python@3.10"].opt_libexec/"bin"
system "npm", "install", *Language::Node.std_npm_install_args(libexec)
(bin/"balena").write_env_script libexec/"bin/balena", PATH: "#{Formula["node@14"].opt_bin}:$PATH"
# Remove incompatible pre-built binaries
os = OS.kernel_name.downcase
arch = Hardware::CPU.intel? ? "x64" : Hardware::CPU.arch.to_s
node_modules = libexec/"lib/node_modules/balena-cli/node_modules"
node_modules.glob("{ffi-napi,ref-napi}/prebuilds/*")
.each { |dir| dir.rmtree if dir.basename.to_s != "#{os}-#{arch}" }
term_size_vendor_dir = node_modules/"term-size/vendor"
term_size_vendor_dir.rmtree # remove pre-built binaries
if OS.mac?
macos_dir = term_size_vendor_dir/"macos"
macos_dir.mkpath
# Replace the vendored pre-built term-size with one we build ourselves
ln_sf (Formula["macos-term-size"].opt_bin/"term-size").relative_path_from(macos_dir), macos_dir
unless Hardware::CPU.intel?
# Replace pre-built x86_64 binaries with native binaries
%w[denymount macmount].each do |mod|
(node_modules/mod/"bin"/mod).unlink
system "make", "-C", node_modules/mod
end
end
end
# Replace universal binaries with their native slices.
deuniversalize_machos
end
test do
assert_match "Logging in to balena-cloud.com",
shell_output("#{bin}/balena login --credentials --email johndoe@gmail.com --password secret 2>/dev/null", 1)
end
end