create-lve 0.1.0 → 0.1.3

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 CHANGED
@@ -10,20 +10,26 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
10
10
 
11
11
  async function main() {
12
12
  console.clear();
13
-
14
- p.intro(`${pc.bgCyan(pc.black(' LVE-CLI '))}`);
15
13
 
16
- // 1. 交互收集信息
14
+ p.intro(`${pc.bgCyan(pc.black(' LVE-CLI '))}${pc.gray(' - 快速构建 React + Tailwind 项目')}`);
15
+
17
16
  const project = await p.group(
18
17
  {
19
- path: () =>
18
+ path: () =>
20
19
  p.text({
21
- message: '项目名称(或路径)?',
22
- placeholder: './lve-app',
23
- validate: (value) => {
24
- if (value.length === 0) return '路径不能为空';
25
- }
20
+ message: '项目存储路径?',
21
+ placeholder: './lve-project',
22
+ defaultValue: 'lve-project',
26
23
  }),
24
+ shouldOverwrite: ({ results }) => {
25
+ const targetDir = path.resolve(process.cwd(), results.path);
26
+ if (fs.existsSync(targetDir) && fs.readdirSync(targetDir).length > 0) {
27
+ return p.confirm({
28
+ message: `⚠️ 目录 ${pc.yellow(results.path)} 已存在且不为空,是否清空?`,
29
+ initialValue: false,
30
+ });
31
+ }
32
+ },
27
33
  },
28
34
  {
29
35
  onCancel: () => {
@@ -33,29 +39,35 @@ async function main() {
33
39
  }
34
40
  );
35
41
 
42
+ if (project.shouldOverwrite === false) {
43
+ p.cancel('操作终止:请更换目录名后再试');
44
+ process.exit(0);
45
+ }
46
+
36
47
  const targetDir = path.resolve(process.cwd(), project.path);
37
48
  const templateDir = path.resolve(__dirname, 'template');
38
49
 
39
50
  const s = p.spinner();
40
- s.start('🚀 正在初始化项目模板...');
51
+ s.start('🚀 正在搬运模板...');
41
52
 
42
53
  try {
43
- if (!fs.existsSync(targetDir)) {
54
+ if (project.shouldOverwrite) {
55
+ await fs.emptyDir(targetDir);
56
+ } else {
44
57
  await fs.ensureDir(targetDir);
45
58
  }
46
59
 
47
60
  await fs.copy(templateDir, targetDir);
48
61
 
49
- const renameList = [
50
- ['_package.json', 'package.json'],
51
- ['_gitignore', '.gitignore']
52
- ];
62
+ const renameMap = {
63
+ '_package.json': 'package.json',
64
+ '_gitignore': '.gitignore',
65
+ };
53
66
 
54
- for (const [oldName, newName] of renameList) {
55
- const oldPath = path.join(targetDir, oldName);
56
- const newPath = path.join(targetDir, newName);
67
+ for (const [oldFile, newFile] of Object.entries(renameMap)) {
68
+ const oldPath = path.join(targetDir, oldFile);
57
69
  if (fs.existsSync(oldPath)) {
58
- await fs.move(oldPath, newPath, { overwrite: true });
70
+ await fs.move(oldPath, path.join(targetDir, newFile), { overwrite: true });
59
71
  }
60
72
  }
61
73
 
@@ -66,24 +78,22 @@ async function main() {
66
78
  await fs.writeJson(pkgPath, pkg, { spaces: 2 });
67
79
  }
68
80
 
69
- const lockFile = path.join(targetDir, 'pnpm-lock.yaml');
70
- if (fs.existsSync(lockFile)) {
71
- await fs.remove(lockFile);
72
- }
81
+ await fs.remove(path.join(targetDir, 'pnpm-lock.yaml'));
82
+
83
+ s.stop(pc.green('项目准备就绪!'));
73
84
 
74
- s.stop('项目初始化成功!');
85
+ const relativePath = path.relative(process.cwd(), targetDir);
86
+ const cdCmd = relativePath === '' ? '' : `cd ${relativePath}\n`;
75
87
 
76
- const cdPath = path.relative(process.cwd(), targetDir);
77
-
78
88
  p.note(
79
- pc.cyan(`cd ${cdPath}\npnpm install\npnpm dev`),
80
- '快速开始'
89
+ pc.cyan(`${cdCmd}pnpm install\npnpm dev`),
90
+ '快速开始指南'
81
91
  );
82
92
 
83
- p.outro(`✨ 祝你开发愉快!如有问题请反馈。`);
93
+ p.outro(pc.magenta('✨ Happy Coding with LVE + Tailwind!'));
84
94
 
85
95
  } catch (err) {
86
- s.stop('初始化失败');
96
+ s.stop('失败');
87
97
  console.error(pc.red(err));
88
98
  process.exit(1);
89
99
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-lve",
3
- "version": "0.1.0",
3
+ "version": "0.1.3",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "create-lve": "index.js"
@@ -10,9 +10,9 @@
10
10
  "template",
11
11
  "dist"
12
12
  ],
13
- "devDependencies": {
13
+ "dependencies": {
14
14
  "@clack/prompts": "^1.1.0",
15
15
  "picocolors": "^1.1.1",
16
16
  "fs-extra": "^11.2.0"
17
17
  }
18
- }
18
+ }
@@ -7,8 +7,9 @@
7
7
  "dev": "vite",
8
8
  "build": "tsc -b && vite build",
9
9
  "build-only": "vite build",
10
- "lint": "eslint .",
11
10
  "preview": "vite preview",
11
+ "lint": "oxlint",
12
+ "lint:fix": "oxlint --fix",
12
13
  "format": "oxfmt src/",
13
14
  "format:check": "oxfmt --check"
14
15
  },
@@ -29,4 +30,4 @@
29
30
  "typescript": "~5.9.3",
30
31
  "vite": "^8.0.0-beta.18"
31
32
  }
32
- }
33
+ }