2023-12-22 12:59:57 +08:00
|
|
|
|
#!/usr/bin/env node
|
2023-12-22 17:38:13 +08:00
|
|
|
|
const { program } = require('commander'); // 命令行提示工具
|
|
|
|
|
const path = require('path'); // 引入操作路径
|
|
|
|
|
const { CommandLogHelp, CommandLogStart } = require('./command-log');
|
|
|
|
|
const { fileIsExist, createProject, downloadProject } = require('./utils');
|
|
|
|
|
|
|
|
|
|
// 首行显示
|
|
|
|
|
CommandLogStart();
|
|
|
|
|
|
|
|
|
|
// 创建项目命令
|
|
|
|
|
program
|
|
|
|
|
.command('create <app-name>')
|
|
|
|
|
.description('创建一个新项目')
|
|
|
|
|
.action(async function (name) {
|
|
|
|
|
// 创建项目-创建一个名字为name的项目,如果存在是否覆盖?
|
|
|
|
|
const targetPath = path.join(process.cwd(), name);
|
|
|
|
|
|
|
|
|
|
// 文件夹下是否有这个名字
|
|
|
|
|
await fileIsExist(targetPath, name);
|
|
|
|
|
|
|
|
|
|
// 新建项目
|
|
|
|
|
const key = await createProject();
|
|
|
|
|
// clone项目
|
|
|
|
|
downloadProject(targetPath, key, name);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 给help信息添加提示
|
|
|
|
|
CommandLogHelp();
|
|
|
|
|
program.parse(process.argv);
|