将命令行参数或标志传递给NPM package.json脚本
我期待着去做这样的事情:
的package.json
... "scripts":{ "debug_mocha_test":"node-debug ./node_modules/mocha/bin/_mocha --grep ${names}" } ...
所以然后在命令行,我可以运行如下所示:
npm run debug_mocha_test --names 'test1'
pipe他呢
有谁知道如何做到这一点,还是有没有比这更好的方法?
对于某些上下文,摩卡testing库有一个–grep函数,如下所示:
http://mochajs.org/
由于npm 2.0.0,可以将parameter passing给package.json文件中定义的脚本( https://github.com/npm/npm/pull/5518 )。 格式不像人们所期望的那样干净,但是工作起来。
将“foo”parameter passing给“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