fs-wh
v1.0.0
Published
```js #!/usr/bin/env node const program = require('commander'), inquirer = require('inquirer'), fs = require('fs'), path = require('path')
Downloads
4
Readme
#!/usr/bin/env node
const program = require('commander'),
inquirer = require('inquirer'),
fs = require('fs'),
path = require('path')
program.command('create') //命令
.description('创建') //描述
.action((dir) => {
inquirer.prompt([{
type: 'checkbox', //类型
message: '请选择要合并的文件夹', //描述
name: 'list', //键
choices: ['a', 'b', 'c'] //选项
}]).then(res => {
let { list } = res, //解构结果
arr = []
list.map(v => {
let dir = fs.readdirSync(v) //读取每个文件夹
console.log(dir)
dir.map(item => {
if (path.extname(item) === '.json') {
let filepath = path.join(v, item)
let jsonObj = JSON.parse(fs.readFileSync(filepath))
arr.push(jsonObj)
return
}
return
})
})
fs.mkdirSync('dist')
fs.writeFileSync('dist/index.json', JSON.stringify(arr))
})
})