40 lines
1.2 KiB
JavaScript
40 lines
1.2 KiB
JavaScript
#!/usr/bin/env node
|
|
const { program } = require('commander');
|
|
const fs = require('fs-extra');
|
|
const path = require('path');
|
|
const simpleGit = require('simple-git');
|
|
|
|
// 定义命令和选项
|
|
program
|
|
.option('-n, --name <name>', 'Specify the project name')
|
|
.action(async (options) => {
|
|
const projectName = options.name;
|
|
if (!projectName) {
|
|
console.error('Please provide a project name using -n or --name.');
|
|
return;
|
|
}
|
|
|
|
const targetDir = path.join(process.cwd(), projectName);
|
|
const gitRepoUrl = 'http://git.funjia.top/funjia/funjia-admin-template-vue.git'; // 替换为你的 Git 仓库地址
|
|
|
|
try {
|
|
// 创建目标目录
|
|
fs.ensureDirSync(targetDir);
|
|
|
|
// 克隆 Git 仓库到目标目录
|
|
const git = simpleGit();
|
|
await git.clone(gitRepoUrl, targetDir);
|
|
|
|
// 删除 .git 文件夹
|
|
const gitDir = path.join(targetDir, '.git');
|
|
if (fs.existsSync(gitDir)) {
|
|
fs.removeSync(gitDir);
|
|
}
|
|
|
|
console.log(`Project ${projectName} has been created successfully!`);
|
|
} catch (error) {
|
|
console.error(`Error creating project: ${error.message}`);
|
|
}
|
|
});
|
|
|
|
program.parse(process.argv); |