UNPKG

@iarjian/web-cli

Version:

前端脚手架工具

59 lines (51 loc) 1.8 kB
// 下载模板 const { template } = require("./templates"); // 引入模板数据 const ora = require("ora"); const fs = require("fs"); // const removeDir = require("../lib/remove"); // 用来删除文件和文件夹 const { log } = require("./utils"); const download = require("./download"); module.exports = async (answer) => { // answer = { // name:'项目名称', // frame:'框架名称', // author:'制作者', // description:'项目描述' // template:'项目模板', // } const gitUrl = template[answer.template]['url']; const process = ora(`🚗🚗🚗下载中......${answer.template}`); process.start(); download(gitUrl, answer.name) .then(async () => { process.succeed(); log(`🚗🚗🚗下载完成`); // 删除模板自带的 .git 文件 // removeDir(`${answer.name}/.git`); const fileName = `${answer.name}/package.json`; if (fs.existsSync(fileName)) { const data = fs.readFileSync(fileName).toString(); let json = JSON.parse(data); json.name = answer.name; json.author = answer.author; json.description = answer.description; //修改项目文件夹中 package.json 文件 fs.writeFileSync(fileName, JSON.stringify(json, null, "\t"), "utf-8"); // 提示 log("🚀🚀🚀 初始化完成:尽情的coding吧😎😎😎"); log("To get Start:"); log("============================="); log(`cd ${answer.name}`); log(`npm install`); let start = json.scripts.start ? "start" : "dev"; log(`npm run ${start}`); log("============================="); return; } process.exit(); }) .catch((e) => { log(e, "red"); process.fail(); }); };