create-szyy-app 1.0.0 → 1.0.1
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 +27 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -321,6 +321,7 @@ async function collectOptions(projectNameArg, flags) {
|
|
|
321
321
|
// src/template.ts
|
|
322
322
|
import fs2 from "fs";
|
|
323
323
|
import path3 from "path";
|
|
324
|
+
import { spawnSync } from "child_process";
|
|
324
325
|
import degit from "degit";
|
|
325
326
|
async function fetchTemplate(targetDir, versions) {
|
|
326
327
|
const localPath = process.env.SZYY_TEMPLATE_PATH;
|
|
@@ -331,12 +332,33 @@ async function fetchTemplate(targetDir, versions) {
|
|
|
331
332
|
const repoOverride = process.env.SZYY_TEMPLATE_REPO;
|
|
332
333
|
const gitBase = repoOverride || `${versions.templateGitBase}/${versions.templateRepo}`;
|
|
333
334
|
const degitSource = `${gitBase}#${versions.template}`;
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
335
|
+
try {
|
|
336
|
+
const emitter = degit(degitSource, {
|
|
337
|
+
cache: false,
|
|
338
|
+
force: true,
|
|
339
|
+
verbose: false
|
|
340
|
+
});
|
|
341
|
+
await emitter.clone(targetDir);
|
|
342
|
+
} catch (error) {
|
|
343
|
+
if (!shouldFallbackToGitClone(error)) {
|
|
344
|
+
throw error;
|
|
345
|
+
}
|
|
346
|
+
cloneWithGit(gitBase, versions.template, targetDir);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
function shouldFallbackToGitClone(error) {
|
|
350
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
351
|
+
return message.includes("degit supports GitHub, GitLab, Sourcehut and BitBucket");
|
|
352
|
+
}
|
|
353
|
+
function cloneWithGit(repo, ref, targetDir) {
|
|
354
|
+
const result = spawnSync("git", ["clone", "--depth", "1", "--branch", ref, repo, targetDir], {
|
|
355
|
+
encoding: "utf8"
|
|
338
356
|
});
|
|
339
|
-
|
|
357
|
+
if (result.status === 0) {
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
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}`);
|
|
340
362
|
}
|
|
341
363
|
function copyLocalTemplate(source, target) {
|
|
342
364
|
if (!fs2.existsSync(source)) {
|