From 2c2a9b7df7cd7dcf6bacfbe87e91f4e07fe1528d Mon Sep 17 00:00:00 2001 From: bunny <1319900154@qq.com> Date: Fri, 22 Dec 2023 21:46:45 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E6=B5=8B=E8=AF=95:=20=E2=9C=85=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0git=E4=BB=93=E5=BA=93=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/config.js | 20 +++++++++--------- bin/index.js | 12 ++++++----- bin/utils.js | 56 ++++++++++++++++++++++++++------------------------- 3 files changed, 46 insertions(+), 42 deletions(-) diff --git a/bin/config.js b/bin/config.js index 87585cd..d034605 100644 --- a/bin/config.js +++ b/bin/config.js @@ -51,16 +51,16 @@ const vue = [ module.exports = { // 项目列表 projectList: { - 'vue&js&vuex': '1', - 'vue&js&pina': '2', - 'vue&ts&vuex': '3', - 'vue&ts&pina': '4', - 'react&js&': '5', - 'react&ts&': '6', - 'react&js&userouter': '7', - 'react&ts&userouter': '8', - 'react&js&RouterProvider': '9', - 'react&ts&RouterProvider': '10', + 'vue&js&vuex': 'https://gitee.com/BunnyBoss/vue_js_vuex.git', + 'vue&js&pina': 'https://gitee.com/BunnyBoss/vue_js_pina.git', + 'vue&ts&vuex': 'https://gitee.com/BunnyBoss/vue_ts_vuex.git', + 'vue&ts&pina': 'https://gitee.com/BunnyBoss/vue_ts_pina.git', + 'react&js&': 'http://129.211.31.58:3000/Bunny-Cli/react_js.git', + 'react&ts&': 'http://129.211.31.58:3000/Bunny-Cli/react_ts.git', + 'react&js&userouter': 'http://129.211.31.58:3000/Bunny-Cli/react_js_userouter.git', + 'react&ts&userouter': 'http://129.211.31.58:3000/Bunny-Cli/react_ts_userouter.git', + 'react&js&RouterProvider': 'http://129.211.31.58:3000/Bunny-Cli/react_js_routerprovider.git', + 'react&ts&RouterProvider': 'http://129.211.31.58:3000/Bunny-Cli/react_ts_routerprovider.git', }, // 问题 question: { frame, react, vue }, diff --git a/bin/index.js b/bin/index.js index 0c27ac2..830f4d2 100644 --- a/bin/index.js +++ b/bin/index.js @@ -16,12 +16,14 @@ program const targetPath = path.join(process.cwd(), name); // 文件夹下是否有这个名字 - await fileIsExist(targetPath, name); + const result = await fileIsExist(targetPath, name); - // 新建项目 - const key = await createProject(); - // clone项目 - downloadProject(targetPath, key, name); + if (result) { + // 新建项目 + const key = await createProject(); + // clone项目 + downloadProject(targetPath, key, name); + } }); // 给help信息添加提示 diff --git a/bin/utils.js b/bin/utils.js index 055e5dc..f857c52 100644 --- a/bin/utils.js +++ b/bin/utils.js @@ -12,7 +12,6 @@ module.exports = { * 是否需要覆盖 */ async fileIsExist(targetPath, name) { - console.log(targetPath); if (fs.existsSync(targetPath, name)) { const awsaner = await inquirer.prompt({ type: 'confirm', @@ -25,7 +24,11 @@ module.exports = { if (awsaner.overWrite) { fs.remove(targetPath); console.log(chalk.green('✅删除成功')); - } else return; + return true; + } else { + console.log(chalk.yellow('❌程序退出')); + return false; + } } }, @@ -53,32 +56,31 @@ module.exports = { /** * 从仓库clone项目 */ - downloadProject(targetPath, key, name) { - const spinner = ora('下载中...').start(); // 注意要使用x几版本因为不支持 + async downloadProject(targetPath, key, name) { + const spinner = ora('下载中...\n').start(); - // 如果有git,删除原有的git - if (fs.existsSync(targetPath, '.git')) { - fs.remove(path.join(targetPath, '.git')); - } - - gitClone(projectList[key], name, { checkout: 'main' }, function (error) { - if (error) { - spinner.fail('😭下载失败,请稍后重试'); // 注意要使用x几版本因为不支持 - } else { - spinner.succeed('😄下载成功'); // 注意要使用x几版本因为不支持 - const overText = ` - ⚓ Running completion hooks... - - 📄 Generating README.md... - - 🎉 Successfully created project ${name} - 👉 Get started with the following commands: - - cd vue_js_vuex - npm run serve - `; - console.log(overText); + try { + await gitClone(key, name, { checkout: 'master' }); + spinner.succeed('😄下载成功'); + // 如果有git,删除原有的git + if (fs.existsSync(targetPath, '.git')) { + fs.remove(path.join(targetPath, '.git')); } - }); + const overText = ` + ⚓ Running completion hooks... + + 📄 Generating README.md... + + 🎉 Successfully created project ${name} + 👉 Get started with the following commands: + + cd vue_js_vuex + npm run serve + `; + console.log(overText); + console.log(chalk.whiteBright('Happy hacking!')); + } catch (error) { + spinner.fail('😭下载失败,请稍后重试'); + } }, };