在节点package.json中,使用额外的参数从另一个脚本调用脚本,在这种情况下添加mocha观察器
在节点的package.json中我想重用一个我已经在'脚本'中的命令。
这是一个实际的例子
而不是(注意观看脚本中的-w ):
"scripts": { "test" : "./node_modules/mocha/bin/mocha --compilers coffee:coffee-script/register --recursive -R list", "watch": "./node_modules/mocha/bin/mocha --compilers coffee:coffee-script/register --recursive -R list -w", }
我想有类似的东西
"scripts": { "test" : "./node_modules/mocha/bin/mocha --compilers coffee:coffee-script/register --recursive -R list", "watch": "npm run script test" + "-w", }
这不工作(不能在json中做string连接),但你应该得到我想要的
我知道npm脚本支持: – &(并行执行) – &(顺序执行)
所以也许有另一种select?
这可以用npm@2.1.17
来完成。 你没有指定你的操作系统和你正在使用的npm
的版本,但是除非你已经做了一些更新,否则你可能运行npm@1.4.28
,它不支持下面的语法。
在Linux或OSX上,您可以使用sudo npm install -g npm@latest
更新npm。 请参阅https://github.com/npm/npm/wiki/Troubleshooting#try-the-latest-stable-version-of-npm ,以获取在所有平台上更新npm
的指南。
你应该可以通过向你的脚本传递一个额外的参数来做到这一点:
"scripts": { "test": "mocha --compilers coffee:coffee-script/register --recursive -R list", "watch": "npm run test -- -w }
我使用以下简化的package.jsonvalidation了这一点:
{ "scripts": { "a": "ls", "b": "npm run a -- -l" } }
输出:
$ npm run a > @ a /Users/smikes/src/github/foo > ls package.json $ npm run b > @ b /Users/smikes/src/github/foo > npm run a -- -l > @ a /Users/smikes/src/github/foo > ls -l total 8 -rw-r--r-- 1 smikes staff 55 4 Jan 05:34 package.json $