【问题标题】:NPM call bash script with multiple argumentsNPM 调用具有多个参数的 bash 脚本
【发布时间】:2018-11-25 11:48:46
【问题描述】:

我创建了一个 bash 脚本来自动化 git 发布流程。该脚本采用一个或多个分支名称作为参数。

我可以在终端调用脚本:./releaseGit.sh -b branch1 -b branch2

但我想将脚本与 npm 一起使用。我当前的 package.json 包含:

"scripts": {
   (other scripts..)
   "git-release": "scripts/releaseGit.sh -b $*"
}

但是使用这种配置,我只能将一个分支作为参数传递给脚本。我该如何改变呢?

作品:

npm run git-release -b only-one-branch

不起作用:

npm run git-release -b first-branch -b second-branch

【问题讨论】:

  • 传递参数时需要-- - 删除脚本中的占位符并调用npm run git-release -- -b first-branch -b second-branch。见the docs
  • 它有效。谢谢!

标签: bash npm npm-scripts


【解决方案1】:

包.json:

scripts: {
  test: "sh init.sh"
}

传递参数:

npm run test -- a b c

【讨论】:

    猜你喜欢
    • 2012-04-17
    • 2023-03-04
    • 1970-01-01
    • 2022-10-23
    • 2014-12-26
    • 2013-06-19
    • 1970-01-01
    • 1970-01-01
    • 2011-09-30
    相关资源
    最近更新 更多