cmyr-template-cli 1.7.2 → 1.7.6

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 CHANGED
@@ -13,7 +13,7 @@ var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
13
13
 
14
14
  const program = new commander.Command('ct')
15
15
  .description('草梅项目创建器');
16
- program.version("1.7.1" , '-v, --version');
16
+ program.version("1.7.5" , '-v, --version');
17
17
  const args = process.argv.slice(2);
18
18
  if (args.length === 0) {
19
19
  args.push('create');
package/dist/plopfile.js CHANGED
@@ -143,6 +143,12 @@ async function init(projectPath, answers) {
143
143
  }
144
144
  }
145
145
  const newPkg = await initProjectJson(projectPath, answers);
146
+ if (isInitSemanticRelease) {
147
+ await initSemanticRelease(projectPath);
148
+ }
149
+ if (isInitHusky) {
150
+ await initHusky(projectPath);
151
+ }
146
152
  if (isOpenSource) {
147
153
  const info = await getProjectInfo(projectPath, answers);
148
154
  if (info) {
@@ -155,16 +161,12 @@ async function init(projectPath, answers) {
155
161
  if (info.licenseName === 'MIT') {
156
162
  await initLicense(projectPath, info);
157
163
  }
158
- if (isInitSemanticRelease) {
159
- await initSemanticRelease(projectPath, info);
160
- }
161
- if (isInitHusky) {
162
- await initHusky(projectPath, info);
163
- }
164
164
  }
165
- await initGithubWorkflows(projectPath, info);
165
+ await initGithubWorkflows(projectPath, answers);
166
166
  }
167
167
  await initConfig(projectPath);
168
+ await initCommitizen(projectPath);
169
+ await sortProjectJson(projectPath);
168
170
  await asyncExec('git add .', {
169
171
  cwd: projectPath,
170
172
  });
@@ -212,8 +214,7 @@ async function initProjectJson(projectPath, answers) {
212
214
  const gitUrl = `git+${repositoryUrl}.git`;
213
215
  const nodeVersion = await getLtsNodeVersion() || '16';
214
216
  const node = Number(nodeVersion) - 4;
215
- const pkgPath = path__default["default"].join(projectPath, 'package.json');
216
- const pkg = await fs__default["default"].readJSON(pkgPath);
217
+ const pkg = await getProjectJson(projectPath);
217
218
  const pkgData = {
218
219
  name,
219
220
  author,
@@ -221,8 +222,13 @@ async function initProjectJson(projectPath, answers) {
221
222
  private: !isPublishToNpm,
222
223
  license: 'UNLICENSED',
223
224
  engines: {
225
+ ...(pkg === null || pkg === void 0 ? void 0 : pkg.engines) || {},
224
226
  node: `>=${node}`,
225
227
  },
228
+ devDependencies: {
229
+ ...pkg === null || pkg === void 0 ? void 0 : pkg.devDependencies,
230
+ 'eslint-config-cmyr': `^${await getNpmPackageVersion('eslint-config-cmyr')}`,
231
+ },
226
232
  };
227
233
  let extData = {};
228
234
  if (isOpenSource) {
@@ -242,7 +248,7 @@ async function initProjectJson(projectPath, answers) {
242
248
  };
243
249
  }
244
250
  const newPkg = Object.assign({}, pkg, pkgData, extData);
245
- await fs__default["default"].writeFile(pkgPath, JSON.stringify(newPkg, null, 2));
251
+ await saveProjectJson(projectPath, newPkg);
246
252
  loading.succeed('package.json 初始化成功!');
247
253
  return newPkg;
248
254
  }
@@ -253,13 +259,12 @@ async function initProjectJson(projectPath, answers) {
253
259
  }
254
260
  const cleanText = (text) => text.replace(/-/g, '--').replace(/_/g, '__');
255
261
  async function getProjectInfo(projectPath, answers) {
256
- var _a, _b, _c, _d, _e;
262
+ var _a, _b, _c, _d, _e, _f;
257
263
  const loading = ora__default["default"]('正在获取项目信息 ……').start();
258
264
  try {
259
265
  const { name, author, description, isOpenSource, isPublishToNpm } = answers;
260
266
  const packageManager = 'npm';
261
- const pkgPath = path__default["default"].join(projectPath, 'package.json');
262
- const pkg = await fs__default["default"].readJSON(pkgPath);
267
+ const pkg = await getProjectJson(projectPath);
263
268
  const engines = (pkg === null || pkg === void 0 ? void 0 : pkg.engines) || {};
264
269
  const license = pkg === null || pkg === void 0 ? void 0 : pkg.license;
265
270
  const version = pkg === null || pkg === void 0 ? void 0 : pkg.version;
@@ -269,6 +274,7 @@ async function getProjectInfo(projectPath, answers) {
269
274
  const buildCommand = ((_c = pkg === null || pkg === void 0 ? void 0 : pkg.scripts) === null || _c === void 0 ? void 0 : _c.build) && `${packageManager} run build`;
270
275
  const testCommand = ((_d = pkg === null || pkg === void 0 ? void 0 : pkg.scripts) === null || _d === void 0 ? void 0 : _d.test) && `${packageManager} run test`;
271
276
  const lintCommand = ((_e = pkg === null || pkg === void 0 ? void 0 : pkg.scripts) === null || _e === void 0 ? void 0 : _e.lint) && `${packageManager} run lint`;
277
+ const commitCommand = ((_f = pkg === null || pkg === void 0 ? void 0 : pkg.scripts) === null || _f === void 0 ? void 0 : _f.commit) && `${packageManager} run commit`;
272
278
  const repositoryUrl = `https://github.com/${author}/${name}`;
273
279
  const issuesUrl = `${repositoryUrl}/issues`;
274
280
  const contributingUrl = `${repositoryUrl}/blob/master/CONTRIBUTING.md`;
@@ -308,6 +314,7 @@ async function getProjectInfo(projectPath, answers) {
308
314
  buildCommand,
309
315
  testCommand,
310
316
  lintCommand,
317
+ commitCommand,
311
318
  isJSProject: true,
312
319
  packageManager,
313
320
  isProjectOnNpm: isPublishToNpm,
@@ -413,10 +420,10 @@ async function initConfig(projectPath) {
413
420
  console.error(error);
414
421
  }
415
422
  }
416
- async function initGithubWorkflows(projectPath, projectInfos) {
423
+ async function initGithubWorkflows(projectPath, answers) {
417
424
  const loading = ora__default["default"]('正在初始化 Github Workflows ……').start();
418
425
  try {
419
- const { isInitSemanticRelease } = projectInfos;
426
+ const { isInitSemanticRelease } = answers;
420
427
  const files = ['.github/workflows/test.yml'];
421
428
  const dir = path__default["default"].join(projectPath, '.github/workflows');
422
429
  if (!await fs__default["default"].pathExists(dir)) {
@@ -425,10 +432,6 @@ async function initGithubWorkflows(projectPath, projectInfos) {
425
432
  const releaseYml = '.github/workflows/release.yml';
426
433
  if (isInitSemanticRelease) {
427
434
  files.push(releaseYml);
428
- const oldReleaseYml = path__default["default"].join(projectPath, '.github/release.yml');
429
- if (await fs__default["default"].pathExists(oldReleaseYml)) {
430
- await fs__default["default"].remove(oldReleaseYml);
431
- }
432
435
  }
433
436
  else {
434
437
  const oldReleaseYml = path__default["default"].join(projectPath, releaseYml);
@@ -436,6 +439,10 @@ async function initGithubWorkflows(projectPath, projectInfos) {
436
439
  await fs__default["default"].remove(oldReleaseYml);
437
440
  }
438
441
  }
442
+ const oldReleaseYml = path__default["default"].join(projectPath, '.github/release.yml');
443
+ if (await fs__default["default"].pathExists(oldReleaseYml)) {
444
+ await fs__default["default"].remove(oldReleaseYml);
445
+ }
439
446
  files.forEach(async (file) => {
440
447
  const templatePath = path__default["default"].join(__dirname, '../templates/', file);
441
448
  const newPath = path__default["default"].join(projectPath, file);
@@ -451,7 +458,7 @@ async function initGithubWorkflows(projectPath, projectInfos) {
451
458
  console.error(error);
452
459
  }
453
460
  }
454
- async function initSemanticRelease(projectPath, projectInfos) {
461
+ async function initSemanticRelease(projectPath) {
455
462
  const loading = ora__default["default"]('正在初始化 semantic-release ……').start();
456
463
  try {
457
464
  const files = ['.releaserc.js'];
@@ -463,13 +470,10 @@ async function initSemanticRelease(projectPath, projectInfos) {
463
470
  }
464
471
  await fs__default["default"].copyFile(templatePath, newPath);
465
472
  });
466
- const pkgPath = path__default["default"].join(projectPath, 'package.json');
467
- const pkg = await fs__default["default"].readJSON(pkgPath);
473
+ const pkg = await getProjectJson(projectPath);
468
474
  const devDependencies = {
469
475
  '@semantic-release/changelog': '^6.0.1',
470
476
  '@semantic-release/git': '^10.0.1',
471
- 'conventional-changelog-cli': '^2.1.1',
472
- 'conventional-changelog-cmyr-config': `^${await getNpmPackageVersion('conventional-changelog-cmyr-config')}`,
473
477
  'semantic-release': '^18.0.1',
474
478
  };
475
479
  const pkgData = {
@@ -480,10 +484,10 @@ async function initSemanticRelease(projectPath, projectInfos) {
480
484
  devDependencies: {
481
485
  ...devDependencies,
482
486
  ...pkg === null || pkg === void 0 ? void 0 : pkg.devDependencies,
487
+ 'conventional-changelog-cmyr-config': `^${await getNpmPackageVersion('conventional-changelog-cmyr-config')}`,
483
488
  },
484
489
  };
485
- const newPkg = Object.assign({}, pkg, pkgData);
486
- await fs__default["default"].writeFile(pkgPath, JSON.stringify(newPkg, null, 2));
490
+ await saveProjectJson(projectPath, pkgData);
487
491
  loading.succeed('semantic-release 初始化成功!');
488
492
  }
489
493
  catch (error) {
@@ -491,7 +495,7 @@ async function initSemanticRelease(projectPath, projectInfos) {
491
495
  console.error(error);
492
496
  }
493
497
  }
494
- async function initHusky(projectPath, projectInfos) {
498
+ async function initHusky(projectPath) {
495
499
  var _a, _b;
496
500
  const loading = ora__default["default"]('正在初始化 husky ……').start();
497
501
  try {
@@ -509,8 +513,7 @@ async function initHusky(projectPath, projectInfos) {
509
513
  await fs__default["default"].copyFile(templatePath, newPath);
510
514
  });
511
515
  const extnames = ['js', 'ts'];
512
- const pkgPath = path__default["default"].join(projectPath, 'package.json');
513
- const pkg = await fs__default["default"].readJSON(pkgPath);
516
+ const pkg = await getProjectJson(projectPath);
514
517
  if ((_a = pkg === null || pkg === void 0 ? void 0 : pkg.dependencies) === null || _a === void 0 ? void 0 : _a.vue) {
515
518
  extnames.push('vue');
516
519
  }
@@ -521,14 +524,11 @@ async function initHusky(projectPath, projectInfos) {
521
524
  const devDependencies = {
522
525
  '@commitlint/cli': '^15.0.0',
523
526
  '@commitlint/config-conventional': '^15.0.0',
524
- commitizen: '^4.2.3',
525
- 'cz-conventional-changelog': '^3.3.0',
526
527
  husky: '^7.0.4',
527
528
  'lint-staged': '^12.1.2',
528
529
  };
529
530
  const pkgData = {
530
531
  scripts: {
531
- commit: 'cz',
532
532
  ...pkg === null || pkg === void 0 ? void 0 : pkg.scripts,
533
533
  prepare: 'husky install',
534
534
  },
@@ -537,11 +537,6 @@ async function initHusky(projectPath, projectInfos) {
537
537
  ...pkg === null || pkg === void 0 ? void 0 : pkg.devDependencies,
538
538
  },
539
539
  husky: undefined,
540
- config: {
541
- commitizen: {
542
- path: 'cz-conventional-changelog',
543
- },
544
- },
545
540
  'lint-staged': {
546
541
  [keyname]: [
547
542
  'npm run lint',
@@ -549,8 +544,7 @@ async function initHusky(projectPath, projectInfos) {
549
544
  ],
550
545
  },
551
546
  };
552
- const newPkg = Object.assign({}, pkg, pkgData);
553
- await fs__default["default"].writeFile(pkgPath, JSON.stringify(newPkg, null, 2));
547
+ await saveProjectJson(projectPath, pkgData);
554
548
  loading.succeed('husky 初始化成功!');
555
549
  }
556
550
  catch (error) {
@@ -558,6 +552,51 @@ async function initHusky(projectPath, projectInfos) {
558
552
  console.error(error);
559
553
  }
560
554
  }
555
+ async function initCommitizen(projectPath) {
556
+ const loading = ora__default["default"]('正在初始化 commitizen ……').start();
557
+ try {
558
+ const pkg = await getProjectJson(projectPath);
559
+ const devDependencies = {
560
+ commitizen: '^4.2.3',
561
+ 'cz-conventional-changelog-cmyr': `^${await getNpmPackageVersion('cz-conventional-changelog-cmyr')}`,
562
+ };
563
+ const pkgData = {
564
+ scripts: {
565
+ ...pkg === null || pkg === void 0 ? void 0 : pkg.scripts,
566
+ commit: 'cz',
567
+ },
568
+ devDependencies: {
569
+ ...devDependencies,
570
+ ...pkg === null || pkg === void 0 ? void 0 : pkg.devDependencies,
571
+ },
572
+ config: {
573
+ ...pkg === null || pkg === void 0 ? void 0 : pkg.config,
574
+ commitizen: {
575
+ path: './node_modules/cz-conventional-changelog-cmyr',
576
+ },
577
+ },
578
+ };
579
+ await saveProjectJson(projectPath, pkgData);
580
+ loading.succeed('commitizen 初始化成功!');
581
+ }
582
+ catch (error) {
583
+ console.error(error);
584
+ loading.fail('commitizen 初始化失败!');
585
+ }
586
+ }
587
+ async function sortProjectJson(projectPath) {
588
+ try {
589
+ const pkg = await getProjectJson(projectPath);
590
+ const pkgData = {
591
+ dependencies: sortKey((pkg === null || pkg === void 0 ? void 0 : pkg.dependencies) || {}),
592
+ devDependencies: sortKey((pkg === null || pkg === void 0 ? void 0 : pkg.devDependencies) || {}),
593
+ };
594
+ await saveProjectJson(projectPath, pkgData);
595
+ }
596
+ catch (error) {
597
+ console.error(error);
598
+ }
599
+ }
561
600
  async function getAuthorWebsiteFromGithubAPI(githubUsername) {
562
601
  try {
563
602
  const userData = (await axios__default["default"].get(`${GITHUB_API_URL}/users/${githubUsername}`)).data;
@@ -596,6 +635,25 @@ function lintMd(markdown) {
596
635
  const fixed = core.fix(markdown, rules);
597
636
  return fixed;
598
637
  }
638
+ function sortKey(obj) {
639
+ const keys = Object.keys(obj).sort((a, b) => a.localeCompare(b));
640
+ const obj2 = {};
641
+ keys.forEach((e) => {
642
+ obj2[e] = obj[e];
643
+ });
644
+ return obj2;
645
+ }
646
+ async function getProjectJson(projectPath) {
647
+ const pkgPath = path__default["default"].join(projectPath, 'package.json');
648
+ const pkg = await fs__default["default"].readJSON(pkgPath);
649
+ return pkg;
650
+ }
651
+ async function saveProjectJson(projectPath, pkgData) {
652
+ const pkgPath = path__default["default"].join(projectPath, 'package.json');
653
+ const pkg = await getProjectJson(projectPath);
654
+ const newPkg = Object.assign({}, pkg, pkgData);
655
+ await fs__default["default"].writeFile(pkgPath, JSON.stringify(newPkg, null, 2));
656
+ }
599
657
 
600
658
  module.exports = function (plop) {
601
659
  plop.setActionType('initProject', initProject);
@@ -751,6 +809,15 @@ module.exports = function (plop) {
751
809
  return answers.isOpenSource;
752
810
  },
753
811
  },
812
+ {
813
+ type: 'confirm',
814
+ name: 'isEnableAfdian',
815
+ message: '是否启用爱发电 ?',
816
+ default: false,
817
+ when(answers) {
818
+ return answers.isOpenSource;
819
+ },
820
+ },
754
821
  ];
755
822
  return inquirer.prompt(questions);
756
823
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cmyr-template-cli",
3
- "version": "1.7.2",
3
+ "version": "1.7.6",
4
4
  "description": "草梅友仁自制的项目模板创建器",
5
5
  "author": "CaoMeiYouRen",
6
6
  "license": "MIT",
@@ -26,7 +26,7 @@
26
26
  "rm": "rimraf node_modules",
27
27
  "start": "node ./dist/index",
28
28
  "release": "semantic-release",
29
- "commit": "git add . && git cz",
29
+ "commit": "cz",
30
30
  "create": "ct create",
31
31
  "build:dev": "rimraf dist && cross-env NODE_ENV=development rollup -c && rimraf temp && cross-env NODE_ENV=development ct create",
32
32
  "build:prod": "npm run build && rimraf temp && cross-env NODE_ENV=production ct create"
@@ -52,6 +52,7 @@
52
52
  "conventional-changelog-cmyr-config": "^1.2.3",
53
53
  "cross-env": "^7.0.2",
54
54
  "cz-conventional-changelog": "^3.3.0",
55
+ "cz-conventional-changelog-cmyr": "^1.0.0",
55
56
  "debug": "^4.3.1",
56
57
  "eslint": "^7.14.0",
57
58
  "eslint-config-cmyr": "^1.1.14",
@@ -83,7 +84,7 @@
83
84
  },
84
85
  "config": {
85
86
  "commitizen": {
86
- "path": "cz-conventional-changelog"
87
+ "path": "./node_modules/cz-conventional-changelog-cmyr"
87
88
  }
88
89
  },
89
90
  "changelog": {
@@ -10,7 +10,7 @@ jobs:
10
10
  steps:
11
11
  - uses: actions/checkout@v2
12
12
  - name: Setup Node.js environment
13
- uses: actions/setup-node@v2.1.2
13
+ uses: actions/setup-node@v2
14
14
  with:
15
15
  node-version: "lts/*"
16
16
  cache: "yarn"
@@ -7,10 +7,12 @@ module.exports = {
7
7
  "config": "conventional-changelog-cmyr-config"
8
8
  }
9
9
  ],
10
- ["@semantic-release/release-notes-generator",
10
+ [
11
+ "@semantic-release/release-notes-generator",
11
12
  {
12
13
  "config": "conventional-changelog-cmyr-config"
13
- }],
14
+ }
15
+ ],
14
16
  [
15
17
  "@semantic-release/changelog",
16
18
  {
@@ -31,4 +33,4 @@ module.exports = {
31
33
  }
32
34
  ]
33
35
  ]
34
- }
36
+ }
@@ -68,8 +68,8 @@
68
68
 
69
69
  - 若为 BUG 修复,则选择 `fix`
70
70
  - 若为新增功能,则选择 `feat`
71
- - 若为移除某些功能,则选择 `perf` 或填写 `BREAKING CHANGE`
72
- - `perf` 和其他破坏性更新,若不是为了修复 BUG,原则上将拒绝该 PR
71
+ - 若为移除某些功能,则选择 `BREAKING CHANGE`
72
+ - `BREAKING CHANGE` 和其他破坏性更新,若不是为了修复 BUG,原则上将拒绝该 PR
73
73
 
74
74
 
75
75
  5. 推送到分支 ( `git push origin feat/your_feature`)
@@ -8,7 +8,7 @@
8
8
  <% if (projectVersion && !isProjectOnNpm) { -%>
9
9
  <img alt="Version" src="https://img.shields.io/badge/version-<%= projectVersion %>-blue.svg?cacheSeconds=2592000" />
10
10
  <% } -%>
11
- <% if (isGithubRepos) { -%>
11
+ <% if (isGithubRepos && isInitSemanticRelease) { -%>
12
12
  <a href="<%= repositoryUrl %>/actions?query=workflow%3ARelease" target="_blank">
13
13
  <img alt="GitHub Workflow Status" src="https://img.shields.io/github/workflow/status/<%= authorGithubUsername %>/<%= projectName %>/Release">
14
14
  </a>
@@ -58,6 +58,7 @@
58
58
  ## 依赖要求
59
59
 
60
60
  <% projectPrerequisites.map(({ name, value }) => { -%>
61
+
61
62
  - <%= name %> <%= value %>
62
63
  <% }) -%>
63
64
  <% } -%>
@@ -109,6 +110,14 @@
109
110
  <%= lintCommand %>
110
111
  ```
111
112
  <% } -%>
113
+ <% if (commitCommand) { -%>
114
+
115
+ ## Commit
116
+
117
+ ```sh
118
+ <%= commitCommand %>
119
+ ```
120
+ <% } -%>
112
121
 
113
122
  <% if (authorName || authorGithubUsername) { -%>
114
123
 
@@ -131,10 +140,15 @@
131
140
  欢迎 贡献、提问或提出新功能!<br />如有问题请查看 [issues page](<%= issuesUrl %>). <br/><%= contributingUrl ? `贡献或提出新功能可以查看[contributing guide](${contributingUrl}).` : '' %>
132
141
  <% } -%>
133
142
 
134
- ## 支持
143
+ ## 💰支持
135
144
 
136
145
  如果觉得这个项目有用的话请给一颗⭐️,非常感谢
146
+ <% if (isEnableAfdian) { -%>
137
147
 
148
+ <a href="https://afdian.net/@<%= authorName %>">
149
+ <img src="https://cdn.jsdelivr.net/gh/CaoMeiYouRen/image-hosting-01@master/images/202112181214695.png">
150
+ </a>
151
+ <% } -%>
138
152
  <% if (licenseName && licenseUrl) { -%>
139
153
 
140
154
  ## 📝 License