test: 测试: 添加git仓库地址

This commit is contained in:
bunny 2023-12-22 21:46:45 +08:00
parent 9407d63be5
commit 2c2a9b7df7
3 changed files with 46 additions and 42 deletions

View File

@ -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 },

View File

@ -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信息添加提示

View File

@ -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('😭下载失败,请稍后重试');
}
},
};