cmyr-template-cli 1.45.0 → 1.45.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/plopfile.js CHANGED
@@ -171,11 +171,11 @@ async function getAuthorWebsiteFromGithubAPI(githubUsername) {
171
171
  }
172
172
  async function getLtsNodeVersionByIndexJson() {
173
173
  const resp = await import_axios.default.get(NODE_INDEX_URL);
174
- return resp.data?.find((e) => e.lts)?.version?.replace("v", "");
174
+ return resp.data?.find((e) => e.lts)?.version?.replace("v", "") ?? "";
175
175
  }
176
176
  async function getLtsNodeVersionByHtml(url) {
177
177
  const html = (await import_axios.default.get(url)).data;
178
- return html.match(/<strong>(.*)<\/strong>/)?.[1]?.trim();
178
+ return html.match(/<strong>(.*)<\/strong>/)?.[1]?.trim() ?? "";
179
179
  }
180
180
  async function getFastUrl(urls) {
181
181
  const fast = await Promise.any(urls.map((url) => (0, import_axios.default)({
@@ -186,7 +186,7 @@ async function getFastUrl(urls) {
186
186
  "Accept-Encoding": ""
187
187
  }
188
188
  })));
189
- return fast?.config?.url;
189
+ return fast?.config?.url ?? urls[0] ?? "";
190
190
  }
191
191
  async function getARepositoryPublicKey(token, data) {
192
192
  const response = await import_axios.default.get(`https://api.github.com/repos/${data.owner}/${data.repo}/actions/secrets/public-key`, {
@@ -499,7 +499,11 @@ var TEMPLATES_META_LIST = [
499
499
 
500
500
  // src/utils/template.ts
501
501
  function getTemplateMeta(templateName) {
502
- return TEMPLATES_META_LIST.find((t) => t.name === templateName);
502
+ const templateMeta = TEMPLATES_META_LIST.find((t) => t.name === templateName);
503
+ if (!templateMeta) {
504
+ throw new Error(`Unknown template: ${templateName}`);
505
+ }
506
+ return templateMeta;
503
507
  }
504
508
 
505
509
  // src/utils/exec.ts
@@ -507,17 +511,19 @@ var import_child_process = require("child_process");
507
511
  var import_colors = __toESM(require("@colors/colors"));
508
512
  async function asyncExec(cmd, options) {
509
513
  return new Promise((resolve, reject) => {
510
- const ls = (0, import_child_process.exec)(cmd, options, (err, stdout, stderr) => {
514
+ const ls = (0, import_child_process.exec)(cmd, options ?? {}, (err, stdout, stderr) => {
511
515
  if (err) {
512
516
  return reject(err);
513
517
  }
514
- const combinedOutput = [stdout, stderr].filter(Boolean).join("").trimEnd();
515
- resolve(combinedOutput || stdout || stderr);
518
+ const stdoutText = typeof stdout === "string" ? stdout : stdout.toString();
519
+ const stderrText = typeof stderr === "string" ? stderr : stderr.toString();
520
+ const combinedOutput = [stdoutText, stderrText].filter(Boolean).join("").trimEnd();
521
+ resolve(combinedOutput || stdoutText || stderrText);
516
522
  });
517
- ls.stdout.on("data", (data) => {
523
+ ls.stdout?.on("data", (data) => {
518
524
  console.log(data);
519
525
  });
520
- ls.stderr.on("data", (data) => {
526
+ ls.stderr?.on("data", (data) => {
521
527
  console.log(import_colors.default.red(data));
522
528
  });
523
529
  });
@@ -574,7 +580,7 @@ function lintMd(markdown) {
574
580
  "no-empty-inlinecode": 0
575
581
  };
576
582
  const fixed = fix(markdown, rules);
577
- return fixed;
583
+ return fixed ?? markdown;
578
584
  }
579
585
 
580
586
  // src/pure/git.ts
@@ -681,7 +687,7 @@ async function handleGithubRepo({ loading, templateMeta, cliConfig, repository }
681
687
  description: repository.description,
682
688
  private: !repository.isOpenSource
683
689
  });
684
- if (resp?.status >= 200) {
690
+ if (resp && typeof resp.status === "number" && resp.status >= 200) {
685
691
  loading.succeed("远程 Git 仓库初始化成功!");
686
692
  console.info(import_colors2.default.green(`远程 Git 仓库地址 ${resp.data?.html_url}`));
687
693
  const owner = resp.data?.owner?.login;
@@ -690,7 +696,7 @@ async function handleGithubRepo({ loading, templateMeta, cliConfig, repository }
690
696
  const topics = buildRepositoryTopics({
691
697
  baseKeywords: repository.keywords,
692
698
  templateMeta,
693
- isPublishToNpm: repository.isPublishToNpm
699
+ isPublishToNpm: Boolean(repository.isPublishToNpm)
694
700
  });
695
701
  console.info(import_colors2.default.green("正在初始化仓库 topics !"));
696
702
  await replaceGithubRepositoryTopics(authToken, {
@@ -761,7 +767,7 @@ async function handleGiteeRepo({ loading, repository, cliConfig }) {
761
767
  description: repository.description,
762
768
  private: true
763
769
  });
764
- if (resp?.status >= 200) {
770
+ if (resp && typeof resp.status === "number" && resp.status >= 200) {
765
771
  loading.succeed("远程 Git 仓库初始化成功!");
766
772
  console.info(import_colors2.default.green(`远程 Git 仓库地址 ${resp.data?.html_url}`));
767
773
  return;
@@ -993,6 +999,9 @@ async function initDocker(projectPath, answers) {
993
999
  }
994
1000
  switch (plan.mode) {
995
1001
  case "java-ejs":
1002
+ if (!plan.templateRelativePath) {
1003
+ throw new Error("缺少 Java Dockerfile 模板路径");
1004
+ }
996
1005
  await renderDockerfile(import_path5.default.join(__dirname, "../templates/", plan.templateRelativePath), dockerfilePath, { javaVersion: templateMeta?.javaVersion });
997
1006
  break;
998
1007
  case "node-ejs":
@@ -1073,7 +1082,7 @@ async function renderMarkdownTemplate({
1073
1082
  );
1074
1083
  await removeFiles(projectPath, [targetRelativePath]);
1075
1084
  await import_fs_extra7.default.mkdirp(import_path6.default.dirname(targetPath));
1076
- await import_fs_extra7.default.writeFile(targetPath, lintMd((0, import_lodash4.unescape)(renderedContent)));
1085
+ await import_fs_extra7.default.writeFile(targetPath, lintMd((0, import_lodash4.unescape)(String(renderedContent))));
1077
1086
  loading.succeed(successText);
1078
1087
  } catch (error) {
1079
1088
  loading.fail(failText);
@@ -2191,11 +2200,17 @@ async function initAgentsMd(projectPath, projectInfo) {
2191
2200
  runtime: projectInfo.templateMeta?.runtime || "nodejs",
2192
2201
  vueVersion: projectInfo.templateMeta?.vueVersion || 0,
2193
2202
  packageManager: projectInfo.packageManager || "npm",
2203
+ repositoryUrl: projectInfo.repositoryUrl || "",
2204
+ documentationUrl: projectInfo.documentationUrl || "",
2205
+ issuesUrl: projectInfo.issuesUrl || "",
2206
+ contributingUrl: projectInfo.contributingUrl || "",
2194
2207
  isInitTest: projectInfo.isInitTest || "none",
2195
2208
  devCommand: projectInfo.devCommand,
2196
2209
  testCommand: projectInfo.testCommand,
2197
2210
  buildCommand: projectInfo.buildCommand,
2198
- lintCommand: projectInfo.lintCommand
2211
+ lintCommand: projectInfo.lintCommand,
2212
+ startCommand: projectInfo.startCommand,
2213
+ commitCommand: projectInfo.commitCommand
2199
2214
  };
2200
2215
  await ejsRender(templatePath, templateData, outputPath);
2201
2216
  loading.succeed("AGENTS.md 生成成功!");
@@ -2338,10 +2353,11 @@ async function getFastGitRepo(repository) {
2338
2353
  }
2339
2354
  }
2340
2355
  async function initProject(answers) {
2341
- const { name, template } = answers;
2356
+ const typedAnswers = answers;
2357
+ const { name, template } = typedAnswers;
2342
2358
  const projectPath = import_path10.default.join(process.cwd(), name);
2343
2359
  await downloadGitRepo(`CaoMeiYouRen/${template}`, projectPath);
2344
- await init(projectPath, answers);
2360
+ await init(projectPath, typedAnswers);
2345
2361
  return "- 下载项目模板成功!";
2346
2362
  }
2347
2363
  async function init(projectPath, answers) {
@@ -2477,7 +2493,7 @@ async function init(projectPath, answers) {
2477
2493
  cwd: projectPath
2478
2494
  });
2479
2495
  } catch (error) {
2480
- console.error(import_colors3.default.red(error));
2496
+ console.error(import_colors3.default.red(error instanceof Error ? error.message : String(error)));
2481
2497
  }
2482
2498
  }
2483
2499
 
@@ -3023,11 +3039,12 @@ module.exports = function(plop) {
3023
3039
  }
3024
3040
  ];
3025
3041
  const answers = await inquirer.prompt(questions);
3026
- if (aiSuggestion) {
3027
- answers.aiGeneratedNames = aiSuggestion.names;
3028
- answers.aiGeneratedDescription = aiSuggestion.description;
3029
- answers.aiGeneratedKeywords = aiSuggestion.keywords;
3030
- answers.aiRecommendedTemplate = aiSuggestion.template;
3042
+ const suggestion = aiSuggestion;
3043
+ if (suggestion) {
3044
+ answers.aiGeneratedNames = suggestion.names;
3045
+ answers.aiGeneratedDescription = suggestion.description;
3046
+ answers.aiGeneratedKeywords = suggestion.keywords;
3047
+ answers.aiRecommendedTemplate = suggestion.template;
3031
3048
  }
3032
3049
  delete answers._aiTrigger;
3033
3050
  return answers;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cmyr-template-cli",
3
- "version": "1.45.0",
3
+ "version": "1.45.1",
4
4
  "description": "草梅友仁自制的项目模板创建器",
5
5
  "author": "CaoMeiYouRen",
6
6
  "license": "MIT",
@@ -35,56 +35,57 @@
35
35
  "typecheck": "tsc --noEmit"
36
36
  },
37
37
  "devDependencies": {
38
- "@commitlint/cli": "^20.1.0",
38
+ "@commitlint/cli": "^21.0.1",
39
39
  "@semantic-release/changelog": "^6.0.3",
40
40
  "@semantic-release/git": "^10.0.1",
41
- "@types/debug": "^4.1.5",
41
+ "@types/debug": "^4.1.13",
42
42
  "@types/ejs": "^3.1.0",
43
43
  "@types/fs-extra": "^11.0.0",
44
44
  "@types/inquirer": "^9.0.3",
45
- "@types/libsodium-wrappers": "^0.7.14",
46
- "@types/lodash": "^4.14.165",
45
+ "@types/libsodium-wrappers": "^0.8.2",
46
+ "@types/lodash": "^4.17.24",
47
47
  "@types/minimist": "^1.2.5",
48
- "@types/node": "^25.3.0",
49
- "@vitest/coverage-v8": "^4.0.9",
48
+ "@types/node": "^25.7.0",
49
+ "@vitest/coverage-v8": "^4.1.6",
50
50
  "commitizen": "^4.3.1",
51
51
  "commitlint-config-cmyr": "1.0.0",
52
52
  "conventional-changelog-cmyr-config": "^3.0.0",
53
- "conventional-changelog-writer": "^8.2.0",
54
- "cross-env": "^10.0.0",
53
+ "conventional-changelog-writer": "^8.4.0",
54
+ "cross-env": "^10.1.0",
55
55
  "cz-conventional-changelog-cmyr": "2.0.0",
56
- "debug": "^4.3.1",
56
+ "debug": "^4.4.3",
57
57
  "eslint": "^9.34.0",
58
- "eslint-config-cmyr": "2.0.1",
58
+ "eslint-config-cmyr": "2.3.0",
59
59
  "husky": "^9.0.5",
60
- "lint-staged": "^16.1.0",
61
- "rimraf": "^6.0.0",
60
+ "lint-staged": "^17.0.4",
61
+ "rimraf": "^6.1.3",
62
62
  "semantic-release": "25.0.3",
63
- "semantic-release-cmyr-config": "1.0.1",
64
- "tsup": "^8.3.5",
65
- "tsx": "^4.20.5",
66
- "typescript": "^6.0.2",
67
- "vitest": "^4.0.9"
63
+ "semantic-release-cmyr-config": "1.0.2",
64
+ "tsup": "^8.5.1",
65
+ "tsx": "^4.22.0",
66
+ "typescript": "^6.0.3",
67
+ "typescript-eslint": "^8.59.3",
68
+ "vitest": "^4.1.6"
68
69
  },
69
70
  "dependencies": {
70
71
  "@colors/colors": "^1.6.0",
71
72
  "@lint-md/core": "^2.0.0",
72
- "acorn": "^8.12.1",
73
- "acorn-walk": "^8.3.3",
74
- "axios": "^1.0.0",
75
- "commander": "^14.0.0",
76
- "dayjs": "^1.9.6",
73
+ "acorn": "^8.16.0",
74
+ "acorn-walk": "^8.3.5",
75
+ "axios": "^1.16.1",
76
+ "commander": "^14.0.3",
77
+ "dayjs": "^1.11.20",
77
78
  "download-git-repo": "^3.0.2",
78
- "ejs": "^5.0.1",
79
- "fs-extra": "^11.0.0",
79
+ "ejs": "^5.0.2",
80
+ "fs-extra": "^11.3.5",
80
81
  "json5": "^2.2.1",
81
- "libsodium-wrappers": "0.8.2",
82
- "lodash": "^4.17.20",
82
+ "libsodium-wrappers": "0.8.4",
83
+ "lodash": "^4.18.1",
83
84
  "minimist": "^1.2.5",
84
85
  "ora": "^5.4.1",
85
86
  "plop": "^2.7.6",
86
87
  "tslib": "^2.4.0",
87
- "yaml": "^2.8.1"
88
+ "yaml": "^2.9.0"
88
89
  },
89
90
  "config": {
90
91
  "commitizen": {
@@ -106,6 +107,19 @@
106
107
  "overrides": {
107
108
  "@semantic-release/github": "^12.0.0",
108
109
  "@semantic-release/npm": "^13.1.0"
109
- }
110
+ },
111
+ "onlyBuiltDependencies": [
112
+ "-",
113
+ "3",
114
+ "b",
115
+ "e",
116
+ "esbuild",
117
+ "i",
118
+ "l",
119
+ "q",
120
+ "r",
121
+ "s",
122
+ "t"
123
+ ]
110
124
  }
111
125
  }
@@ -15,11 +15,12 @@
15
15
  <% if (vueVersion === 2) { %>- 框架: Vue 2<% } %>
16
16
  - 包管理器: <%= packageManager %>
17
17
 
18
- ## 仓库信息
18
+ <% if (repositoryUrl || documentationUrl || issuesUrl || contributingUrl) { %>## 仓库信息
19
19
  <% if (repositoryUrl) { %>- 仓库地址: <%= repositoryUrl %><% } %>
20
20
  <% if (documentationUrl) { %>- 项目文档: <%= documentationUrl %><% } %>
21
21
  <% if (issuesUrl) { %>- Issue 地址: <%= issuesUrl %><% } %>
22
22
  <% if (contributingUrl) { %>- 贡献指南: <%= contributingUrl %><% } %>
23
+ <% } %>
23
24
 
24
25
  ## 项目结构
25
26
  > 以下目录为模板默认结构;具体项目可在生成后按实际情况增删。