create-szyy-app 1.0.2 → 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,12 +202,6 @@ 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 });
209
- }
210
- }
211
205
  var GENERATED_CHANGELOG = `# \u53D1\u5E03\u8BB0\u5F55
212
206
 
213
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
@@ -368,6 +362,7 @@ async function collectOptions(projectNameArg, flags) {
368
362
  // src/template.ts
369
363
  import fs2 from "fs";
370
364
  import path3 from "path";
365
+ import os from "os";
371
366
  import { spawnSync } from "child_process";
372
367
  import degit from "degit";
373
368
  async function fetchTemplate(targetDir, versions) {
@@ -379,6 +374,10 @@ async function fetchTemplate(targetDir, versions) {
379
374
  const repoOverride = process.env.SZYY_TEMPLATE_REPO;
380
375
  const gitBase = repoOverride || `${versions.templateGitBase}/${versions.templateRepo}`;
381
376
  const degitSource = `${gitBase}#${versions.template}`;
377
+ if (shouldUseGitCloneDirectly(gitBase)) {
378
+ cloneWithGit(gitBase, versions.template, targetDir);
379
+ return;
380
+ }
382
381
  try {
383
382
  const emitter = degit(degitSource, {
384
383
  cache: false,
@@ -394,20 +393,37 @@ async function fetchTemplate(targetDir, versions) {
394
393
  cloneWithGit(gitBase, versions.template, targetDir);
395
394
  }
396
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
+ }
397
407
  function shouldFallbackToGitClone(error) {
398
408
  const message = error instanceof Error ? error.message : String(error);
399
409
  return message.includes("degit supports GitHub, GitLab, Sourcehut and BitBucket");
400
410
  }
401
411
  function cloneWithGit(repo, ref, targetDir) {
402
- const result = spawnSync("git", ["clone", "--depth", "1", "--branch", ref, repo, targetDir], {
403
- encoding: "utf8"
404
- });
405
- if (result.status === 0) {
406
- removeExcludedTemplateEntries(targetDir);
407
- 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 });
408
426
  }
409
- const errorOutput = result.stderr?.trim() || result.stdout?.trim() || "git clone \u6267\u884C\u5931\u8D25";
410
- throw new Error(`\u6A21\u677F\u62C9\u53D6\u5931\u8D25: ${errorOutput}`);
411
427
  }
412
428
  function copyLocalTemplate(source, target) {
413
429
  if (!fs2.existsSync(source)) {
@@ -503,7 +519,6 @@ async function run(projectName, flags) {
503
519
  spinner2.start("\u6E05\u7406\u6A21\u677F\u7EF4\u62A4\u6587\u4EF6...");
504
520
  cleanupTemplateArtifacts(createOptions.targetDir);
505
521
  spinner2.stop("\u6A21\u677F\u7EF4\u62A4\u6587\u4EF6\u5DF2\u6E05\u7406");
506
- removeGitDir(createOptions.targetDir);
507
522
  p2.outro(
508
523
  [
509
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.2",
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.2",
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,