create-szyy-app 1.0.0 → 1.0.2
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 +93 -6
- package/package.json +1 -1
- package/templates/versions.json +1 -1
package/dist/index.js
CHANGED
|
@@ -208,6 +208,53 @@ function removeGitDir(targetDir) {
|
|
|
208
208
|
fs.rmSync(gitDir, { recursive: true, force: true });
|
|
209
209
|
}
|
|
210
210
|
}
|
|
211
|
+
var GENERATED_CHANGELOG = `# \u53D1\u5E03\u8BB0\u5F55
|
|
212
|
+
|
|
213
|
+
> \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
|
|
214
|
+
`;
|
|
215
|
+
function cleanupTemplateArtifacts(targetDir) {
|
|
216
|
+
const cursorDir = path.join(targetDir, ".cursor");
|
|
217
|
+
if (fs.existsSync(cursorDir)) {
|
|
218
|
+
fs.rmSync(cursorDir, { recursive: true, force: true });
|
|
219
|
+
}
|
|
220
|
+
const syncScript = path.join(targetDir, "build/sync-to-template.ts");
|
|
221
|
+
if (fs.existsSync(syncScript)) {
|
|
222
|
+
fs.rmSync(syncScript, { force: true });
|
|
223
|
+
}
|
|
224
|
+
fs.writeFileSync(path.join(targetDir, "CHANGELOG.md"), GENERATED_CHANGELOG, "utf-8");
|
|
225
|
+
cleanupGeneratedPackageJson(targetDir);
|
|
226
|
+
cleanupGeneratedReadme(targetDir);
|
|
227
|
+
cleanupGeneratedGitignore(targetDir);
|
|
228
|
+
}
|
|
229
|
+
function cleanupGeneratedPackageJson(targetDir) {
|
|
230
|
+
const pkgPath = path.join(targetDir, "package.json");
|
|
231
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
|
|
232
|
+
if (pkg.scripts) {
|
|
233
|
+
delete pkg.scripts["sync:to-template"];
|
|
234
|
+
}
|
|
235
|
+
pkg.version = "1.0.0";
|
|
236
|
+
fs.writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}
|
|
237
|
+
`, "utf-8");
|
|
238
|
+
}
|
|
239
|
+
function cleanupGeneratedReadme(targetDir) {
|
|
240
|
+
const readmePath = path.join(targetDir, "README.md");
|
|
241
|
+
if (!fs.existsSync(readmePath)) return;
|
|
242
|
+
let content = fs.readFileSync(readmePath, "utf-8");
|
|
243
|
+
content = content.replace(/\n> \*\*说明:\*\*[^\n]*\n/, "\n");
|
|
244
|
+
content = content.replace(/\n## 维护:dev → create-app 同步\n\n```bash\n[\s\S]*?```\n/, "\n");
|
|
245
|
+
fs.writeFileSync(readmePath, content, "utf-8");
|
|
246
|
+
}
|
|
247
|
+
function cleanupGeneratedGitignore(targetDir) {
|
|
248
|
+
const gitignorePath = path.join(targetDir, ".gitignore");
|
|
249
|
+
if (!fs.existsSync(gitignorePath)) return;
|
|
250
|
+
let content = fs.readFileSync(gitignorePath, "utf-8");
|
|
251
|
+
content = content.replace(/\n# Cursor project metadata[\s\S]*?(?=\n*$)/, "\n");
|
|
252
|
+
content = content.replace(/\n# \.cursor\/\*\n/, "\n");
|
|
253
|
+
if (!content.includes(".cursor")) {
|
|
254
|
+
content = content.replace(/(\n\.idea\n)/, "$1.cursor/\n");
|
|
255
|
+
}
|
|
256
|
+
fs.writeFileSync(gitignorePath, content.replace(/\n{3,}/g, "\n\n").replace(/\n+$/, "\n"), "utf-8");
|
|
257
|
+
}
|
|
211
258
|
|
|
212
259
|
// src/validate.ts
|
|
213
260
|
function validateName(name) {
|
|
@@ -321,6 +368,7 @@ async function collectOptions(projectNameArg, flags) {
|
|
|
321
368
|
// src/template.ts
|
|
322
369
|
import fs2 from "fs";
|
|
323
370
|
import path3 from "path";
|
|
371
|
+
import { spawnSync } from "child_process";
|
|
324
372
|
import degit from "degit";
|
|
325
373
|
async function fetchTemplate(targetDir, versions) {
|
|
326
374
|
const localPath = process.env.SZYY_TEMPLATE_PATH;
|
|
@@ -331,12 +379,35 @@ async function fetchTemplate(targetDir, versions) {
|
|
|
331
379
|
const repoOverride = process.env.SZYY_TEMPLATE_REPO;
|
|
332
380
|
const gitBase = repoOverride || `${versions.templateGitBase}/${versions.templateRepo}`;
|
|
333
381
|
const degitSource = `${gitBase}#${versions.template}`;
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
382
|
+
try {
|
|
383
|
+
const emitter = degit(degitSource, {
|
|
384
|
+
cache: false,
|
|
385
|
+
force: true,
|
|
386
|
+
verbose: false
|
|
387
|
+
});
|
|
388
|
+
await emitter.clone(targetDir);
|
|
389
|
+
removeExcludedTemplateEntries(targetDir);
|
|
390
|
+
} catch (error) {
|
|
391
|
+
if (!shouldFallbackToGitClone(error)) {
|
|
392
|
+
throw error;
|
|
393
|
+
}
|
|
394
|
+
cloneWithGit(gitBase, versions.template, targetDir);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
function shouldFallbackToGitClone(error) {
|
|
398
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
399
|
+
return message.includes("degit supports GitHub, GitLab, Sourcehut and BitBucket");
|
|
400
|
+
}
|
|
401
|
+
function cloneWithGit(repo, ref, targetDir) {
|
|
402
|
+
const result = spawnSync("git", ["clone", "--depth", "1", "--branch", ref, repo, targetDir], {
|
|
403
|
+
encoding: "utf8"
|
|
338
404
|
});
|
|
339
|
-
|
|
405
|
+
if (result.status === 0) {
|
|
406
|
+
removeExcludedTemplateEntries(targetDir);
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
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}`);
|
|
340
411
|
}
|
|
341
412
|
function copyLocalTemplate(source, target) {
|
|
342
413
|
if (!fs2.existsSync(source)) {
|
|
@@ -347,7 +418,7 @@ function copyLocalTemplate(source, target) {
|
|
|
347
418
|
}
|
|
348
419
|
function copyRecursive(source, target) {
|
|
349
420
|
for (const entry of fs2.readdirSync(source, { withFileTypes: true })) {
|
|
350
|
-
if (entry.name
|
|
421
|
+
if (shouldSkipTemplateEntry(entry.name)) continue;
|
|
351
422
|
const srcPath = path3.join(source, entry.name);
|
|
352
423
|
const destPath = path3.join(target, entry.name);
|
|
353
424
|
if (entry.isDirectory()) {
|
|
@@ -358,6 +429,19 @@ function copyRecursive(source, target) {
|
|
|
358
429
|
}
|
|
359
430
|
}
|
|
360
431
|
}
|
|
432
|
+
var EXCLUDED_TEMPLATE_ENTRIES = /* @__PURE__ */ new Set(["node_modules", ".git", "dist", ".cursor"]);
|
|
433
|
+
function shouldSkipTemplateEntry(name) {
|
|
434
|
+
return EXCLUDED_TEMPLATE_ENTRIES.has(name);
|
|
435
|
+
}
|
|
436
|
+
function removeExcludedTemplateEntries(targetDir) {
|
|
437
|
+
for (const name of EXCLUDED_TEMPLATE_ENTRIES) {
|
|
438
|
+
if (name === "node_modules" || name === ".git") continue;
|
|
439
|
+
const entryPath = path3.join(targetDir, name);
|
|
440
|
+
if (fs2.existsSync(entryPath)) {
|
|
441
|
+
fs2.rmSync(entryPath, { recursive: true, force: true });
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
361
445
|
|
|
362
446
|
// src/index.ts
|
|
363
447
|
var program = new Command();
|
|
@@ -416,6 +500,9 @@ async function run(projectName, flags) {
|
|
|
416
500
|
applyMinimalMode(createOptions.targetDir, createOptions.appName);
|
|
417
501
|
spinner2.stop("Demo \u9875\u5DF2\u79FB\u9664");
|
|
418
502
|
}
|
|
503
|
+
spinner2.start("\u6E05\u7406\u6A21\u677F\u7EF4\u62A4\u6587\u4EF6...");
|
|
504
|
+
cleanupTemplateArtifacts(createOptions.targetDir);
|
|
505
|
+
spinner2.stop("\u6A21\u677F\u7EF4\u62A4\u6587\u4EF6\u5DF2\u6E05\u7406");
|
|
419
506
|
removeGitDir(createOptions.targetDir);
|
|
420
507
|
p2.outro(
|
|
421
508
|
[
|
package/package.json
CHANGED
package/templates/versions.json
CHANGED