vite-shadcn-ui-cli 1.0.11 → 1.0.13

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 +15 -18
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -36,22 +36,19 @@ program
36
36
  output: process.stdout,
37
37
  });
38
38
 
39
- // 提示用户是否覆盖
40
- rl.question('Do you want to overwrite it? (y/N): ', async (answer) => {
39
+ // 提示用户选择
40
+ rl.question('Do you want to overwrite it? (y/N): ', (answer) => {
41
41
  rl.close();
42
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.`));
46
-
47
- // 增加延时确保系统释放资源
48
- setTimeout(() => {
43
+ // fs.rmdirSync(targetPath, { recursive: true, force: true });
44
+ fs.rm(targetPath, { recursive: true, force: true }, (err) => {
45
+ if (err) {
46
+ console.error('Error deleting directory:', err);
47
+ } else {
48
+ console.log(chalk.yellow(`\n⚠️ The existing directory "${projectDir}" was removed.`));
49
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
- }
50
+ }
51
+ });
55
52
  } else {
56
53
  console.log(chalk.blue('\nOperation cancelled.'));
57
54
  process.exit(1);
@@ -62,29 +59,29 @@ program
62
59
  }
63
60
  });
64
61
 
62
+ program.parse(process.argv);
63
+
65
64
  // 克隆 GitHub 仓库的函数
66
65
  async function cloneRepo(projectDir) {
67
66
  const spinner = ora('Cloning the repository...').start();
68
67
  const repoUrl = 'https://github.com/kyrie668/vite-shadcn-ui.git';
69
68
 
70
69
  try {
71
- execSync(`git clone ${repoUrl} ${projectDir}`, { stdio: 'ignore' });
70
+ await git.clone(repoUrl, projectDir);
72
71
  spinner.succeed('Project cloned successfully!');
73
72
 
74
73
  // 移除 .git 文件夹以断开 Git 关联
75
- await fs.promises.rm(path.join(projectDir, '.git'), { recursive: true, force: true });
74
+ fs.rmSync(path.join(projectDir, '.git'), { recursive: true, force: true });
76
75
  console.log(
77
76
  chalk.green('\n✅ Git history removed. You can now initialize your own repository.')
78
77
  );
79
-
80
78
  console.log(chalk.cyan(`\n👉 Next steps:`));
81
79
  console.log(` cd ${projectDir}`);
82
80
  console.log(' npm install');
83
81
  console.log(' npm run dev');
84
82
  } catch (error) {
85
83
  spinner.fail('Failed to clone the repository.');
86
- console.error(chalk.red(`\nError: ${error.message}`));
84
+ console.error(error);
87
85
  process.exit(1);
88
86
  }
89
87
  }
90
- program.parse();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-shadcn-ui-cli",
3
- "version": "1.0.11",
3
+ "version": "1.0.13",
4
4
  "description": "A CLI tool to bootstrap Vite projects with shadcn UI components",
5
5
  "main": "index.js",
6
6
  "bin": {