vite-shadcn-ui-cli 1.0.5 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +51 -22
- package/package.json +1 -1
package/index.js
CHANGED
@@ -23,32 +23,61 @@ program
|
|
23
23
|
|
24
24
|
program
|
25
25
|
.argument('<project-directory>', 'Directory to create your new project')
|
26
|
-
.action((
|
27
|
-
const
|
28
|
-
const projectPath = path.resolve(process.cwd(), projectDirectory);
|
26
|
+
.action(async (projectDir) => {
|
27
|
+
const targetPath = path.resolve(process.cwd(), projectDir);
|
29
28
|
|
30
|
-
|
29
|
+
// 检查目录是否已存在
|
30
|
+
if (fs.existsSync(targetPath)) {
|
31
|
+
console.log(chalk.red(`\n❌ The directory "${projectDir}" already exists!`));
|
31
32
|
|
32
|
-
|
33
|
-
|
33
|
+
const readline = await import('readline');
|
34
|
+
const rl = readline.createInterface({
|
35
|
+
input: process.stdin,
|
36
|
+
output: process.stdout,
|
37
|
+
});
|
34
38
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
+
// 提示用户选择
|
40
|
+
rl.question('Do you want to overwrite it? (y/N): ', (answer) => {
|
41
|
+
rl.close();
|
42
|
+
if (answer.toLowerCase() === 'y') {
|
43
|
+
fs.rmSync(targetPath, { recursive: true, force: true });
|
44
|
+
console.log(chalk.yellow(`\n⚠️ The existing directory "${projectDir}" was removed.`));
|
45
|
+
cloneRepo(projectDir);
|
46
|
+
} else {
|
47
|
+
console.log(chalk.blue('\nOperation cancelled.'));
|
48
|
+
process.exit(1);
|
49
|
+
}
|
50
|
+
});
|
51
|
+
} else {
|
52
|
+
cloneRepo(projectDir);
|
39
53
|
}
|
40
|
-
|
41
|
-
console.log(`\n🎉 Project setup complete!`);
|
42
|
-
console.log(`\nNext steps:\n`);
|
43
|
-
console.log(` cd ${projectDirectory}`);
|
44
|
-
console.log(` npm install`);
|
45
|
-
console.log(` npm run dev`);
|
46
|
-
console.log(`\nTo initialize a new Git repository:\n`);
|
47
|
-
console.log(` git init`);
|
48
|
-
console.log(` git remote add origin <your-repo-url>`);
|
49
|
-
console.log(` git add .`);
|
50
|
-
console.log(` git commit -m "Initial commit"`);
|
51
|
-
console.log(` git push -u origin main\n`);
|
52
54
|
});
|
53
55
|
|
56
|
+
program.parse(process.argv);
|
57
|
+
|
58
|
+
// 克隆 GitHub 仓库的函数
|
59
|
+
async function cloneRepo(projectDir) {
|
60
|
+
const spinner = ora('Cloning the repository...').start();
|
61
|
+
const repoUrl = 'https://github.com/kyrie668/vite-shadcn-ui.git';
|
62
|
+
|
63
|
+
try {
|
64
|
+
await git.clone(repoUrl, projectDir);
|
65
|
+
spinner.succeed('Project cloned successfully!');
|
66
|
+
|
67
|
+
// 移除 .git 文件夹以断开 Git 关联
|
68
|
+
fs.rmSync(path.join(projectDir, '.git'), { recursive: true, force: true });
|
69
|
+
console.log(
|
70
|
+
chalk.green('\n✅ Git history removed. You can now initialize your own repository.')
|
71
|
+
);
|
72
|
+
console.log(chalk.cyan(`\n👉 Next steps:`));
|
73
|
+
console.log(` cd ${projectDir}`);
|
74
|
+
console.log(' npm install');
|
75
|
+
console.log(' npm run dev');
|
76
|
+
} catch (error) {
|
77
|
+
spinner.fail('Failed to clone the repository.');
|
78
|
+
console.error(error);
|
79
|
+
process.exit(1);
|
80
|
+
}
|
81
|
+
}
|
82
|
+
|
54
83
|
program.parse();
|