create-szyy-app 1.0.1 → 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 +66 -1
- 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) {
|
|
@@ -339,6 +386,7 @@ async function fetchTemplate(targetDir, versions) {
|
|
|
339
386
|
verbose: false
|
|
340
387
|
});
|
|
341
388
|
await emitter.clone(targetDir);
|
|
389
|
+
removeExcludedTemplateEntries(targetDir);
|
|
342
390
|
} catch (error) {
|
|
343
391
|
if (!shouldFallbackToGitClone(error)) {
|
|
344
392
|
throw error;
|
|
@@ -355,6 +403,7 @@ function cloneWithGit(repo, ref, targetDir) {
|
|
|
355
403
|
encoding: "utf8"
|
|
356
404
|
});
|
|
357
405
|
if (result.status === 0) {
|
|
406
|
+
removeExcludedTemplateEntries(targetDir);
|
|
358
407
|
return;
|
|
359
408
|
}
|
|
360
409
|
const errorOutput = result.stderr?.trim() || result.stdout?.trim() || "git clone \u6267\u884C\u5931\u8D25";
|
|
@@ -369,7 +418,7 @@ function copyLocalTemplate(source, target) {
|
|
|
369
418
|
}
|
|
370
419
|
function copyRecursive(source, target) {
|
|
371
420
|
for (const entry of fs2.readdirSync(source, { withFileTypes: true })) {
|
|
372
|
-
if (entry.name
|
|
421
|
+
if (shouldSkipTemplateEntry(entry.name)) continue;
|
|
373
422
|
const srcPath = path3.join(source, entry.name);
|
|
374
423
|
const destPath = path3.join(target, entry.name);
|
|
375
424
|
if (entry.isDirectory()) {
|
|
@@ -380,6 +429,19 @@ function copyRecursive(source, target) {
|
|
|
380
429
|
}
|
|
381
430
|
}
|
|
382
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
|
+
}
|
|
383
445
|
|
|
384
446
|
// src/index.ts
|
|
385
447
|
var program = new Command();
|
|
@@ -438,6 +500,9 @@ async function run(projectName, flags) {
|
|
|
438
500
|
applyMinimalMode(createOptions.targetDir, createOptions.appName);
|
|
439
501
|
spinner2.stop("Demo \u9875\u5DF2\u79FB\u9664");
|
|
440
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");
|
|
441
506
|
removeGitDir(createOptions.targetDir);
|
|
442
507
|
p2.outro(
|
|
443
508
|
[
|
package/package.json
CHANGED
package/templates/versions.json
CHANGED