我正在使用这样./index.js --project mono --type item --title newInvoice --comments 'Creates an invoice' --write
的commander.js命令,现在我通过在这样的文件npm run item newInvoice
中设置一些选项来使用命令package.json
"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"
}
但是每当我尝试--write
使用 npm 获得选项时,它npm run item newInvoice --write
都会显示undefined
--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 命令?