create-szyy-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.
package/dist/index.js CHANGED
@@ -202,11 +202,52 @@ function applyMinimalMode(targetDir, appName) {
202
202
  "utf-8"
203
203
  );
204
204
  }
205
- function removeGitDir(targetDir) {
206
- const gitDir = path.join(targetDir, ".git");
207
- if (fs.existsSync(gitDir)) {
208
- fs.rmSync(gitDir, { recursive: true, force: true });
205
+ var GENERATED_CHANGELOG = `# \u53D1\u5E03\u8BB0\u5F55
206
+
207
+ > \u672C\u9879\u76EE\u6309\u7167\u81EA\u5B9A\u4E49\u63D0\u4EA4\u89C4\u8303\uFF08\u5982 fix: +\u63CF\u8FF0\uFF09\u81EA\u52A8\u751F\u6210\u4EE5\u4E0B\u53D8\u66F4\u8BB0\u5F55\u3002
208
+ `;
209
+ function cleanupTemplateArtifacts(targetDir) {
210
+ const cursorDir = path.join(targetDir, ".cursor");
211
+ if (fs.existsSync(cursorDir)) {
212
+ fs.rmSync(cursorDir, { recursive: true, force: true });
213
+ }
214
+ const syncScript = path.join(targetDir, "build/sync-to-template.ts");
215
+ if (fs.existsSync(syncScript)) {
216
+ fs.rmSync(syncScript, { force: true });
209
217
  }
218
+ fs.writeFileSync(path.join(targetDir, "CHANGELOG.md"), GENERATED_CHANGELOG, "utf-8");
219
+ cleanupGeneratedPackageJson(targetDir);
220
+ cleanupGeneratedReadme(targetDir);
221
+ cleanupGeneratedGitignore(targetDir);
222
+ }
223
+ function cleanupGeneratedPackageJson(targetDir) {
224
+ const pkgPath = path.join(targetDir, "package.json");
225
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
226
+ if (pkg.scripts) {
227
+ delete pkg.scripts["sync:to-template"];
228
+ }
229
+ pkg.version = "1.0.0";
230
+ fs.writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}
231
+ `, "utf-8");
232
+ }
233
+ function cleanupGeneratedReadme(targetDir) {
234
+ const readmePath = path.join(targetDir, "README.md");
235
+ if (!fs.existsSync(readmePath)) return;
236
+ let content = fs.readFileSync(readmePath, "utf-8");
237
+ content = content.replace(/\n> \*\*说明:\*\*[^\n]*\n/, "\n");
238
+ content = content.replace(/\n## 维护:dev → create-app 同步\n\n```bash\n[\s\S]*?```\n/, "\n");
239
+ fs.writeFileSync(readmePath, content, "utf-8");
240
+ }
241
+ function cleanupGeneratedGitignore(targetDir) {
242
+ const gitignorePath = path.join(targetDir, ".gitignore");
243
+ if (!fs.existsSync(gitignorePath)) return;
244
+ let content = fs.readFileSync(gitignorePath, "utf-8");
245
+ content = content.replace(/\n# Cursor project metadata[\s\S]*?(?=\n*$)/, "\n");
246
+ content = content.replace(/\n# \.cursor\/\*\n/, "\n");
247
+ if (!content.includes(".cursor")) {
248
+ content = content.replace(/(\n\.idea\n)/, "$1.cursor/\n");
249
+ }
250
+ fs.writeFileSync(gitignorePath, content.replace(/\n{3,}/g, "\n\n").replace(/\n+$/, "\n"), "utf-8");
210
251
  }
211
252
 
212
253
  // src/validate.ts
@@ -321,6 +362,7 @@ async function collectOptions(projectNameArg, flags) {
321
362
  // src/template.ts
322
363
  import fs2 from "fs";
323
364
  import path3 from "path";
365
+ import os from "os";
324
366
  import { spawnSync } from "child_process";
325
367
  import degit from "degit";
326
368
  async function fetchTemplate(targetDir, versions) {
@@ -332,6 +374,10 @@ async function fetchTemplate(targetDir, versions) {
332
374
  const repoOverride = process.env.SZYY_TEMPLATE_REPO;
333
375
  const gitBase = repoOverride || `${versions.templateGitBase}/${versions.templateRepo}`;
334
376
  const degitSource = `${gitBase}#${versions.template}`;
377
+ if (shouldUseGitCloneDirectly(gitBase)) {
378
+ cloneWithGit(gitBase, versions.template, targetDir);
379
+ return;
380
+ }
335
381
  try {
336
382
  const emitter = degit(degitSource, {
337
383
  cache: false,
@@ -339,6 +385,7 @@ async function fetchTemplate(targetDir, versions) {
339
385
  verbose: false
340
386
  });
341
387
  await emitter.clone(targetDir);
388
+ removeExcludedTemplateEntries(targetDir);
342
389
  } catch (error) {
343
390
  if (!shouldFallbackToGitClone(error)) {
344
391
  throw error;
@@ -346,19 +393,37 @@ async function fetchTemplate(targetDir, versions) {
346
393
  cloneWithGit(gitBase, versions.template, targetDir);
347
394
  }
348
395
  }
396
+ var DEGIT_HOSTS = /* @__PURE__ */ new Set(["github.com", "gitlab.com", "bitbucket.org", "git.sr.ht"]);
397
+ function shouldUseGitCloneDirectly(source) {
398
+ if (source.startsWith("git@") || source.startsWith("file://")) return true;
399
+ if (source.startsWith(".") || source.startsWith("/") || /^[A-Za-z]:[\\/]/.test(source)) return true;
400
+ try {
401
+ const url = new URL(source);
402
+ return !DEGIT_HOSTS.has(url.hostname.toLowerCase());
403
+ } catch {
404
+ return true;
405
+ }
406
+ }
349
407
  function shouldFallbackToGitClone(error) {
350
408
  const message = error instanceof Error ? error.message : String(error);
351
409
  return message.includes("degit supports GitHub, GitLab, Sourcehut and BitBucket");
352
410
  }
353
411
  function cloneWithGit(repo, ref, targetDir) {
354
- const result = spawnSync("git", ["clone", "--depth", "1", "--branch", ref, repo, targetDir], {
355
- encoding: "utf8"
356
- });
357
- if (result.status === 0) {
358
- return;
412
+ const tempDir = fs2.mkdtempSync(path3.join(os.tmpdir(), "create-szyy-app-"));
413
+ try {
414
+ const cloneDir = path3.join(tempDir, "template");
415
+ const result = spawnSync("git", ["clone", "--depth", "1", "--branch", ref, repo, cloneDir], {
416
+ encoding: "utf8"
417
+ });
418
+ if (result.status === 0) {
419
+ copyRecursive(cloneDir, targetDir);
420
+ return;
421
+ }
422
+ const errorOutput = result.stderr?.trim() || result.stdout?.trim() || "git clone \u6267\u884C\u5931\u8D25";
423
+ throw new Error(`\u6A21\u677F\u62C9\u53D6\u5931\u8D25: ${errorOutput}`);
424
+ } finally {
425
+ fs2.rmSync(tempDir, { recursive: true, force: true });
359
426
  }
360
- const errorOutput = result.stderr?.trim() || result.stdout?.trim() || "git clone \u6267\u884C\u5931\u8D25";
361
- throw new Error(`\u6A21\u677F\u62C9\u53D6\u5931\u8D25: ${errorOutput}`);
362
427
  }
363
428
  function copyLocalTemplate(source, target) {
364
429
  if (!fs2.existsSync(source)) {
@@ -369,7 +434,7 @@ function copyLocalTemplate(source, target) {
369
434
  }
370
435
  function copyRecursive(source, target) {
371
436
  for (const entry of fs2.readdirSync(source, { withFileTypes: true })) {
372
- if (entry.name === "node_modules" || entry.name === ".git" || entry.name === "dist" || entry.name === ".cursor") continue;
437
+ if (shouldSkipTemplateEntry(entry.name)) continue;
373
438
  const srcPath = path3.join(source, entry.name);
374
439
  const destPath = path3.join(target, entry.name);
375
440
  if (entry.isDirectory()) {
@@ -380,6 +445,19 @@ function copyRecursive(source, target) {
380
445
  }
381
446
  }
382
447
  }
448
+ var EXCLUDED_TEMPLATE_ENTRIES = /* @__PURE__ */ new Set(["node_modules", ".git", "dist", ".cursor"]);
449
+ function shouldSkipTemplateEntry(name) {
450
+ return EXCLUDED_TEMPLATE_ENTRIES.has(name);
451
+ }
452
+ function removeExcludedTemplateEntries(targetDir) {
453
+ for (const name of EXCLUDED_TEMPLATE_ENTRIES) {
454
+ if (name === "node_modules" || name === ".git") continue;
455
+ const entryPath = path3.join(targetDir, name);
456
+ if (fs2.existsSync(entryPath)) {
457
+ fs2.rmSync(entryPath, { recursive: true, force: true });
458
+ }
459
+ }
460
+ }
383
461
 
384
462
  // src/index.ts
385
463
  var program = new Command();
@@ -438,7 +516,9 @@ async function run(projectName, flags) {
438
516
  applyMinimalMode(createOptions.targetDir, createOptions.appName);
439
517
  spinner2.stop("Demo \u9875\u5DF2\u79FB\u9664");
440
518
  }
441
- removeGitDir(createOptions.targetDir);
519
+ spinner2.start("\u6E05\u7406\u6A21\u677F\u7EF4\u62A4\u6587\u4EF6...");
520
+ cleanupTemplateArtifacts(createOptions.targetDir);
521
+ spinner2.stop("\u6A21\u677F\u7EF4\u62A4\u6587\u4EF6\u5DF2\u6E05\u7406");
442
522
  p2.outro(
443
523
  [
444
524
  `${pc2.green("\u2713")} \u9879\u76EE ${pc2.cyan(createOptions.appName)} \u521B\u5EFA\u6210\u529F`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-szyy-app",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "脚手架:一键创建微前端子应用",
5
5
  "type": "module",
6
6
  "bin": {
@@ -53,6 +53,7 @@
53
53
  "scripts": {
54
54
  "build": "tsup",
55
55
  "dev": "tsup --watch",
56
+ "smoke": "pnpm build && node scripts/smoke-create.mjs",
56
57
  "typecheck": "tsc --noEmit",
57
58
  "lint": "eslint .",
58
59
  "lint:fix": "eslint . --fix",
@@ -1,5 +1,5 @@
1
1
  {
2
- "template": "v1.0.1",
2
+ "template": "v1.0.3",
3
3
  "templateRepo": "sunyard-szyy-app-template",
4
4
  "templateGitBase": "http://172.1.1.65/RDKit",
5
5
  "defaultPort": 5690,