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

How to pass arguments to piped npm scripts?

本文关键字:管道 npm 脚本 参数传递      更新时间:2023-09-26

我的package.json中有以下脚本。

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

我尝试将命令行参数传递给transport.js脚本,如下所示:

npm run fetcher -- --days=10

但是没有传递任何参数,npm 愚蠢地将参数传递到命令的末尾。

一个肮脏的黑客会像

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

然后运行命令

npm run fetcher -- --days=10)

请注意,使用黑客,npm run fetcher不起作用,它应该npm run fetcher -- )