【问题标题】:Passing preferential command line flags to combined scripts in nodejs将优先命令行标志传递给nodejs中的组合脚本
【发布时间】:2019-08-22 17:26:35
【问题描述】:

我在nodejspackage.json文件中有一个组合脚本,例如

"scripts": {
    "combination": "node service1.js; node service2.js"
}

我可以使用

运行这个组合脚本
$ npm run combination

此命令将首先运行service1.js,当service1.js 的执行终止时,service2.js 将开始。这两个脚本都可以接受相同的命令行可选标志。例如,

node service1.js --showlog=true --logintodatabase=true
node service1.js --showlog=true --logintodatabase=true

但是,我只想在运行 combination 脚本时将这些命令行标志传递给 service1.js。如果我通过将命令行标志提供为

来执行 combination 脚本
$ npm run combination -- --showlog=true --logintodatabase=true

这些标志适用于script2.js

如何将命令行标志传递给combination 脚本,以便只由script1.js 而不是script2.js 接收标志。我需要保留脚本的执行顺序。

【问题讨论】:

    标签: node.js npm command-line flags


    【解决方案1】:

    通过将combination 脚本拆分为combinationpostcombination 解决了这个问题,即

    "scripts": {
        "combination": "node service1.js",
        "postcombination": "node service2.js"
    }
    

    现在当我运行时

    $ npm run combination -- --showlog=true --logintodatabase=true
    

    首先service1.js 脚本接收标志并执行,然后script2.js 执行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-10-15
      • 1970-01-01
      • 2018-01-11
      • 2014-03-08
      • 2013-10-22
      • 2016-12-19
      • 1970-01-01
      相关资源
      最近更新 更多