mty_list
v1.0.0
Published
```js #!/usr/bin/env node
Downloads
3
Readme
#!/usr/bin/env node
const program = require('commander');
const inquirer = require('inquirer');
const fs = require('fs');//引入fs模块
const path = require('path');//引入path模块
program.command('create')
.description('创建')
.action((dir) => {
inquirer.prompt([
{
type:'checkbox',
message:'使用命令',//问题描述
name:'list',
choices:['list.json'] //选择json文件
}
]).then(val => {
let { list } = dir
inquirer.prompt([
{
message:'读文件信息',//读取文件
name:'filename',
validate:(item) => {//选择校验文件并读取
console.log(JSON.parse( fs.readFileSync(item)))
}
}
]).then(val => {
let {item} = val//拿到上一个数据
item.map(v=> { //生成json文件
fs.writeFileSync('package.init.json',path.json(v,item))
})
fs.writeFileSync('package.init.json',path.json(v,item))
})
})
})
program.parse(program.argv)
program.version('1.0.0')