Good day. The question is simple, how to pass flags/options to npm-run-script and read them using commander.js.
Example:
package.json
{
"scripts": {
"start": "node index.js"
},
"dependencies": {
"commander": "^12.1.0"
}
}
index.js
const { program } = require("commander");
program.option("-p --config-path <path>", "config path", ".").parse();
console.log(`options: ${ JSON.stringify(program.opts()) }`);
Running 1 and 2, works as expected:
- (1)
node index.js -p "/path/foo/boo" - (2)
node index.js --config-path="/path/foo/boo"
results in: options: {"configPath":"/path/foo/boo"}
Running npm start (used special --)
- (1)
npm start -- -p="/path/foo/boo" - (2)
npm start -- --config-path="/path/foo/boo"
results in:
> start
> node index.js
options: {"configPath":"."}
configPath option received default value ".".
Can the same result be achieved with npm-run-script?
