如何正确运行带有参数的 npm 脚本 [英] How to properly run a npm script with arguments
问题描述
我用 nodejs 编写了一个小的命令行程序,我希望能够输入 npm run test
并使用下面的参数运行程序.
I've written a small command line program with nodejs and I want to be able to type npm run test
and run the program with the arguments below.
直接输入以下命令即可,node.exe scrappee.js -u 'https://github.com/matutter/{}' -us 'cloggie, AirRocks-Flightcontroller' -s '$commit=li.commits >>跨度,$sha=.right .commit-tease-sha' -pm .\test\example_parse_module.js
Typing the following command directly works,
node.exe scrappee.js -u 'https://github.com/matutter/{}' -us 'cloggie, AirRocks-Flightcontroller' -s '$commit=li.commits > a > span, $sha=.right .commit-tease-sha' -pm .\test\example_parse_module.js
但是我的 package.json 的内容如下,没有任何输出.
But with the contents of my package.json as follows there is no output whatsoever.
"scripts": {
"test" : "node.exe scrappee.js -u 'https://github.com/matutter/{}' -us 'cloggie, AirRocks-Flightcontroller' -s '$commit=li.commits > a > span, $sha=.right .commit-tease-sha' -pm .\\test\\example_parse_module.js"
}
如何获取命令 npm run test
以使用这些参数运行 scrappee.js 脚本?
How can I get the command npm run test
to run the scrappee.js script with the these arguments?
推荐答案
问题来自单引号 '
在转发参数时被 npm 转换为 "'",解决方案是用双引号替换它们,如下所示.
The issue was from the single quote '
being converted to "'" by npm when the arguments are forwarded, the solution was to replace them with double quotes like below.
"test" : "node.exe scrappee.js -u \"https://github.com/matutter/{}\" -us \"cloggie, AirRocks-Flightcontroller\" -s \"$commit=li.commits > a > span, $sha=.right .commit-tease-sha\" -pm \".\\test\\example_parse_module.js\""
这篇关于如何正确运行带有参数的 npm 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!