// code logic
// 1.create directory based on name
// 2.create dynamic package.json
// 3.copy template file
// 4.install dependencies and run (not sure)
import {createdir, pathUtils, printLog, copyFolder } from '../../utils';
import fs from 'fs';
import yargs from "yargs";
import interactive from './interactive';



export default async function (name:string) {

    try {
        printLog.info('开始创建');
        if(fs.existsSync(pathUtils.cwd(`${name}`))){
            printLog.warning(`${name}目录已存在！`);
            const choice = await yargs.describe( 'ovveride','是否覆盖当前目录？')
                .choices('ovveride',['是', '否']);
        }
        createdir(`${name}`);
        copyFolder(pathUtils.relative('../../template/library/'),pathUtils.cwd(`${name}`))
        const pkgJson:any = fs.readFileSync(pathUtils.cwd(`./${name}/package.json`)).toJSON();
        pkgJson['name'] = `@auto/${name}`;
        pkgJson['version'] = '1.0.0';

        printLog.progress();

    } catch (e) {
        printLog.fail('创建失败\n',e);
    }
    printLog.done();

}