@shark-pepper/create-app 1.0.1 → 1.0.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.
@@ -31,14 +31,33 @@ function hasPnpm() {
31
31
  }
32
32
  const installCmd = hasPnpm() ? "pnpm install" : "npm install";
33
33
 
34
+ // 获取模板路径(全局安装后可用)
35
+ function getTemplatePath(templateName) {
36
+ const templatePath = path.resolve(__dirname, "../templates", templateName);
37
+ if (!fs.existsSync(templatePath)) {
38
+ console.error(symbols.error, chalk.red(`模板不存在: ${templatePath}`));
39
+ process.exit(1);
40
+ }
41
+ return templatePath;
42
+ }
43
+
34
44
  // 异步复制模板
35
45
  async function copyTemplate(src, dest) {
36
46
  try {
37
47
  await fse.copy(src, dest, {
38
48
  overwrite: true,
39
- filter: (srcPath) => !srcPath.includes("node_modules"),
49
+ filter: (srcPath) => {
50
+ const relPath = path.relative(src, srcPath);
51
+ if (!relPath) return true; // 根目录
52
+ // 忽略 node_modules 目录和某些隐藏文件
53
+ if (relPath.split(path.sep).includes("node_modules")) return false;
54
+ if (relPath.startsWith(".git")) return false;
55
+ if (relPath.startsWith(".DS_Store")) return false;
56
+
57
+ return true;
58
+ },
40
59
  });
41
- console.log(symbols.success, chalk.green("✅ 模板文件复制完成"));
60
+ console.log(symbols.success, chalk.green("✅ 模板文件复制完成"));
42
61
  } catch (err) {
43
62
  console.error(symbols.error, chalk.red("模板复制失败"), err);
44
63
  process.exit(1);
@@ -66,7 +85,7 @@ function setupHusky(projectPath) {
66
85
  );
67
86
  }
68
87
 
69
- console.log(symbols.success, chalk.green("✅ Husky + lint-staged 已配置"));
88
+ console.log(symbols.success, chalk.green("✅ Husky + lint-staged 已配置"));
70
89
  } catch (err) {
71
90
  console.error(symbols.error, chalk.red("Husky 配置失败"), err);
72
91
  }
@@ -137,7 +156,7 @@ module.exports = {
137
156
  const fileMock = `module.exports = 'test-file-stub';\n`;
138
157
  fs.writeFileSync(path.join(mocksDir, "fileMock.js"), fileMock, "utf-8");
139
158
 
140
- console.log(symbols.success, chalk.green("✅ Jest 配置完成"));
159
+ console.log(symbols.success, chalk.green("✅ Jest 配置完成"));
141
160
  } catch (err) {
142
161
  console.error(symbols.error, chalk.red("Jest 配置失败"), err);
143
162
  }
@@ -191,10 +210,10 @@ async function run() {
191
210
  }
192
211
 
193
212
  fs.mkdirSync(projectPath);
194
- console.log(symbols.info, chalk.blue("📁 创建项目目录中..."));
213
+ console.log(symbols.info, chalk.blue("📁 创建项目目录中..."));
195
214
 
196
215
  // 复制模板
197
- const templatePath = path.join(__dirname, "../templates", template);
216
+ const templatePath = getTemplatePath(template);
198
217
  await copyTemplate(templatePath, projectPath);
199
218
 
200
219
  // 处理 package.base.json → package.json
@@ -207,16 +226,16 @@ async function run() {
207
226
  pkgData.description = description;
208
227
  fs.writeFileSync(pkgPath, JSON.stringify(pkgData, null, 2), "utf-8");
209
228
  fs.unlinkSync(basePkgPath);
210
- console.log(symbols.success, chalk.green("✅ 已生成 package.json"));
229
+ console.log(symbols.success, chalk.green("✅ 已生成 package.json"));
211
230
  }
212
231
 
213
232
  // 安装依赖
214
233
  console.log(
215
- chalk.yellow(`📦 正在使用 ${installCmd.split(" ")[0]} 安装依赖...`)
234
+ chalk.yellow(`📦 正在使用 ${installCmd.split(" ")[0]} 安装依赖...`)
216
235
  );
217
236
  execSync(installCmd, { cwd: projectPath, stdio: "inherit" });
218
237
 
219
- // 固定启用 Husky + lint-staged
238
+ // Husky + lint-staged
220
239
  setupHusky(projectPath);
221
240
 
222
241
  // 可选 Jest
@@ -226,7 +245,7 @@ async function run() {
226
245
  symbols.success,
227
246
  chalk.green(`🎉 项目 ${projectName} 创建成功!`)
228
247
  );
229
- console.log(chalk.cyan(`👉 运行项目:`));
248
+ console.log(chalk.cyan(`👉 运行项目:`));
230
249
  console.log(chalk.white(` cd ${projectName}`));
231
250
  console.log(chalk.white(` npm start`));
232
251
  } catch (err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shark-pepper/create-app",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -10,6 +10,10 @@
10
10
  "bin": {
11
11
  "create-app": "bin/create-app-cli.js"
12
12
  },
13
+ "files": [
14
+ "bin",
15
+ "templates"
16
+ ],
13
17
  "keywords": [],
14
18
  "author": "",
15
19
  "license": "ISC",