【问题标题】:Passing a command line argument or flag to NPM package.json scripts将命令行参数或标志传递给 NPM package.json 脚本
【发布时间】:2015-07-01 21:06:24
【问题描述】:

我正在寻找做这样的事情:

package.json

...
"scripts":{

      "debug_mocha_test":"node-debug ./node_modules/mocha/bin/_mocha --grep ${names}"
  }
...

然后在命令行,我可以运行类似的东西:

npm run debug_mocha_test --names 'test1'

什么的

有谁知道怎么做,或者有比这更好的方法吗?

在某些情况下,mocha 测试库有一个 --grep 函数,如下所示:

http://mochajs.org/

【问题讨论】:

标签: node.js bash shell npm


【解决方案1】:

从 npm 2.0.0 开始,可以将参数传递给 package.json 文件 (https://github.com/npm/npm/pull/5518) 中定义的脚本。格式并不像预期的那样干净,但它确实有效。

将“foo”参数传递给“start”脚本:

npm run-script start -- foo=1

所以在你的情况下,package.json 中的脚本应该是:

"debug_mocha_test":"node-debug ./node_modules/mocha/bin/_mocha --grep"

您可以使用以下命令运行它:

npm run debug_mocha_test -- test1

【讨论】:

    猜你喜欢
    • 2020-05-09
    • 1970-01-01
    • 2018-04-21
    • 2016-05-15
    • 2018-10-15
    • 2018-09-24
    • 2018-01-11
    相关资源
    最近更新 更多