mty_jsontodir
v1.0.0
Published
```js #!/usr/bin/env node
Downloads
1
Readme
#!/usr/bin/env node
const program = require('commander');
const inquirer = require('inquirer');
const fs = require('fs');
const { dirname } = require('path');
program.command('create')
.description('创建')
.action((dir) => {
inquirer.prompt([
{
type: 'checkbox',//选择去读文件
message: '读取文件',
name: 'list',
choices: ['list.json']
}
]).then(val => {
let { list } = val
list.map(v => {
if (v.type === 'file') {//判断文件类型
fs.mkdirSync(v.dirname, v.content, 'utf-8')//生成文件夹
return
} else {
v.children.map(val => {
fs.writeFileSync(val.filename, val.content, 'utf-8')//生成文件夹中的子文件
return
})
}
})
})
})
program.parse(program.argv)
program.version('1.0.0')