简体   繁体   English

如何将参数传递给管道npm脚本?

[英]How to pass arguments to piped npm scripts?

I have the following script in my package.json . 我的package.json有以下脚本。

{ "scripts": { "fetcher": "node server/processes/transport.js | bunyan" } }

I try to pass command line arguments to transport.js script like this: 我尝试将命令行参数传递给transport.js脚本,如下所示:

npm run fetcher -- --days=10

But no arguments get passed, npm dumbly passes arguments to the end of the command. 但是不会传递任何参数,npm会将参数传递给命令末尾。

A dirty hack will be like 肮脏的hack会像

{
  "scripts": {
    "fetcher": "bunyan $(node server/processes/transport.js"
  }
}

then run the command 然后运行命令

npm run fetcher -- --days=10)

Notice, with the hack, npm run fetcher will not work, it should be npm run fetcher -- ) 请注意,有了该hack, npm run fetcher将无法正常工作,应该是npm run fetcher -- )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM