【发布时间】:2020-06-23 02:43:43
【问题描述】:
我正在使用类似./index.js --project mono --type item --title newInvoice --comments 'Creates an invoice' --write 这样的commander.js 命令,现在我通过在package.json 文件中设置一些选项来通过npm run item newInvoice 使用命令
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"snapshot": "node --max-old-space-size=10240 ./scripts/snapshot.js",
"item": "./index.js --project mono --type item --title",
"config": "./index.js --project mono --type config --title"
}
但是,每当我尝试使用 npm run item newInvoice --write 使用 npm 获取 --write 选项时,它会显示 undefined for --write
源代码:
#!/usr/bin/env node
const fs = require('fs');
const program = require('commander');
require('colors');
program
.version('0.1.0')
.option('--project [project]', 'Specifies the project name', 'mono')
.option('--type [type]', 'Type of code to generate, either "item" or "config"', /^(config|item)$/, 'config')
.option('--title [title]', 'Title of the item or config', 'untitled')
.option('--comments [comments]', 'Configs: describe the config', '@todo description/comments')
.option('--write', 'Write the source code to a new file in the expected path')
.option('--read', 'To see what would be written the source code to a new file in the expected path')
.parse(process.argv);
console.log(program.write, program.read); //=> undefined undefined
谁能帮我如何在 npm 中使用指挥官 js 命令?
【问题讨论】:
标签: npm npm-scripts node-commander