vite-shadcn-ui-cli 1.0.5 → 1.0.10

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.
Files changed (2) hide show
  1. package/index.js +60 -23
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -23,32 +23,69 @@ program
23
23
 
24
24
  program
25
25
  .argument('<project-directory>', 'Directory to create your new project')
26
- .action((projectDirectory) => {
27
- const repoUrl = 'https://github.com/kyrie668/vite-shadcn-ui.git';
28
- const projectPath = path.resolve(process.cwd(), projectDirectory);
26
+ .action(async (projectDir) => {
27
+ const targetPath = path.resolve(process.cwd(), projectDir);
29
28
 
30
- console.log(`\n📦 Cloning project into ${projectDirectory}...\n`);
29
+ // 检查目录是否已存在
30
+ if (fs.existsSync(targetPath)) {
31
+ console.log(chalk.red(`\n❌ The directory "${projectDir}" already exists!`));
31
32
 
32
- // 克隆仓库
33
- execSync(`git clone ${repoUrl} ${projectDirectory}`, { stdio: 'inherit' });
33
+ const readline = await import('readline');
34
+ const rl = readline.createInterface({
35
+ input: process.stdin,
36
+ output: process.stdout,
37
+ });
34
38
 
35
- // 删除 .git 文件夹
36
- const gitPath = path.join(projectPath, '.git');
37
- if (fs.existsSync(gitPath)) {
38
- fs.rmSync(gitPath, { recursive: true, force: true });
39
- }
39
+ // 提示用户是否覆盖
40
+ rl.question('Do you want to overwrite it? (y/N): ', async (answer) => {
41
+ rl.close();
42
+ if (answer.toLowerCase() === 'y') {
43
+ try {
44
+ await fs.promises.rm(targetPath, { recursive: true, force: true });
45
+ console.log(chalk.yellow(`\n⚠️ The existing directory "${projectDir}" was removed.`));
40
46
 
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`);
47
+ // 增加延时确保系统释放资源
48
+ setTimeout(() => {
49
+ cloneRepo(projectDir);
50
+ }, 500); // 500ms 延时
51
+ } catch (err) {
52
+ console.error(chalk.red(`Failed to remove directory: ${err.message}`));
53
+ process.exit(1);
54
+ }
55
+ } else {
56
+ console.log(chalk.blue('\nOperation cancelled.'));
57
+ process.exit(1);
58
+ }
59
+ });
60
+ } else {
61
+ cloneRepo(projectDir);
62
+ }
52
63
  });
53
64
 
54
- program.parse();
65
+ program.parse(process.argv);
66
+
67
+ // 克隆 GitHub 仓库的函数
68
+ async function cloneRepo(projectDir) {
69
+ const spinner = ora('Cloning the repository...').start();
70
+ const repoUrl = 'https://github.com/kyrie668/vite-shadcn-ui.git';
71
+
72
+ try {
73
+ execSync(`git clone ${repoUrl} ${projectDir}`, { stdio: 'ignore' });
74
+ spinner.succeed('Project cloned successfully!');
75
+
76
+ // 移除 .git 文件夹以断开 Git 关联
77
+ await fs.promises.rm(path.join(projectDir, '.git'), { recursive: true, force: true });
78
+ console.log(
79
+ chalk.green('\n✅ Git history removed. You can now initialize your own repository.')
80
+ );
81
+
82
+ console.log(chalk.cyan(`\n👉 Next steps:`));
83
+ console.log(` cd ${projectDir}`);
84
+ console.log(' npm install');
85
+ console.log(' npm run dev');
86
+ } catch (error) {
87
+ spinner.fail('Failed to clone the repository.');
88
+ console.error(chalk.red(`\nError: ${error.message}`));
89
+ process.exit(1);
90
+ }
91
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-shadcn-ui-cli",
3
- "version": "1.0.5",
3
+ "version": "1.0.10",
4
4
  "description": "A CLI tool to bootstrap Vite projects with shadcn UI components",
5
5
  "main": "index.js",
6
6
  "bin": {