fizz-cli
Version:
fizz项目脚手架
71 lines (68 loc) • 1.96 kB
JavaScript
// 命令行 loading 效果
const ora = require("ora");
// 交互式命令行
const inquirer = require("inquirer");
// shell
const shell = require("shelljs");
// git
const clone = require("git-clone");
// 修改控制台字符串的样式
const chalk = require("chalk");
// 仓库地址、默认分支
const { respository, defaultBranch } = require("../config");
module.exports = function () {
console.log("\n项目初始化");
console.log("----------------------------------");
inquirer
.prompt([
{
name: "frameworkType",
type: "list",
message: "请选择框架版本",
choices: ["fizz", "fizz-ie8"],
},
// {
// name: "branch",
// type: "list",
// message: "请选择目标分支",
// choices: ["dev", "master"]
// },
{
name: "projectName",
type: "input",
message: "请输入项目名称",
validate(val) {
return !val ? "项目名称不能为空!" : true;
},
},
])
.then(({ frameworkType, projectName }) => {
console.log("");
// 项目路径
const projectPath = `${shell.pwd()}\\${projectName}`;
const spinner = ora(`正在拉取模板代码...`);
spinner.start();
// git仓库地址
const git = respository[frameworkType];
// 初始化使用的默认分支
const branch = defaultBranch[frameworkType];
clone(
git,
projectPath,
{
checkout: branch,
},
function () {
// 删除.git目录
shell.rm("-rf", `${projectPath}/.git`);
spinner.succeed();
console.log(chalk.green("\n项目生成完毕!"));
console.log("\n执行以下命令即可启动项目:");
console.log(`\ncd ${projectName}`);
console.log("\nnpm install");
console.log("\nnpm run dev");
}
);
});
};