cmyr-template-cli 1.35.2 → 1.36.0

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.
Files changed (3) hide show
  1. package/README.md +7 -1
  2. package/dist/plopfile.js +412 -300
  3. package/package.json +3 -1
package/README.md CHANGED
@@ -73,7 +73,9 @@ ct create
73
73
  "TWITTER_USERNAME": "",
74
74
  "NPM_USERNAME": "",
75
75
  "DOCKER_USERNAME": "",
76
- "CONTACT_EMAIL": ""
76
+ "DOCKER_PASSWORD": "",
77
+ "CONTACT_EMAIL": "",
78
+ "NPM_TOKEN": ""
77
79
  }
78
80
  ```
79
81
 
@@ -97,8 +99,12 @@ NPM_USERNAME:Npm 用户名,可空,默认会使用 `GITHUB_USERNAME` 的用
97
99
 
98
100
  DOCKER_USERNAME:Docker Hub 用户名,可空,默认会使用**小写的** `GITHUB_USERNAME` 的用户名
99
101
 
102
+ DOCKER_PASSWORD:Docker Hub 密码,可空,默认值为空。如果填写,会自动初始化对应的仓库 action secret
103
+
100
104
  CONTACT_EMAIL:联系邮箱,可空,默认值为空
101
105
 
106
+ NPM_TOKEN:Npm 令牌,可空,默认值为空。如果填写,会自动初始化对应的仓库 action secret
107
+
102
108
  **如果不使用自动初始化远程仓库功能,可以跳过该配置**
103
109
 
104
110
  ## 开发
package/dist/plopfile.js CHANGED
@@ -22,26 +22,115 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
22
22
  mod
23
23
  ));
24
24
 
25
- // src/env.ts
25
+ // src/config/env.ts
26
26
  var env = process.env;
27
27
  var __DEV__ = env.NODE_ENV === "development";
28
28
  var PACKAGE_MANAGER = "pnpm";
29
29
 
30
- // src/utils.ts
31
- var import_fs_extra = __toESM(require("fs-extra"));
32
- var import_path = __toESM(require("path"));
33
- var import_ora = __toESM(require("ora"));
30
+ // src/utils/utils.ts
31
+ var import_fs_extra3 = __toESM(require("fs-extra"));
32
+ var import_path2 = __toESM(require("path"));
33
+ var import_ora2 = __toESM(require("ora"));
34
34
  var import_download_git_repo = __toESM(require("download-git-repo"));
35
- var import_axios = __toESM(require("axios"));
36
35
  var import_child_process = require("child_process");
37
36
  var import_colors = __toESM(require("@colors/colors"));
38
- var import_ejs = __toESM(require("ejs"));
37
+ var import_ejs2 = __toESM(require("ejs"));
39
38
  var import_lodash = require("lodash");
40
- var import_core = require("@lint-md/core");
41
39
  var import_json5 = __toESM(require("json5"));
42
40
  var import_os = __toESM(require("os"));
41
+ var import_yaml = __toESM(require("yaml"));
42
+ var import_acorn = __toESM(require("acorn"));
43
+ var import_acorn_walk = __toESM(require("acorn-walk"));
43
44
 
44
- // src/constants.ts
45
+ // src/utils/constants.ts
46
+ var GITHUB_API_URL = "https://api.github.com";
47
+ var GITEE_API_URL = "https://gitee.com/api/v5";
48
+ var NODEJS_URLS = [
49
+ "https://nodejs.org/zh-cn/download/"
50
+ ];
51
+ var NODE_INDEX_URL = "https://cdn.npmmirror.com/binaries/node/index.json";
52
+ var REMOTES = [
53
+ "https://github.com",
54
+ "https://hub.fastgit.xyz",
55
+ "https://download.fastgit.org",
56
+ "https://ghproxy.com/https://github.com",
57
+ "https://gh.ddlc.top/https://github.com",
58
+ "https://gh.flyinbug.top/gh/https://github.com",
59
+ "https://gh.con.sh/https://github.com",
60
+ "https://cors.isteed.cc/github.com",
61
+ "https://ghps.cc/https://github.com",
62
+ "https://download.nuaa.cf",
63
+ "https://kgithub.com",
64
+ "https://github.moeyy.xyz/https://github.com",
65
+ "https://hub.njuu.cf"
66
+ ];
67
+
68
+ // src/utils/dependencies.ts
69
+ var COMMON_DEPENDENCIES = {
70
+ devDependencies: {
71
+ "@types/fs-extra": "^9.0.4",
72
+ "@types/lodash": "^4.14.165",
73
+ "@types/lodash-es": "^4.17.4",
74
+ "@types/md5": "^2.3.1"
75
+ },
76
+ dependencies: {
77
+ "await-to-js": "^3.0.0",
78
+ axios: "^1.0.0",
79
+ "cmyr-error-collection": "^1.5.0",
80
+ "cmyr-sign": "^1.1.0",
81
+ dayjs: "^1.9.6",
82
+ "fs-extra": "^10.0.0",
83
+ "isomorphic-unfetch": "^3.1.0",
84
+ lodash: "^4.17.20",
85
+ "lodash-es": "^4.17.21",
86
+ "p-limit": "^6.1.0",
87
+ "p-queue": "^8.0.1",
88
+ "push-all-in-one": "^2.2.0",
89
+ "leancloud-storage": "^4.15.0",
90
+ yaml: "^2.3.3"
91
+ }
92
+ };
93
+ var NODE_DEPENDENCIES = {
94
+ devDependencies: {
95
+ tsx: "^4.15.7"
96
+ },
97
+ dependencies: {
98
+ cron: "^3.1.7",
99
+ dotenv: "^16.3.1",
100
+ log4js: "^6.9.1",
101
+ md5: "^2.3.0",
102
+ rimraf: "^5.0.0",
103
+ "rss-parser": "^3.12.0",
104
+ zx: "^8.1.0"
105
+ }
106
+ };
107
+ var VUE2_DEPENDENCIES = {
108
+ devDependencies: {},
109
+ dependencies: {
110
+ "@smallwei/avue": "2.9.4",
111
+ "@vueuse/core": "^10.4.1",
112
+ "element-ui": "^2.15.7",
113
+ vuetify: "^2.6.3"
114
+ }
115
+ };
116
+ var VUE3_DEPENDENCIES = {
117
+ devDependencies: {},
118
+ dependencies: {
119
+ "@smallwei/avue": "^3.2.20",
120
+ "@vueuse/core": "^10.4.1",
121
+ "element-plus": "^2.3.14",
122
+ vuetify: "^3.3.14"
123
+ }
124
+ };
125
+ var WEB_DEPENDENCIES = {
126
+ devDependencies: {},
127
+ dependencies: {
128
+ "animate.css": "^4.1.1",
129
+ "normalize.css": "^8.0.1"
130
+ }
131
+ };
132
+
133
+ // src/core/constants.ts
45
134
  var TEMPLATES_META_LIST = [
46
135
  {
47
136
  name: "vite-latest-template",
@@ -286,97 +375,93 @@ var TEMPLATES_META_LIST = [
286
375
  }
287
376
  ];
288
377
 
289
- // src/utils.ts
290
- var import_yaml = __toESM(require("yaml"));
291
- var import_acorn = __toESM(require("acorn"));
292
- var import_acorn_walk = __toESM(require("acorn-walk"));
378
+ // src/utils/template.ts
379
+ function getTemplateMeta(templateName) {
380
+ return TEMPLATES_META_LIST.find((t) => t.name === templateName);
381
+ }
382
+
383
+ // src/utils/string.ts
384
+ var import_core = require("@lint-md/core");
385
+ function kebabCase(str) {
386
+ return str.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/_+/g, "-").replace(/\s+/g, "-").toLowerCase();
387
+ }
293
388
  var fix = (markdown, rules) => (0, import_core.lintMarkdown)(markdown, rules, true)?.fixedResult?.result;
294
- import_axios.default.defaults.timeout = 10 * 1e3;
295
- var GITHUB_API_URL = "https://api.github.com";
296
- var GITEE_API_URL = "https://gitee.com/api/v5";
297
- var NODEJS_URLS = [
298
- "https://nodejs.org/zh-cn/download/"
299
- // 'http://nodejs.cn/download/',
300
- ];
301
- var NODE_INDEX_URL = "https://cdn.npmmirror.com/binaries/node/index.json";
302
- var REMOTES = [
303
- "https://github.com",
304
- "https://hub.fastgit.xyz",
305
- "https://download.fastgit.org",
306
- "https://ghproxy.com/https://github.com",
307
- "https://gh.ddlc.top/https://github.com",
308
- "https://gh.flyinbug.top/gh/https://github.com",
309
- "https://gh.con.sh/https://github.com",
310
- "https://cors.isteed.cc/github.com",
311
- "https://ghps.cc/https://github.com",
312
- "https://download.nuaa.cf",
313
- "https://kgithub.com",
314
- "https://github.moeyy.xyz/https://github.com",
315
- "https://hub.njuu.cf"
316
- ];
317
- var COMMON_DEPENDENCIES = {
318
- devDependencies: {
319
- "@types/fs-extra": "^9.0.4",
320
- "@types/lodash": "^4.14.165",
321
- "@types/lodash-es": "^4.17.4",
322
- "@types/md5": "^2.3.1"
323
- },
324
- dependencies: {
325
- "await-to-js": "^3.0.0",
326
- axios: "^1.0.0",
327
- "cmyr-error-collection": "^1.5.0",
328
- "cmyr-sign": "^1.1.0",
329
- dayjs: "^1.9.6",
330
- "fs-extra": "^10.0.0",
331
- "isomorphic-unfetch": "^3.1.0",
332
- lodash: "^4.17.20",
333
- "lodash-es": "^4.17.21",
334
- "p-limit": "^6.1.0",
335
- "p-queue": "^8.0.1",
336
- "push-all-in-one": "^2.2.0",
337
- "leancloud-storage": "^4.15.0",
338
- yaml: "^2.3.3"
339
- }
340
- };
341
- var NODE_DEPENDENCIES = {
342
- devDependencies: {
343
- tsx: "^4.15.7"
344
- },
345
- dependencies: {
346
- cron: "^3.1.7",
347
- dotenv: "^16.3.1",
348
- log4js: "^6.9.1",
349
- md5: "^2.3.0",
350
- rimraf: "^5.0.0",
351
- "rss-parser": "^3.12.0",
352
- zx: "^8.1.0"
353
- }
354
- };
355
- var VUE2_DEPENDENCIES = {
356
- devDependencies: {},
357
- dependencies: {
358
- "@smallwei/avue": "2.9.4",
359
- "@vueuse/core": "^10.4.1",
360
- "element-ui": "^2.15.7",
361
- vuetify: "^2.6.3"
362
- }
363
- };
364
- var VUE3_DEPENDENCIES = {
365
- devDependencies: {},
366
- dependencies: {
367
- "@smallwei/avue": "^3.2.20",
368
- "@vueuse/core": "^10.4.1",
369
- "element-plus": "^2.3.14",
370
- vuetify: "^3.3.14"
389
+ function lintMd(markdown) {
390
+ const rules = {
391
+ "no-empty-code": 0,
392
+ "no-trailing-punctuation": 0,
393
+ "no-long-code": 0,
394
+ "no-empty-code-lang": 0,
395
+ "no-empty-inlinecode": 0
396
+ };
397
+ const fixed = fix(markdown, rules);
398
+ return fixed;
399
+ }
400
+
401
+ // src/utils/ejs.ts
402
+ var import_ejs = __toESM(require("ejs"));
403
+ var import_fs_extra = __toESM(require("fs-extra"));
404
+ async function ejsRender(templatePath, data, outputPath) {
405
+ const template = (await import_fs_extra.default.readFile(templatePath, "utf8")).toString();
406
+ const content = await import_ejs.default.render(
407
+ template,
408
+ data,
409
+ {
410
+ debug: false,
411
+ async: true
412
+ }
413
+ );
414
+ await import_fs_extra.default.writeFile(outputPath, content);
415
+ }
416
+
417
+ // src/utils/files.ts
418
+ var import_fs_extra2 = __toESM(require("fs-extra"));
419
+ var import_path = __toESM(require("path"));
420
+ var import_ora = __toESM(require("ora"));
421
+ async function copyFilesFromTemplates(projectPath, files, lazy = false) {
422
+ const loading = (0, import_ora.default)(`正在复制文件 ${files.join()} ……`).start();
423
+ try {
424
+ for await (const file of files) {
425
+ const templatePath = import_path.default.join(__dirname, "../templates/", file);
426
+ const newPath = import_path.default.join(projectPath, file);
427
+ if (await import_fs_extra2.default.pathExists(newPath)) {
428
+ if (lazy) {
429
+ continue;
430
+ }
431
+ await import_fs_extra2.default.remove(newPath);
432
+ }
433
+ await import_fs_extra2.default.copyFile(templatePath, newPath);
434
+ }
435
+ loading.succeed(`文件 ${files.join()} 复制成功!`);
436
+ return true;
437
+ } catch (error) {
438
+ loading.fail(`文件 ${files.join()} 复制失败!`);
439
+ throw error;
371
440
  }
372
- };
373
- var WEB_DEPENDENCIES = {
374
- devDependencies: {},
375
- dependencies: {
376
- "animate.css": "^4.1.1",
377
- "normalize.css": "^8.0.1"
441
+ }
442
+ async function removeFiles(projectPath, files) {
443
+ const loading = (0, import_ora.default)(`正在删除文件 ${files.join()} ……`).start();
444
+ try {
445
+ for await (const file of files) {
446
+ const newPath = import_path.default.join(projectPath, file);
447
+ if (await import_fs_extra2.default.pathExists(newPath)) {
448
+ await import_fs_extra2.default.remove(newPath);
449
+ } else {
450
+ console.log(`文件 ${file} 不存在,已跳过删除`);
451
+ }
452
+ }
453
+ loading.succeed(`文件 ${files.join()} 删除成功!`);
454
+ return true;
455
+ } catch (error) {
456
+ loading.fail(`文件 ${files.join()} 删除失败!`);
457
+ throw error;
378
458
  }
379
- };
459
+ }
460
+
461
+ // src/utils/api.ts
462
+ var import_axios = __toESM(require("axios"));
463
+ var import_libsodium_wrappers = __toESM(require("libsodium-wrappers"));
464
+ import_axios.default.defaults.timeout = 15 * 1e3;
380
465
  async function createGiteeRepo(data) {
381
466
  try {
382
467
  const formData = new URLSearchParams();
@@ -432,12 +517,74 @@ async function replaceGithubRepositoryTopics(authToken, data) {
432
517
  return null;
433
518
  }
434
519
  }
520
+ async function getAuthorWebsiteFromGithubAPI(githubUsername) {
521
+ try {
522
+ const userData = (await import_axios.default.get(`${GITHUB_API_URL}/users/${githubUsername}`)).data;
523
+ const authorWebsite = userData?.blog;
524
+ return authorWebsite || "";
525
+ } catch (error) {
526
+ console.error(error);
527
+ return "";
528
+ }
529
+ }
530
+ async function getLtsNodeVersionByIndexJson() {
531
+ const resp = await import_axios.default.get(NODE_INDEX_URL);
532
+ return resp.data?.find((e) => e.lts)?.version?.replace("v", "");
533
+ }
534
+ async function getLtsNodeVersionByHtml(url) {
535
+ const html = (await import_axios.default.get(url)).data;
536
+ return html.match(/<strong>(.*)<\/strong>/)?.[1]?.trim();
537
+ }
538
+ async function getFastUrl(urls) {
539
+ const fast = await Promise.any(urls.map((url) => (0, import_axios.default)({
540
+ url,
541
+ method: "HEAD",
542
+ timeout: 15 * 1e3,
543
+ headers: {
544
+ "Accept-Encoding": ""
545
+ }
546
+ })));
547
+ return fast?.config?.url;
548
+ }
549
+ async function getARepositoryPublicKey(token, data) {
550
+ const response = await import_axios.default.get(`https://api.github.com/repos/${data.owner}/${data.repo}/actions/secrets/public-key`, {
551
+ headers: {
552
+ Authorization: `token ${token}`,
553
+ "Content-Type": "application/json"
554
+ }
555
+ });
556
+ return response.data;
557
+ }
558
+ async function createOrUpdateARepositorySecret(token, data) {
559
+ const { secret_value, secret_name, owner, repo, ...other } = data;
560
+ const { key, key_id } = await getARepositoryPublicKey(token, { owner, repo });
561
+ const binkey = import_libsodium_wrappers.default.from_base64(key, import_libsodium_wrappers.default.base64_variants.ORIGINAL);
562
+ const binsec = import_libsodium_wrappers.default.from_string(secret_value);
563
+ const encBytes = import_libsodium_wrappers.default.crypto_box_seal(binsec, binkey);
564
+ const encrypted_value = import_libsodium_wrappers.default.to_base64(encBytes, import_libsodium_wrappers.default.base64_variants.ORIGINAL);
565
+ const newData = {
566
+ ...other,
567
+ owner,
568
+ repo,
569
+ encrypted_value,
570
+ key_id
571
+ };
572
+ const response = await import_axios.default.put(`https://api.github.com/repos/${owner}/${repo}/actions/secrets/${secret_name}`, newData, {
573
+ headers: {
574
+ Authorization: `token ${token}`,
575
+ "Content-Type": "application/json"
576
+ }
577
+ });
578
+ return response.data;
579
+ }
580
+
581
+ // src/utils/utils.ts
435
582
  async function loadTemplateCliConfig() {
436
- const paths = [process.cwd(), import_os.default.homedir()].map((e) => import_path.default.join(e, ".ctrc"));
583
+ const paths = [process.cwd(), import_os.default.homedir()].map((e) => import_path2.default.join(e, ".ctrc"));
437
584
  const [local, home] = (await Promise.all(paths.map(async (p) => {
438
585
  try {
439
- if (await import_fs_extra.default.pathExists(p)) {
440
- return import_fs_extra.default.readJSON(p);
586
+ if (await import_fs_extra3.default.pathExists(p)) {
587
+ return import_fs_extra3.default.readJSON(p);
441
588
  }
442
589
  return null;
443
590
  } catch (error) {
@@ -457,7 +604,7 @@ async function loadTemplateCliConfig() {
457
604
  }
458
605
  async function downloadGitRepo(repository, destination, options = {}) {
459
606
  const fastRepo = await getFastGitRepo(repository);
460
- const loading = (0, import_ora.default)(`正在下载模板 - ${repository}`);
607
+ const loading = (0, import_ora2.default)(`正在下载模板 - ${repository}`);
461
608
  loading.start();
462
609
  return Promise.any([
463
610
  new Promise((resolve) => {
@@ -474,7 +621,7 @@ async function downloadGitRepo(repository, destination, options = {}) {
474
621
  ]);
475
622
  }
476
623
  async function getFastGitRepo(repository) {
477
- const loading = (0, import_ora.default)(`正在选择镜像源 - ${repository}`);
624
+ const loading = (0, import_ora2.default)(`正在选择镜像源 - ${repository}`);
478
625
  loading.start();
479
626
  try {
480
627
  const fastUrl = await getFastUrl(REMOTES.map((remote) => `${remote}/${repository}/archive/refs/heads/master.zip`));
@@ -507,7 +654,7 @@ async function asyncExec(cmd, options) {
507
654
  }
508
655
  async function initProject(answers) {
509
656
  const { name, template } = answers;
510
- const projectPath = import_path.default.join(process.cwd(), name);
657
+ const projectPath = import_path2.default.join(process.cwd(), name);
511
658
  await downloadGitRepo(`CaoMeiYouRen/${template}`, projectPath);
512
659
  await init(projectPath, answers);
513
660
  return "- 下载项目模板成功!";
@@ -643,12 +790,8 @@ async function init(projectPath, answers) {
643
790
  console.error(import_colors.default.red(error));
644
791
  }
645
792
  }
646
- async function getGitUserName() {
647
- const username = await asyncExec("git config user.name") || "";
648
- return username?.trim();
649
- }
650
793
  async function initRemoteGitRepo(projectPath, answers) {
651
- const loading = (0, import_ora.default)("正在初始化远程 Git 仓库……").start();
794
+ const loading = (0, import_ora2.default)("正在初始化远程 Git 仓库……").start();
652
795
  try {
653
796
  const { name, description, gitRemoteUrl, isOpenSource, isInitRemoteRepo, keywords, template, isPublishToNpm } = answers;
654
797
  const templateMeta = getTemplateMeta(template);
@@ -714,9 +857,35 @@ async function initRemoteGitRepo(projectPath, answers) {
714
857
  topics: (0, import_lodash.uniq)(keywords).map((e) => kebabCase(e))
715
858
  });
716
859
  console.info(import_colors.default.green("仓库 topics 初始化成功!"));
860
+ console.info(import_colors.default.green("正在初始化仓库 action secret !"));
861
+ const { DOCKER_USERNAME, DOCKER_PASSWORD, NPM_TOKEN } = config;
862
+ if (isPublishToNpm && NPM_TOKEN) {
863
+ await createOrUpdateARepositorySecret(authToken, {
864
+ owner,
865
+ repo,
866
+ secret_name: "NPM_TOKEN",
867
+ secret_value: NPM_TOKEN
868
+ });
869
+ }
870
+ if (templateMeta.docker && DOCKER_USERNAME && DOCKER_PASSWORD) {
871
+ await createOrUpdateARepositorySecret(authToken, {
872
+ owner,
873
+ repo,
874
+ secret_name: "DOCKER_USERNAME",
875
+ secret_value: DOCKER_USERNAME
876
+ });
877
+ await createOrUpdateARepositorySecret(authToken, {
878
+ owner,
879
+ repo,
880
+ secret_name: "DOCKER_PASSWORD",
881
+ secret_value: DOCKER_PASSWORD
882
+ });
883
+ }
884
+ console.info(import_colors.default.green("仓库 action secret 初始化成功!"));
885
+ return;
717
886
  }
718
- } else {
719
887
  loading.fail("远程 Git 仓库初始化失败!");
888
+ return;
720
889
  }
721
890
  return;
722
891
  }
@@ -751,7 +920,7 @@ async function initRemoteGitRepo(projectPath, answers) {
751
920
  }
752
921
  }
753
922
  async function installNpmPackages(projectPath) {
754
- const loading = (0, import_ora.default)("正在安装依赖……").start();
923
+ const loading = (0, import_ora2.default)("正在安装依赖……").start();
755
924
  try {
756
925
  const files = [".npmrc"];
757
926
  await copyFilesFromTemplates(projectPath, files);
@@ -765,7 +934,7 @@ async function installNpmPackages(projectPath) {
765
934
  }
766
935
  }
767
936
  async function initCommonDependencies(projectPath, answers) {
768
- const loading = (0, import_ora.default)("正在初始化 常见依赖……").start();
937
+ const loading = (0, import_ora2.default)("正在初始化 常见依赖……").start();
769
938
  try {
770
939
  const { commonDependencies = [] } = answers;
771
940
  const pkg = await getProjectJson(projectPath);
@@ -811,9 +980,9 @@ async function initDependabot(projectPath, answers) {
811
980
  } else {
812
981
  const pkg = await getProjectJson(projectPath);
813
982
  if (pkg?.devDependencies?.["semantic-release"]) {
814
- const dependabotPath = import_path.default.join(projectPath, ".github/dependabot.yml");
815
- if (await import_fs_extra.default.pathExists(dependabotPath)) {
816
- const dependabot = import_yaml.default.parse(await import_fs_extra.default.readFile(dependabotPath, "utf-8"));
983
+ const dependabotPath = import_path2.default.join(projectPath, ".github/dependabot.yml");
984
+ if (await import_fs_extra3.default.pathExists(dependabotPath)) {
985
+ const dependabot = import_yaml.default.parse(await import_fs_extra3.default.readFile(dependabotPath, "utf-8"));
817
986
  if (dependabot?.updates?.[0]["package-ecosystem"] === "npm") {
818
987
  dependabot.updates[0].ignore = (0, import_lodash.uniqBy)([
819
988
  ...dependabot?.updates?.[0].ignore || [],
@@ -830,7 +999,7 @@ async function initDependabot(projectPath, answers) {
830
999
  versions: [">= 19.0.0"]
831
1000
  }
832
1001
  ], (e) => e["dependency-name"]);
833
- import_fs_extra.default.writeFile(dependabotPath, import_yaml.default.stringify(dependabot));
1002
+ import_fs_extra3.default.writeFile(dependabotPath, import_yaml.default.stringify(dependabot));
834
1003
  }
835
1004
  }
836
1005
  }
@@ -852,10 +1021,10 @@ async function initYarn(projectPath, answers) {
852
1021
  }
853
1022
  async function initTsconfig(projectPath, answers) {
854
1023
  try {
855
- const tsconfigPath = import_path.default.join(projectPath, "tsconfig.json");
1024
+ const tsconfigPath = import_path2.default.join(projectPath, "tsconfig.json");
856
1025
  const { jsModuleType } = answers;
857
- if (await import_fs_extra.default.pathExists(tsconfigPath)) {
858
- const tsconfigStr = await import_fs_extra.default.readFile(tsconfigPath, "utf8");
1026
+ if (await import_fs_extra3.default.pathExists(tsconfigPath)) {
1027
+ const tsconfigStr = await import_fs_extra3.default.readFile(tsconfigPath, "utf8");
859
1028
  const tsconfig = import_json5.default.parse(tsconfigStr);
860
1029
  if (tsconfig?.compilerOptions?.importHelpers) {
861
1030
  const pkg = await getProjectJson(projectPath);
@@ -893,7 +1062,7 @@ async function initTsconfig(projectPath, answers) {
893
1062
  break;
894
1063
  }
895
1064
  if (hasChanges) {
896
- await import_fs_extra.default.writeFile(tsconfigPath, JSON.stringify(newTsconfig, null, 4));
1065
+ await import_fs_extra3.default.writeFile(tsconfigPath, JSON.stringify(newTsconfig, null, 4));
897
1066
  }
898
1067
  }
899
1068
  }
@@ -902,7 +1071,7 @@ async function initTsconfig(projectPath, answers) {
902
1071
  }
903
1072
  }
904
1073
  async function initProjectJson(projectPath, projectInfos) {
905
- const loading = (0, import_ora.default)("正在初始化 package.json ……").start();
1074
+ const loading = (0, import_ora2.default)("正在初始化 package.json ……").start();
906
1075
  try {
907
1076
  const { packageName, engines, license, homepage, issuesUrl, gitUrl, author, description, keywords = [], isOpenSource, isPublishToNpm = false, jsModuleType } = projectInfos;
908
1077
  const pkg = await getProjectJson(projectPath);
@@ -945,6 +1114,7 @@ async function initProjectJson(projectPath, projectInfos) {
945
1114
  break;
946
1115
  }
947
1116
  const newPkg = (0, import_lodash.merge)({}, pkg, pkgData, extData);
1117
+ newPkg.keywords = (0, import_lodash.uniq)(keywords);
948
1118
  await saveProjectJson(projectPath, newPkg);
949
1119
  loading.succeed("package.json 初始化成功!");
950
1120
  return newPkg;
@@ -955,7 +1125,7 @@ async function initProjectJson(projectPath, projectInfos) {
955
1125
  }
956
1126
  var cleanText = (text) => text.replace(/-/g, "--").replace(/_/g, "__");
957
1127
  async function getProjectInfo(projectPath, answers) {
958
- const loading = (0, import_ora.default)("正在获取项目信息 ……").start();
1128
+ const loading = (0, import_ora2.default)("正在获取项目信息 ……").start();
959
1129
  try {
960
1130
  const { name, author, description, template, isOpenSource, isPublishToNpm, license = "UNLICENSED", isPrivateScopePackage, scopeName, isInitDocker = false } = answers;
961
1131
  const templateMeta = getTemplateMeta(template);
@@ -976,6 +1146,7 @@ async function getProjectInfo(projectPath, answers) {
976
1146
  const lintCommand = pkg?.scripts?.lint && `${packageManager} run lint`;
977
1147
  const commitCommand = pkg?.scripts?.commit && `${packageManager} run commit`;
978
1148
  const mainFile = pkg?.main;
1149
+ answers.config = config;
979
1150
  const githubUsername = config?.GITHUB_USERNAME || author;
980
1151
  const giteeUsername = config?.GITEE_USERNAME;
981
1152
  const weiboUsername = config?.WEIBO_USERNAME;
@@ -984,7 +1155,9 @@ async function getProjectInfo(projectPath, answers) {
984
1155
  const patreonUsername = config?.PATREON_USERNAME;
985
1156
  const npmUsername = config?.NPM_USERNAME || githubUsername;
986
1157
  const dockerUsername = config?.DOCKER_USERNAME || githubUsername?.toLowerCase();
1158
+ const dockerPassword = config?.DOCKER_PASSWORD || "";
987
1159
  const contactEmail = config?.CONTACT_EMAIL || "";
1160
+ const npmToken = config?.NPM_TOKEN || "";
988
1161
  const repositoryUrl = `https://github.com/${githubUsername}/${projectName}`;
989
1162
  const gitUrl = `git+${repositoryUrl}.git`;
990
1163
  const issuesUrl = `${repositoryUrl}/issues`;
@@ -1051,10 +1224,12 @@ async function getProjectInfo(projectPath, answers) {
1051
1224
  twitterUsername,
1052
1225
  npmUsername,
1053
1226
  dockerUsername,
1227
+ dockerPassword,
1054
1228
  templateMeta,
1055
1229
  mainFile,
1056
1230
  isInitDocker,
1057
- contactEmail
1231
+ contactEmail,
1232
+ npmToken
1058
1233
  };
1059
1234
  loading.succeed("项目信息 初始化成功!");
1060
1235
  return projectInfos;
@@ -1065,12 +1240,12 @@ async function getProjectInfo(projectPath, answers) {
1065
1240
  }
1066
1241
  }
1067
1242
  async function initReadme(projectPath, projectInfos) {
1068
- const loading = (0, import_ora.default)("正在初始化 README.md ……").start();
1243
+ const loading = (0, import_ora2.default)("正在初始化 README.md ……").start();
1069
1244
  try {
1070
- const templatePath = import_path.default.join(__dirname, "../templates/README.md");
1071
- const template = (await import_fs_extra.default.readFile(templatePath, "utf8")).toString();
1072
- const newReadmePath = import_path.default.join(projectPath, "README.md");
1073
- const readmeContent = await import_ejs.default.render(
1245
+ const templatePath = import_path2.default.join(__dirname, "../templates/README.md");
1246
+ const template = (await import_fs_extra3.default.readFile(templatePath, "utf8")).toString();
1247
+ const newReadmePath = import_path2.default.join(projectPath, "README.md");
1248
+ const readmeContent = await import_ejs2.default.render(
1074
1249
  template,
1075
1250
  projectInfos,
1076
1251
  {
@@ -1079,7 +1254,7 @@ async function initReadme(projectPath, projectInfos) {
1079
1254
  }
1080
1255
  );
1081
1256
  await removeFiles(projectPath, ["README.md"]);
1082
- await import_fs_extra.default.writeFile(newReadmePath, lintMd((0, import_lodash.unescape)(readmeContent)));
1257
+ await import_fs_extra3.default.writeFile(newReadmePath, lintMd((0, import_lodash.unescape)(readmeContent)));
1083
1258
  loading.succeed("README.md 初始化成功!");
1084
1259
  } catch (error) {
1085
1260
  loading.fail("README.md 初始化失败!");
@@ -1087,12 +1262,12 @@ async function initReadme(projectPath, projectInfos) {
1087
1262
  }
1088
1263
  }
1089
1264
  async function initContributing(projectPath, projectInfos) {
1090
- const loading = (0, import_ora.default)("正在初始化 贡献指南 ……").start();
1265
+ const loading = (0, import_ora2.default)("正在初始化 贡献指南 ……").start();
1091
1266
  try {
1092
- const templatePath = import_path.default.join(__dirname, "../templates/CONTRIBUTING.md");
1093
- const template = (await import_fs_extra.default.readFile(templatePath, "utf8")).toString();
1094
- const newContributingPath = import_path.default.join(projectPath, "CONTRIBUTING.md");
1095
- const content = await import_ejs.default.render(
1267
+ const templatePath = import_path2.default.join(__dirname, "../templates/CONTRIBUTING.md");
1268
+ const template = (await import_fs_extra3.default.readFile(templatePath, "utf8")).toString();
1269
+ const newContributingPath = import_path2.default.join(projectPath, "CONTRIBUTING.md");
1270
+ const content = await import_ejs2.default.render(
1096
1271
  template,
1097
1272
  projectInfos,
1098
1273
  {
@@ -1101,7 +1276,7 @@ async function initContributing(projectPath, projectInfos) {
1101
1276
  }
1102
1277
  );
1103
1278
  await removeFiles(projectPath, ["CONTRIBUTING.md"]);
1104
- await import_fs_extra.default.writeFile(newContributingPath, lintMd((0, import_lodash.unescape)(content)));
1279
+ await import_fs_extra3.default.writeFile(newContributingPath, lintMd((0, import_lodash.unescape)(content)));
1105
1280
  loading.succeed("贡献指南 初始化成功!");
1106
1281
  } catch (error) {
1107
1282
  loading.fail("贡献指南 初始化失败!");
@@ -1109,12 +1284,12 @@ async function initContributing(projectPath, projectInfos) {
1109
1284
  }
1110
1285
  }
1111
1286
  async function initCodeOfConduct(projectPath, projectInfos) {
1112
- const loading = (0, import_ora.default)("正在初始化 贡献者公约 ……").start();
1287
+ const loading = (0, import_ora2.default)("正在初始化 贡献者公约 ……").start();
1113
1288
  try {
1114
- const templatePath = import_path.default.join(__dirname, "../templates/CODE_OF_CONDUCT.md");
1115
- const template = (await import_fs_extra.default.readFile(templatePath, "utf8")).toString();
1116
- const newPath = import_path.default.join(projectPath, "CODE_OF_CONDUCT.md");
1117
- const content = await import_ejs.default.render(
1289
+ const templatePath = import_path2.default.join(__dirname, "../templates/CODE_OF_CONDUCT.md");
1290
+ const template = (await import_fs_extra3.default.readFile(templatePath, "utf8")).toString();
1291
+ const newPath = import_path2.default.join(projectPath, "CODE_OF_CONDUCT.md");
1292
+ const content = await import_ejs2.default.render(
1118
1293
  template,
1119
1294
  projectInfos,
1120
1295
  {
@@ -1123,7 +1298,7 @@ async function initCodeOfConduct(projectPath, projectInfos) {
1123
1298
  }
1124
1299
  );
1125
1300
  await removeFiles(projectPath, ["CODE_OF_CONDUCT.md"]);
1126
- await import_fs_extra.default.writeFile(newPath, lintMd((0, import_lodash.unescape)(content)));
1301
+ await import_fs_extra3.default.writeFile(newPath, lintMd((0, import_lodash.unescape)(content)));
1127
1302
  loading.succeed("贡献者公约 初始化成功!");
1128
1303
  } catch (error) {
1129
1304
  loading.fail("贡献者公约 初始化失败!");
@@ -1131,17 +1306,17 @@ async function initCodeOfConduct(projectPath, projectInfos) {
1131
1306
  }
1132
1307
  }
1133
1308
  async function initLicense(projectPath, projectInfos) {
1134
- const loading = (0, import_ora.default)("正在初始化 LICENSE ……").start();
1309
+ const loading = (0, import_ora2.default)("正在初始化 LICENSE ……").start();
1135
1310
  try {
1136
1311
  const { license } = projectInfos;
1137
- const templatePath = import_path.default.join(__dirname, "../templates/licenses/", license);
1138
- if (!await import_fs_extra.default.pathExists(templatePath)) {
1312
+ const templatePath = import_path2.default.join(__dirname, "../templates/licenses/", license);
1313
+ if (!await import_fs_extra3.default.pathExists(templatePath)) {
1139
1314
  loading.fail("无效的 LICENSE Name");
1140
1315
  return;
1141
1316
  }
1142
- const template = (await import_fs_extra.default.readFile(templatePath, "utf8")).toString();
1143
- const newPath = import_path.default.join(projectPath, "LICENSE");
1144
- const content = await import_ejs.default.render(
1317
+ const template = (await import_fs_extra3.default.readFile(templatePath, "utf8")).toString();
1318
+ const newPath = import_path2.default.join(projectPath, "LICENSE");
1319
+ const content = await import_ejs2.default.render(
1145
1320
  template,
1146
1321
  projectInfos,
1147
1322
  {
@@ -1150,7 +1325,7 @@ async function initLicense(projectPath, projectInfos) {
1150
1325
  }
1151
1326
  );
1152
1327
  await removeFiles(projectPath, ["LICENSE"]);
1153
- await import_fs_extra.default.writeFile(newPath, (0, import_lodash.unescape)(content));
1328
+ await import_fs_extra3.default.writeFile(newPath, (0, import_lodash.unescape)(content));
1154
1329
  loading.succeed("LICENSE 初始化成功!");
1155
1330
  } catch (error) {
1156
1331
  loading.fail("LICENSE 初始化失败!");
@@ -1167,13 +1342,13 @@ async function initConfig(projectPath) {
1167
1342
  }
1168
1343
  }
1169
1344
  async function initGithubWorkflows(projectPath, answers) {
1170
- const loading = (0, import_ora.default)("正在初始化 Github Workflows ……").start();
1345
+ const loading = (0, import_ora2.default)("正在初始化 Github Workflows ……").start();
1171
1346
  try {
1172
1347
  const { isInitSemanticRelease } = answers;
1173
1348
  const files = [".github/workflows/test.yml", ".github/workflows/todo.yml"];
1174
- const dir = import_path.default.join(projectPath, ".github/workflows");
1175
- if (!await import_fs_extra.default.pathExists(dir)) {
1176
- await import_fs_extra.default.mkdirp(dir);
1349
+ const dir = import_path2.default.join(projectPath, ".github/workflows");
1350
+ if (!await import_fs_extra3.default.pathExists(dir)) {
1351
+ await import_fs_extra3.default.mkdirp(dir);
1177
1352
  }
1178
1353
  const releaseYml = ".github/workflows/release.yml";
1179
1354
  if (isInitSemanticRelease) {
@@ -1190,7 +1365,7 @@ async function initGithubWorkflows(projectPath, answers) {
1190
1365
  }
1191
1366
  }
1192
1367
  async function initSemanticRelease(projectPath) {
1193
- const loading = (0, import_ora.default)("正在初始化 semantic-release ……").start();
1368
+ const loading = (0, import_ora2.default)("正在初始化 semantic-release ……").start();
1194
1369
  try {
1195
1370
  const pkg = await getProjectJson(projectPath);
1196
1371
  const files = [".releaserc.js", ".releaserc.cjs"];
@@ -1224,12 +1399,12 @@ async function initSemanticRelease(projectPath) {
1224
1399
  }
1225
1400
  }
1226
1401
  async function initHusky(projectPath) {
1227
- const loading = (0, import_ora.default)("正在初始化 husky ……").start();
1402
+ const loading = (0, import_ora2.default)("正在初始化 husky ……").start();
1228
1403
  try {
1229
1404
  const files = [".husky/commit-msg", ".husky/pre-commit"];
1230
- const dir = import_path.default.join(projectPath, ".husky");
1231
- if (!await import_fs_extra.default.pathExists(dir)) {
1232
- await import_fs_extra.default.mkdirp(dir);
1405
+ const dir = import_path2.default.join(projectPath, ".husky");
1406
+ if (!await import_fs_extra3.default.pathExists(dir)) {
1407
+ await import_fs_extra3.default.mkdirp(dir);
1233
1408
  }
1234
1409
  await copyFilesFromTemplates(projectPath, files);
1235
1410
  const extnames = ["js", "ts"];
@@ -1270,7 +1445,7 @@ async function initHusky(projectPath) {
1270
1445
  }
1271
1446
  }
1272
1447
  async function initEslint(projectPath, answers) {
1273
- const loading = (0, import_ora.default)("正在初始化 eslint ……").start();
1448
+ const loading = (0, import_ora2.default)("正在初始化 eslint ……").start();
1274
1449
  try {
1275
1450
  const templateMeta = getTemplateMeta(answers.template);
1276
1451
  const pkg = await getProjectJson(projectPath);
@@ -1319,10 +1494,10 @@ async function initEslint(projectPath, answers) {
1319
1494
  root: true,
1320
1495
  extends: '${eslintType}',
1321
1496
  }`;
1322
- const cjsPath = import_path.default.join(projectPath, ".eslintrc.cjs");
1323
- const jsPath = import_path.default.join(projectPath, ".eslintrc.js");
1324
- if (!await import_fs_extra.default.pathExists(cjsPath) && !await import_fs_extra.default.pathExists(jsPath)) {
1325
- await import_fs_extra.default.writeFile(jsPath, eslintrc);
1497
+ const cjsPath = import_path2.default.join(projectPath, ".eslintrc.cjs");
1498
+ const jsPath = import_path2.default.join(projectPath, ".eslintrc.js");
1499
+ if (!await import_fs_extra3.default.pathExists(cjsPath) && !await import_fs_extra3.default.pathExists(jsPath)) {
1500
+ await import_fs_extra3.default.writeFile(jsPath, eslintrc);
1326
1501
  }
1327
1502
  loading.succeed("eslint 初始化成功!");
1328
1503
  } catch (error) {
@@ -1331,7 +1506,7 @@ async function initEslint(projectPath, answers) {
1331
1506
  }
1332
1507
  }
1333
1508
  async function initStylelint(projectPath) {
1334
- const loading = (0, import_ora.default)("正在初始化 stylelint ……").start();
1509
+ const loading = (0, import_ora2.default)("正在初始化 stylelint ……").start();
1335
1510
  try {
1336
1511
  const pkg = await getProjectJson(projectPath);
1337
1512
  const extnames = ["html", "css", "scss", "sass"];
@@ -1376,7 +1551,7 @@ async function initStylelint(projectPath) {
1376
1551
  }
1377
1552
  }
1378
1553
  async function initCommitizen(projectPath) {
1379
- const loading = (0, import_ora.default)("正在初始化 commitizen ……").start();
1554
+ const loading = (0, import_ora2.default)("正在初始化 commitizen ……").start();
1380
1555
  try {
1381
1556
  const pkg = await getProjectJson(projectPath);
1382
1557
  const devDependencies = {
@@ -1409,21 +1584,21 @@ async function initCommitizen(projectPath) {
1409
1584
  }
1410
1585
  }
1411
1586
  async function initDocker(projectPath, answers) {
1412
- const loading = (0, import_ora.default)("正在初始化 Docker ……").start();
1587
+ const loading = (0, import_ora2.default)("正在初始化 Docker ……").start();
1413
1588
  try {
1414
1589
  const { name } = answers;
1415
1590
  if (answers.template === "hono-template") {
1416
- const dockerComposePath = import_path.default.join(projectPath, "docker-compose.yml");
1417
- if (await import_fs_extra.default.pathExists(dockerComposePath)) {
1418
- let dockerCompose = await import_fs_extra.default.readFile(dockerComposePath, "utf-8");
1591
+ const dockerComposePath = import_path2.default.join(projectPath, "docker-compose.yml");
1592
+ if (await import_fs_extra3.default.pathExists(dockerComposePath)) {
1593
+ let dockerCompose = await import_fs_extra3.default.readFile(dockerComposePath, "utf-8");
1419
1594
  dockerCompose = dockerCompose.replaceAll("hono-template", name);
1420
- await import_fs_extra.default.writeFile(dockerComposePath, dockerCompose);
1595
+ await import_fs_extra3.default.writeFile(dockerComposePath, dockerCompose);
1421
1596
  }
1422
- const wranglerPath = import_path.default.join(projectPath, "wrangler.toml");
1423
- if (await import_fs_extra.default.pathExists(wranglerPath)) {
1424
- let wrangler = await import_fs_extra.default.readFile(wranglerPath, "utf-8");
1597
+ const wranglerPath = import_path2.default.join(projectPath, "wrangler.toml");
1598
+ if (await import_fs_extra3.default.pathExists(wranglerPath)) {
1599
+ let wrangler = await import_fs_extra3.default.readFile(wranglerPath, "utf-8");
1425
1600
  wrangler = wrangler.replaceAll("hono-template", name);
1426
- await import_fs_extra.default.writeFile(wranglerPath, wrangler);
1601
+ await import_fs_extra3.default.writeFile(wranglerPath, wrangler);
1427
1602
  }
1428
1603
  loading.succeed("Docker 初始化成功!");
1429
1604
  return;
@@ -1432,27 +1607,27 @@ async function initDocker(projectPath, answers) {
1432
1607
  const files = [".dockerignore", "docker-compose.yml", ".github/workflows/docker.yml"];
1433
1608
  await copyFilesFromTemplates(projectPath, files);
1434
1609
  let dockerfile = "Dockerfile";
1435
- const newPath = import_path.default.join(projectPath, "Dockerfile");
1436
- if (await import_fs_extra.default.pathExists(newPath)) {
1437
- await import_fs_extra.default.remove(newPath);
1610
+ const newPath = import_path2.default.join(projectPath, "Dockerfile");
1611
+ if (await import_fs_extra3.default.pathExists(newPath)) {
1612
+ await import_fs_extra3.default.remove(newPath);
1438
1613
  }
1439
1614
  if (templateMeta?.runtime === "java") {
1440
- const templatePath = import_path.default.join(__dirname, "../templates/java/Dockerfile.ejs");
1615
+ const templatePath = import_path2.default.join(__dirname, "../templates/java/Dockerfile.ejs");
1441
1616
  await ejsRender(templatePath, { javaVersion: templateMeta?.javaVersion }, newPath);
1442
1617
  loading.succeed("Docker 初始化成功!");
1443
1618
  return;
1444
1619
  }
1445
1620
  if (templateMeta?.runtime === "nodejs") {
1446
1621
  if (templateMeta?.runtime === "nodejs") {
1447
- const scriptsDir = import_path.default.join(projectPath, "scripts");
1448
- if (!await import_fs_extra.default.pathExists(scriptsDir)) {
1449
- await import_fs_extra.default.mkdir(scriptsDir);
1622
+ const scriptsDir = import_path2.default.join(projectPath, "scripts");
1623
+ if (!await import_fs_extra3.default.pathExists(scriptsDir)) {
1624
+ await import_fs_extra3.default.mkdir(scriptsDir);
1450
1625
  }
1451
1626
  await copyFilesFromTemplates(projectPath, ["scripts/minify-docker.cjs"]);
1452
1627
  }
1453
1628
  const pkg = await getProjectJson(projectPath);
1454
1629
  const mainFile = pkg?.main;
1455
- const templatePath = import_path.default.join(__dirname, "../templates/Dockerfile");
1630
+ const templatePath = import_path2.default.join(__dirname, "../templates/Dockerfile");
1456
1631
  await ejsRender(templatePath, { mainFile }, newPath);
1457
1632
  loading.succeed("Docker 初始化成功!");
1458
1633
  return;
@@ -1468,15 +1643,15 @@ async function initDocker(projectPath, answers) {
1468
1643
  dockerfile = "Dockerfile";
1469
1644
  break;
1470
1645
  }
1471
- const dockerfilePath = import_path.default.join(__dirname, "../templates/", dockerfile);
1472
- await import_fs_extra.default.copyFile(dockerfilePath, newPath);
1646
+ const dockerfilePath = import_path2.default.join(__dirname, "../templates/", dockerfile);
1647
+ await import_fs_extra3.default.copyFile(dockerfilePath, newPath);
1473
1648
  loading.succeed("Docker 初始化成功!");
1474
1649
  } catch (error) {
1475
1650
  loading.fail("Docker 初始化失败!");
1476
1651
  }
1477
1652
  }
1478
1653
  async function initTest(projectPath, answers) {
1479
- const loading = (0, import_ora.default)("正在初始化测试 ……").start();
1654
+ const loading = (0, import_ora2.default)("正在初始化测试 ……").start();
1480
1655
  try {
1481
1656
  if (answers.isInitTest === "vitest") {
1482
1657
  const files = ["vitest.config.ts"];
@@ -1539,40 +1714,40 @@ async function initTest(projectPath, answers) {
1539
1714
  }
1540
1715
  }
1541
1716
  async function jsFileExtRename(projectPath) {
1542
- const loading = (0, import_ora.default)("正在重命名 js 后缀名 ……").start();
1717
+ const loading = (0, import_ora2.default)("正在重命名 js 后缀名 ……").start();
1543
1718
  try {
1544
- const jsFiles = (await import_fs_extra.default.readdir(projectPath)).filter((file) => /\.js$/.test(file)).map((file) => import_path.default.join(projectPath, file));
1719
+ const jsFiles = (await import_fs_extra3.default.readdir(projectPath)).filter((file) => /\.js$/.test(file)).map((file) => import_path2.default.join(projectPath, file));
1545
1720
  const pkg = await getProjectJson(projectPath);
1546
1721
  if (pkg.type === "module") {
1547
1722
  for await (const filepath of jsFiles) {
1548
- const fileContent = await import_fs_extra.default.readFile(filepath, "utf-8");
1723
+ const fileContent = await import_fs_extra3.default.readFile(filepath, "utf-8");
1549
1724
  const moduleType = getJsModuleType(fileContent);
1550
1725
  console.log(`正在判断文件:${filepath} 的模块类型`);
1551
1726
  if (moduleType === "CommonJS") {
1552
- const dirpath = import_path.default.dirname(filepath);
1553
- const extname = import_path.default.extname(filepath);
1554
- const basename = `${import_path.default.basename(filepath, extname)}.cjs`;
1555
- const newPath = import_path.default.join(dirpath, basename);
1556
- if (await import_fs_extra.default.pathExists(newPath)) {
1557
- await import_fs_extra.default.remove(newPath);
1727
+ const dirpath = import_path2.default.dirname(filepath);
1728
+ const extname = import_path2.default.extname(filepath);
1729
+ const basename = `${import_path2.default.basename(filepath, extname)}.cjs`;
1730
+ const newPath = import_path2.default.join(dirpath, basename);
1731
+ if (await import_fs_extra3.default.pathExists(newPath)) {
1732
+ await import_fs_extra3.default.remove(newPath);
1558
1733
  }
1559
- await import_fs_extra.default.rename(filepath, newPath);
1734
+ await import_fs_extra3.default.rename(filepath, newPath);
1560
1735
  }
1561
1736
  }
1562
1737
  } else if (pkg.type === "commonjs") {
1563
1738
  for await (const filepath of jsFiles) {
1564
- const fileContent = await import_fs_extra.default.readFile(filepath, "utf-8");
1739
+ const fileContent = await import_fs_extra3.default.readFile(filepath, "utf-8");
1565
1740
  const moduleType = getJsModuleType(fileContent);
1566
1741
  console.log(`正在判断文件:${filepath} 的模块类型`);
1567
1742
  if (moduleType === "EsModule") {
1568
- const dirpath = import_path.default.dirname(filepath);
1569
- const extname = import_path.default.extname(filepath);
1570
- const basename = `${import_path.default.basename(filepath, extname)}.mjs`;
1571
- const newPath = import_path.default.join(dirpath, basename);
1572
- if (await import_fs_extra.default.pathExists(newPath)) {
1573
- await import_fs_extra.default.remove(newPath);
1743
+ const dirpath = import_path2.default.dirname(filepath);
1744
+ const extname = import_path2.default.extname(filepath);
1745
+ const basename = `${import_path2.default.basename(filepath, extname)}.mjs`;
1746
+ const newPath = import_path2.default.join(dirpath, basename);
1747
+ if (await import_fs_extra3.default.pathExists(newPath)) {
1748
+ await import_fs_extra3.default.remove(newPath);
1574
1749
  }
1575
- await import_fs_extra.default.rename(filepath, newPath);
1750
+ await import_fs_extra3.default.rename(filepath, newPath);
1576
1751
  }
1577
1752
  }
1578
1753
  }
@@ -1641,26 +1816,8 @@ async function sortProjectJson(projectPath) {
1641
1816
  console.error(error);
1642
1817
  }
1643
1818
  }
1644
- async function getAuthorWebsiteFromGithubAPI(githubUsername) {
1645
- try {
1646
- const userData = (await import_axios.default.get(`${GITHUB_API_URL}/users/${githubUsername}`)).data;
1647
- const authorWebsite = userData?.blog;
1648
- return authorWebsite || "";
1649
- } catch (error) {
1650
- console.error(error);
1651
- return "";
1652
- }
1653
- }
1654
- async function getLtsNodeVersionByIndexJson() {
1655
- const resp = await import_axios.default.get(NODE_INDEX_URL);
1656
- return resp.data?.find((e) => e.lts)?.version?.replace("v", "");
1657
- }
1658
- async function getLtsNodeVersionByHtml(url) {
1659
- const html = (await import_axios.default.get(url)).data;
1660
- return html.match(/<strong>(.*)<\/strong>/)?.[1]?.trim();
1661
- }
1662
1819
  async function getLtsNodeVersion() {
1663
- const loading = (0, import_ora.default)("正在获取 Node.js lts 版本号");
1820
+ const loading = (0, import_ora2.default)("正在获取 Node.js lts 版本号");
1664
1821
  loading.start();
1665
1822
  try {
1666
1823
  const fastUrl = await getFastUrl([...NODEJS_URLS, NODE_INDEX_URL]);
@@ -1679,32 +1836,10 @@ async function getLtsNodeVersion() {
1679
1836
  return "";
1680
1837
  }
1681
1838
  }
1682
- async function getFastUrl(urls) {
1683
- const fast = await Promise.any(urls.map((url) => (0, import_axios.default)({
1684
- url,
1685
- method: "HEAD",
1686
- timeout: 15 * 1e3,
1687
- headers: {
1688
- "Accept-Encoding": ""
1689
- }
1690
- })));
1691
- return fast?.config?.url;
1692
- }
1693
1839
  async function getNpmPackageVersion(name) {
1694
1840
  const version = await asyncExec(`${PACKAGE_MANAGER} view ${name} version`) || "";
1695
1841
  return version.trim();
1696
1842
  }
1697
- function lintMd(markdown) {
1698
- const rules = {
1699
- "no-empty-code": 0,
1700
- "no-trailing-punctuation": 0,
1701
- "no-long-code": 0,
1702
- "no-empty-code-lang": 0,
1703
- "no-empty-inlinecode": 0
1704
- };
1705
- const fixed = fix(markdown, rules);
1706
- return fixed;
1707
- }
1708
1843
  function sortKey(obj) {
1709
1844
  const keys = Object.keys(obj).sort((a, b) => a.localeCompare(b));
1710
1845
  const obj2 = {};
@@ -1714,77 +1849,54 @@ function sortKey(obj) {
1714
1849
  return obj2;
1715
1850
  }
1716
1851
  async function getProjectJson(projectPath) {
1717
- const pkgPath = import_path.default.join(projectPath, "package.json");
1718
- const pkg = await import_fs_extra.default.readJSON(pkgPath);
1852
+ const pkgPath = import_path2.default.join(projectPath, "package.json");
1853
+ const pkg = await import_fs_extra3.default.readJSON(pkgPath);
1719
1854
  return pkg;
1720
1855
  }
1721
1856
  async function saveProjectJson(projectPath, pkgData) {
1722
- const pkgPath = import_path.default.join(projectPath, "package.json");
1857
+ const pkgPath = import_path2.default.join(projectPath, "package.json");
1723
1858
  const pkg = await getProjectJson(projectPath);
1724
1859
  const newPkg = Object.assign({}, pkg, pkgData);
1725
- await import_fs_extra.default.writeFile(pkgPath, JSON.stringify(newPkg, null, 2));
1860
+ await import_fs_extra3.default.writeFile(pkgPath, JSON.stringify(newPkg, null, 2));
1726
1861
  }
1727
- async function copyFilesFromTemplates(projectPath, files, lazy = false) {
1728
- const loading = (0, import_ora.default)(`正在复制文件 ${files.join()} ……`).start();
1729
- try {
1730
- for await (const file of files) {
1731
- const templatePath = import_path.default.join(__dirname, "../templates/", file);
1732
- const newPath = import_path.default.join(projectPath, file);
1733
- if (await import_fs_extra.default.pathExists(newPath)) {
1734
- if (lazy) {
1735
- continue;
1736
- }
1737
- await import_fs_extra.default.remove(newPath);
1862
+
1863
+ // src/plopfile.ts
1864
+ var import_fs_extra4 = __toESM(require("fs-extra"));
1865
+ var import_path3 = __toESM(require("path"));
1866
+
1867
+ // src/utils/exec.ts
1868
+ var import_child_process2 = require("child_process");
1869
+ var import_colors2 = __toESM(require("@colors/colors"));
1870
+ async function asyncExec2(cmd, options) {
1871
+ return new Promise((resolve, reject) => {
1872
+ const ls = (0, import_child_process2.exec)(cmd, options, (err, stdout, stderr) => {
1873
+ if (err) {
1874
+ return reject(err);
1738
1875
  }
1739
- await import_fs_extra.default.copyFile(templatePath, newPath);
1740
- }
1741
- loading.succeed(`文件 ${files.join()} 复制成功!`);
1742
- return true;
1743
- } catch (error) {
1744
- loading.fail(`文件 ${files.join()} 复制失败!`);
1745
- throw error;
1746
- }
1876
+ if (stderr) {
1877
+ return resolve(stderr);
1878
+ }
1879
+ resolve(stdout);
1880
+ });
1881
+ ls.stdout.on("data", (data) => {
1882
+ console.log(data);
1883
+ });
1884
+ ls.stderr.on("data", (data) => {
1885
+ console.log(import_colors2.default.red(data));
1886
+ });
1887
+ });
1747
1888
  }
1748
- async function removeFiles(projectPath, files) {
1749
- const loading = (0, import_ora.default)(`正在删除文件 ${files.join()} ……`).start();
1889
+
1890
+ // src/utils/git.ts
1891
+ async function getGitUserName() {
1750
1892
  try {
1751
- for await (const file of files) {
1752
- const newPath = import_path.default.join(projectPath, file);
1753
- if (await import_fs_extra.default.pathExists(newPath)) {
1754
- await import_fs_extra.default.remove(newPath);
1755
- } else {
1756
- console.log(`文件 ${file} 不存在,已跳过删除`);
1757
- }
1758
- }
1759
- loading.succeed(`文件 ${files.join()} 删除成功!`);
1760
- return true;
1893
+ return (await asyncExec2("git config user.name"))?.trim();
1761
1894
  } catch (error) {
1762
- loading.fail(`文件 ${files.join()} 删除失败!`);
1763
- throw error;
1895
+ return "";
1764
1896
  }
1765
1897
  }
1766
- function kebabCase(str) {
1767
- return str.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/_+/g, "-").replace(/\s+/g, "-").toLowerCase();
1768
- }
1769
- function getTemplateMeta(template) {
1770
- return TEMPLATES_META_LIST.find((e) => e.name === template);
1771
- }
1772
- async function ejsRender(templatePath, data, outputPath) {
1773
- const template = (await import_fs_extra.default.readFile(templatePath, "utf8")).toString();
1774
- const content = await import_ejs.default.render(
1775
- template,
1776
- data,
1777
- {
1778
- debug: false,
1779
- async: true
1780
- }
1781
- );
1782
- await import_fs_extra.default.writeFile(outputPath, content);
1783
- }
1784
1898
 
1785
1899
  // src/plopfile.ts
1786
- var import_fs_extra2 = __toESM(require("fs-extra"));
1787
- var import_path2 = __toESM(require("path"));
1788
1900
  module.exports = function(plop) {
1789
1901
  plop.setActionType("initProject", initProject);
1790
1902
  plop.setGenerator("create", {
@@ -1905,7 +2017,7 @@ module.exports = function(plop) {
1905
2017
  name: "license",
1906
2018
  message: "请选择开源协议",
1907
2019
  async choices() {
1908
- return import_fs_extra2.default.readdir(import_path2.default.join(__dirname, "../templates/licenses/"));
2020
+ return import_fs_extra4.default.readdir(import_path3.default.join(__dirname, "../templates/licenses/"));
1909
2021
  },
1910
2022
  default: "MIT",
1911
2023
  when(answers) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cmyr-template-cli",
3
- "version": "1.35.2",
3
+ "version": "1.36.0",
4
4
  "description": "草梅友仁自制的项目模板创建器",
5
5
  "author": "CaoMeiYouRen",
6
6
  "license": "MIT",
@@ -38,6 +38,7 @@
38
38
  "@types/ejs": "^3.1.0",
39
39
  "@types/fs-extra": "^11.0.0",
40
40
  "@types/inquirer": "^9.0.3",
41
+ "@types/libsodium-wrappers": "^0.7.14",
41
42
  "@types/lodash": "^4.14.165",
42
43
  "@types/node": "^22.0.0",
43
44
  "@typescript-eslint/eslint-plugin": "7.18.0",
@@ -71,6 +72,7 @@
71
72
  "ejs": "^3.1.6",
72
73
  "fs-extra": "^11.0.0",
73
74
  "json5": "^2.2.1",
75
+ "libsodium-wrappers": "^0.7.15",
74
76
  "lodash": "^4.17.20",
75
77
  "minimist": "^1.2.5",
76
78
  "ora": "^5.4.1",