bunny-cli/bin/index.js

32 lines
906 B
JavaScript
Raw Normal View History

2023-12-22 12:59:57 +08:00
#!/usr/bin/env node
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);
// 文件夹下是否有这个名字
const result = await fileIsExist(targetPath, name);
if (result) {
// 新建项目
const key = await createProject();
// clone项目
downloadProject(targetPath, key, name);
}
});
// 给help信息添加提示
CommandLogHelp();
program.parse(process.argv);