使用brew在全局安装npm软件包

时间:2019-08-15 16:39:44

标签: node.js npm homebrew package-managers npm-scripts

我想提供使用NodeJs开发的CLI工具,并且我尝试使用yum而不是使用npm进行全局安装,因为我不希望用户要求安装Nodejs和npm。不知道该怎么做?

替换

npm install -g my-cli-tool

使用

brew install my-cli-tool

因此,用户不必安装NodeJ和Npm。需要将整个Nodejs运行时环境+我的软件包打包为Brew软件包。

1 个答案:

答案 0 :(得分:0)

您需要自己编写自制公式。我会为您提供一些有用的资源。

  1. 阅读Node for Formula Author Documentation,尤其是最后的公式示例。

  2. 使用 <?php require_once 'conn.php'; $names = $_GET['term']; $names = array(); $names = $conn->real_escape_string($names); $stmt = $conn->query("SELECT Student_Name FROM `stndb` WHERE Div_No='$names'"); $rows = $stmt->num_rows; if($rows > 0){ while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $names[] = $row['Student_Name']; } } echo json_encode($names); ?> 作为依赖项列出相似的公式。使用这些现有公式作为参考。

    node

这里是一个示例

brew uses node

# check one of them, like this "cash-cli"
brew edit cash-cli

应在自定义公式中删除require "language/node" class CashCli < Formula desc "Convert currency rates directly from your terminal" homepage "https://github.com/xxczaki/cash-cli" url "https://registry.npmjs.org/cash-cli/-/cash-cli-4.0.0.tgz" sha256 "c8b1d437305bc4c492cb9b85bb1b91edb5cc74fa91bd007616746c6258dae6c5" bottle do cellar :any_skip_relocation sha256 "c78661062dbc6e913d0f69f45af80af1f9967e50fe1eca86a95337ab16fac7ea" => :mojave sha256 "6b8215de6daf01c61e48bd46465be7ad9b400d4ec5ab514f5167bee787d6fa48" => :high_sierra sha256 "5941317cef9b92097c4b45df1e94b7b8d08e708d9813508ab3f42f55068541d3" => :sierra end depends_on "node" def install system "npm", "install", *Language::Node.std_npm_install_args(libexec) bin.install_symlink Dir["#{libexec}/bin/*"] end test do assert_match "Conversion of USD 100", shell_output("#{bin}/cash 100 USD PLN CHF") end end 部分。

最后,维护一个水龙头,然后从该水龙头安装公式。