1.0.9 • Published 3 years ago

yz_week v1.0.9

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

#考试

#!/usr/bin/env node
const program = require('commander');//引入文件
const inquirer = require('inquirer');
//内置模块
const fs = require('fs');
const path = require('path');

//创建命令
program.command("yz_create")
    .description("创建")//描述
    //执行的步骤
    .action((dir) => {
        //执行命令
        inquirer.prompt([{
            type: "input",
            name: "week",
            message: '请输入你生成的文件夹名字:',
            validate: v => {
                //查找以.结束 对参数进行容错处理
                if (v.length >= 4) {
                    return true
                }
                //失败
                return false
            }
        }]).then(res => {
            //结构
            let { week } = res;
            //文件
            inquirer.prompt([{
                type: "input",
                name: "fill",
                message: '请输入你生成的文件名字:',
                validate: v => {
                    //查找以.结束 对参数进行容错处理
                    if (v.lastIndexOf('.') > -1) {
                        return true
                    }
                    //失败
                    return false
                }

            }]).then(val => {
                //结构文件名字
                let { fill } = val;
                //读取文件
                let fillWen = fs.readFileSync("list.json", 'utf-8');
                //生成文件夹 创建对应的项目目录
                fs.mkdirSync(week);
                //拼接
                let oppo = path.join(week,fill,'utf-8');
                //写入文件
                fs.writeFileSync("./bin/data.json", fillWen, 'utf-8');
            })

        })

    })

//解析
program.parse(program.argv);
//版本号
program.version("9.9.9");