gpt4 book ai didi

node.js - 将参数传播到与 && 结合的两个命令

转载 作者:行者123 更新时间:2023-12-04 07:29:56 24 4
gpt4 key购买 nike

我在 package.json 中有两个命令结合'&&':

  "scripts": {
"someAction": "node dist/scripts/actionOne && node -r dist/scripts/actionTwo"
},
是否可以从 cli 调用此脚本,将参数传递给 'actionOne' 和 'actionTwo' ?
打电话时 npm run someAction -- firstArg, secondArg args 仅传递给“actionOne”脚本。
* actionOne 和 actionTwo 预期的参数数量相同。

最佳答案

看完docs ,看起来像 npm-run-all将与 一起使用参数占位符。
我们可以使用占位符将 -- 前面的参数提供给脚本。

$ npm-run-all build "start-server -- --port {1}" -- 8080
这对于从 npm run 命令传递参数很有用。
{
"scripts": {
"start": "npm-run-all build \"start-server -- --port {1}\" --"
}
}

$ npm run start 8080

> example@0.0.0 start /path/to/package.json
> npm-run-all build "start-server -- --port {1}" -- "8080"
所以你可以做这样的事情:
{
"scripts": {
"start": "npm-run-all dist/scripts/actionOne -- --arg {1} && dist/scripts/actionTwo -- --arg2 {2}"
}
}
然后:
npm run start arg1 arg2

关于node.js - 将参数传播到与 && 结合的两个命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68003384/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com