cmyr-template-cli 1.7.0 → 1.7.4

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.6.0" , '-v, --version');
16
+ program.version("1.7.3" , '-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
@@ -115,7 +115,7 @@ async function initProject(answers) {
115
115
  }
116
116
  async function init(projectPath, answers) {
117
117
  var _a;
118
- const { isOpenSource, isRemoveDependabot, gitRemoteUrl, isInitReadme, isInitContributing, isInitHusky } = answers;
118
+ const { isOpenSource, isRemoveDependabot, gitRemoteUrl, isInitReadme, isInitContributing, isInitHusky, isInitSemanticRelease } = answers;
119
119
  try {
120
120
  await asyncExec('git --version', {
121
121
  cwd: projectPath,
@@ -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,13 +161,11 @@ async function init(projectPath, answers) {
155
161
  if (info.licenseName === 'MIT') {
156
162
  await initLicense(projectPath, info);
157
163
  }
158
- if (isInitHusky) {
159
- await initHusky(projectPath, info);
160
- }
161
164
  }
162
- await initGithubWorkflows(projectPath, info);
165
+ await initGithubWorkflows(projectPath, answers);
163
166
  }
164
167
  await initConfig(projectPath);
168
+ await sortProjectJson(projectPath);
165
169
  await asyncExec('git add .', {
166
170
  cwd: projectPath,
167
171
  });
@@ -209,8 +213,7 @@ async function initProjectJson(projectPath, answers) {
209
213
  const gitUrl = `git+${repositoryUrl}.git`;
210
214
  const nodeVersion = await getLtsNodeVersion() || '16';
211
215
  const node = Number(nodeVersion) - 4;
212
- const pkgPath = path__default["default"].join(projectPath, 'package.json');
213
- const pkg = await fs__default["default"].readJSON(pkgPath);
216
+ const pkg = await getProjectJson(projectPath);
214
217
  const pkgData = {
215
218
  name,
216
219
  author,
@@ -218,8 +221,13 @@ async function initProjectJson(projectPath, answers) {
218
221
  private: !isPublishToNpm,
219
222
  license: 'UNLICENSED',
220
223
  engines: {
224
+ ...(pkg === null || pkg === void 0 ? void 0 : pkg.engines) || {},
221
225
  node: `>=${node}`,
222
226
  },
227
+ devDependencies: {
228
+ ...pkg === null || pkg === void 0 ? void 0 : pkg.devDependencies,
229
+ 'eslint-config-cmyr': `^${await getNpmPackageVersion('eslint-config-cmyr')}`,
230
+ },
223
231
  };
224
232
  let extData = {};
225
233
  if (isOpenSource) {
@@ -233,18 +241,13 @@ async function initProjectJson(projectPath, answers) {
233
241
  bugs: {
234
242
  url: issuesUrl,
235
243
  },
236
- devDependencies: {
237
- 'conventional-changelog-cli': '^2.1.1',
238
- 'conventional-changelog-cmyr-config': `^${await getNpmPackageVersion('conventional-changelog-cmyr-config')}`,
239
- ...pkg === null || pkg === void 0 ? void 0 : pkg.devDependencies,
240
- },
241
244
  changelog: {
242
245
  language: 'zh',
243
246
  },
244
247
  };
245
248
  }
246
249
  const newPkg = Object.assign({}, pkg, pkgData, extData);
247
- await fs__default["default"].writeFile(pkgPath, JSON.stringify(newPkg, null, 2));
250
+ await saveProjectJson(projectPath, newPkg);
248
251
  loading.succeed('package.json 初始化成功!');
249
252
  return newPkg;
250
253
  }
@@ -255,13 +258,12 @@ async function initProjectJson(projectPath, answers) {
255
258
  }
256
259
  const cleanText = (text) => text.replace(/-/g, '--').replace(/_/g, '__');
257
260
  async function getProjectInfo(projectPath, answers) {
258
- var _a, _b, _c, _d, _e;
261
+ var _a, _b, _c, _d, _e, _f;
259
262
  const loading = ora__default["default"]('正在获取项目信息 ……').start();
260
263
  try {
261
264
  const { name, author, description, isOpenSource, isPublishToNpm } = answers;
262
265
  const packageManager = 'npm';
263
- const pkgPath = path__default["default"].join(projectPath, 'package.json');
264
- const pkg = await fs__default["default"].readJSON(pkgPath);
266
+ const pkg = await getProjectJson(projectPath);
265
267
  const engines = (pkg === null || pkg === void 0 ? void 0 : pkg.engines) || {};
266
268
  const license = pkg === null || pkg === void 0 ? void 0 : pkg.license;
267
269
  const version = pkg === null || pkg === void 0 ? void 0 : pkg.version;
@@ -271,6 +273,7 @@ async function getProjectInfo(projectPath, answers) {
271
273
  const buildCommand = ((_c = pkg === null || pkg === void 0 ? void 0 : pkg.scripts) === null || _c === void 0 ? void 0 : _c.build) && `${packageManager} run build`;
272
274
  const testCommand = ((_d = pkg === null || pkg === void 0 ? void 0 : pkg.scripts) === null || _d === void 0 ? void 0 : _d.test) && `${packageManager} run test`;
273
275
  const lintCommand = ((_e = pkg === null || pkg === void 0 ? void 0 : pkg.scripts) === null || _e === void 0 ? void 0 : _e.lint) && `${packageManager} run lint`;
276
+ const commitCommand = ((_f = pkg === null || pkg === void 0 ? void 0 : pkg.scripts) === null || _f === void 0 ? void 0 : _f.commit) && `${packageManager} run commit`;
274
277
  const repositoryUrl = `https://github.com/${author}/${name}`;
275
278
  const issuesUrl = `${repositoryUrl}/issues`;
276
279
  const contributingUrl = `${repositoryUrl}/blob/master/CONTRIBUTING.md`;
@@ -310,6 +313,7 @@ async function getProjectInfo(projectPath, answers) {
310
313
  buildCommand,
311
314
  testCommand,
312
315
  lintCommand,
316
+ commitCommand,
313
317
  isJSProject: true,
314
318
  packageManager,
315
319
  isProjectOnNpm: isPublishToNpm,
@@ -415,22 +419,18 @@ async function initConfig(projectPath) {
415
419
  console.error(error);
416
420
  }
417
421
  }
418
- async function initGithubWorkflows(projectPath, projectInfos) {
422
+ async function initGithubWorkflows(projectPath, answers) {
419
423
  const loading = ora__default["default"]('正在初始化 Github Workflows ……').start();
420
424
  try {
421
- const { isPublishToNpm } = projectInfos;
425
+ const { isInitSemanticRelease } = answers;
422
426
  const files = ['.github/workflows/test.yml'];
423
427
  const dir = path__default["default"].join(projectPath, '.github/workflows');
424
428
  if (!await fs__default["default"].pathExists(dir)) {
425
429
  await fs__default["default"].mkdirp(dir);
426
430
  }
427
431
  const releaseYml = '.github/workflows/release.yml';
428
- if (isPublishToNpm) {
432
+ if (isInitSemanticRelease) {
429
433
  files.push(releaseYml);
430
- const oldReleaseYml = path__default["default"].join(projectPath, '.github/release.yml');
431
- if (await fs__default["default"].pathExists(oldReleaseYml)) {
432
- await fs__default["default"].remove(oldReleaseYml);
433
- }
434
434
  }
435
435
  else {
436
436
  const oldReleaseYml = path__default["default"].join(projectPath, releaseYml);
@@ -438,6 +438,10 @@ async function initGithubWorkflows(projectPath, projectInfos) {
438
438
  await fs__default["default"].remove(oldReleaseYml);
439
439
  }
440
440
  }
441
+ const oldReleaseYml = path__default["default"].join(projectPath, '.github/release.yml');
442
+ if (await fs__default["default"].pathExists(oldReleaseYml)) {
443
+ await fs__default["default"].remove(oldReleaseYml);
444
+ }
441
445
  files.forEach(async (file) => {
442
446
  const templatePath = path__default["default"].join(__dirname, '../templates/', file);
443
447
  const newPath = path__default["default"].join(projectPath, file);
@@ -453,7 +457,44 @@ async function initGithubWorkflows(projectPath, projectInfos) {
453
457
  console.error(error);
454
458
  }
455
459
  }
456
- async function initHusky(projectPath, projectInfos) {
460
+ async function initSemanticRelease(projectPath) {
461
+ const loading = ora__default["default"]('正在初始化 semantic-release ……').start();
462
+ try {
463
+ const files = ['.releaserc.js'];
464
+ files.forEach(async (file) => {
465
+ const templatePath = path__default["default"].join(__dirname, '../templates/', file);
466
+ const newPath = path__default["default"].join(projectPath, file);
467
+ if (await fs__default["default"].pathExists(newPath)) {
468
+ await fs__default["default"].remove(newPath);
469
+ }
470
+ await fs__default["default"].copyFile(templatePath, newPath);
471
+ });
472
+ const pkg = await getProjectJson(projectPath);
473
+ const devDependencies = {
474
+ '@semantic-release/changelog': '^6.0.1',
475
+ '@semantic-release/git': '^10.0.1',
476
+ 'semantic-release': '^18.0.1',
477
+ };
478
+ const pkgData = {
479
+ scripts: {
480
+ release: 'semantic-release',
481
+ ...pkg === null || pkg === void 0 ? void 0 : pkg.scripts,
482
+ },
483
+ devDependencies: {
484
+ ...devDependencies,
485
+ ...pkg === null || pkg === void 0 ? void 0 : pkg.devDependencies,
486
+ 'conventional-changelog-cmyr-config': `^${await getNpmPackageVersion('conventional-changelog-cmyr-config')}`,
487
+ },
488
+ };
489
+ await saveProjectJson(projectPath, pkgData);
490
+ loading.succeed('semantic-release 初始化成功!');
491
+ }
492
+ catch (error) {
493
+ loading.fail('semantic-release 初始化失败!');
494
+ console.error(error);
495
+ }
496
+ }
497
+ async function initHusky(projectPath) {
457
498
  var _a, _b;
458
499
  const loading = ora__default["default"]('正在初始化 husky ……').start();
459
500
  try {
@@ -471,8 +512,7 @@ async function initHusky(projectPath, projectInfos) {
471
512
  await fs__default["default"].copyFile(templatePath, newPath);
472
513
  });
473
514
  const extnames = ['js', 'ts'];
474
- const pkgPath = path__default["default"].join(projectPath, 'package.json');
475
- const pkg = await fs__default["default"].readJSON(pkgPath);
515
+ const pkg = await getProjectJson(projectPath);
476
516
  if ((_a = pkg === null || pkg === void 0 ? void 0 : pkg.dependencies) === null || _a === void 0 ? void 0 : _a.vue) {
477
517
  extnames.push('vue');
478
518
  }
@@ -489,6 +529,11 @@ async function initHusky(projectPath, projectInfos) {
489
529
  'lint-staged': '^12.1.2',
490
530
  };
491
531
  const pkgData = {
532
+ scripts: {
533
+ commit: 'cz',
534
+ ...pkg === null || pkg === void 0 ? void 0 : pkg.scripts,
535
+ prepare: 'husky install',
536
+ },
492
537
  devDependencies: {
493
538
  ...devDependencies,
494
539
  ...pkg === null || pkg === void 0 ? void 0 : pkg.devDependencies,
@@ -506,8 +551,7 @@ async function initHusky(projectPath, projectInfos) {
506
551
  ],
507
552
  },
508
553
  };
509
- const newPkg = Object.assign({}, pkg, pkgData);
510
- await fs__default["default"].writeFile(pkgPath, JSON.stringify(newPkg, null, 2));
554
+ await saveProjectJson(projectPath, pkgData);
511
555
  loading.succeed('husky 初始化成功!');
512
556
  }
513
557
  catch (error) {
@@ -515,6 +559,19 @@ async function initHusky(projectPath, projectInfos) {
515
559
  console.error(error);
516
560
  }
517
561
  }
562
+ async function sortProjectJson(projectPath) {
563
+ try {
564
+ const pkg = await getProjectJson(projectPath);
565
+ const pkgData = {
566
+ dependencies: sortKey((pkg === null || pkg === void 0 ? void 0 : pkg.dependencies) || {}),
567
+ devDependencies: sortKey((pkg === null || pkg === void 0 ? void 0 : pkg.devDependencies) || {}),
568
+ };
569
+ await saveProjectJson(projectPath, pkgData);
570
+ }
571
+ catch (error) {
572
+ console.error(error);
573
+ }
574
+ }
518
575
  async function getAuthorWebsiteFromGithubAPI(githubUsername) {
519
576
  try {
520
577
  const userData = (await axios__default["default"].get(`${GITHUB_API_URL}/users/${githubUsername}`)).data;
@@ -553,6 +610,25 @@ function lintMd(markdown) {
553
610
  const fixed = core.fix(markdown, rules);
554
611
  return fixed;
555
612
  }
613
+ function sortKey(obj) {
614
+ const keys = Object.keys(obj).sort((a, b) => a.localeCompare(b));
615
+ const obj2 = {};
616
+ keys.forEach((e) => {
617
+ obj2[e] = obj[e];
618
+ });
619
+ return obj2;
620
+ }
621
+ async function getProjectJson(projectPath) {
622
+ const pkgPath = path__default["default"].join(projectPath, 'package.json');
623
+ const pkg = await fs__default["default"].readJSON(pkgPath);
624
+ return pkg;
625
+ }
626
+ async function saveProjectJson(projectPath, pkgData) {
627
+ const pkgPath = path__default["default"].join(projectPath, 'package.json');
628
+ const pkg = await getProjectJson(projectPath);
629
+ const newPkg = Object.assign({}, pkg, pkgData);
630
+ await fs__default["default"].writeFile(pkgPath, JSON.stringify(newPkg, null, 2));
631
+ }
556
632
 
557
633
  module.exports = function (plop) {
558
634
  plop.setActionType('initProject', initProject);
@@ -654,11 +730,26 @@ module.exports = function (plop) {
654
730
  return answers.isOpenSource;
655
731
  },
656
732
  },
733
+ {
734
+ type: 'confirm',
735
+ name: 'isInitSemanticRelease',
736
+ message: '是否初始化 semantic-release?',
737
+ default(answers) {
738
+ const { isPublishToNpm } = answers;
739
+ return isPublishToNpm;
740
+ },
741
+ when(answers) {
742
+ return answers.isOpenSource;
743
+ },
744
+ },
657
745
  {
658
746
  type: 'confirm',
659
747
  name: 'isInitHusky',
660
748
  message: '是否初始化 husky?',
661
- default: false,
749
+ default(answers) {
750
+ const { isPublishToNpm } = answers;
751
+ return isPublishToNpm;
752
+ },
662
753
  when(answers) {
663
754
  return answers.isOpenSource;
664
755
  },
@@ -676,7 +767,10 @@ module.exports = function (plop) {
676
767
  type: 'confirm',
677
768
  name: 'isInitContributing',
678
769
  message: '是否初始化 贡献指南(CONTRIBUTING.md) ?',
679
- default: true,
770
+ default(answers) {
771
+ const { isPublishToNpm } = answers;
772
+ return isPublishToNpm;
773
+ },
680
774
  when(answers) {
681
775
  return answers.isOpenSource;
682
776
  },
@@ -690,6 +784,15 @@ module.exports = function (plop) {
690
784
  return answers.isOpenSource;
691
785
  },
692
786
  },
787
+ {
788
+ type: 'confirm',
789
+ name: 'isEnableAfdian',
790
+ message: '是否启用爱发电 ?',
791
+ default: false,
792
+ when(answers) {
793
+ return answers.isOpenSource;
794
+ },
795
+ },
693
796
  ];
694
797
  return inquirer.prompt(questions);
695
798
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cmyr-template-cli",
3
- "version": "1.7.0",
3
+ "version": "1.7.4",
4
4
  "description": "草梅友仁自制的项目模板创建器",
5
5
  "author": "CaoMeiYouRen",
6
6
  "license": "MIT",
@@ -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"
@@ -0,0 +1,36 @@
1
+ const { name } = require('./package.json')
2
+ module.exports = {
3
+ plugins: [
4
+ [
5
+ "@semantic-release/commit-analyzer",
6
+ {
7
+ "config": "conventional-changelog-cmyr-config"
8
+ }
9
+ ],
10
+ [
11
+ "@semantic-release/release-notes-generator",
12
+ {
13
+ "config": "conventional-changelog-cmyr-config"
14
+ }
15
+ ],
16
+ [
17
+ "@semantic-release/changelog",
18
+ {
19
+ "changelogFile": "CHANGELOG.md",
20
+ "changelogTitle": "# " + name
21
+ }
22
+ ],
23
+ '@semantic-release/npm',
24
+ '@semantic-release/github',
25
+ [
26
+ "@semantic-release/git",
27
+ {
28
+ "assets": [
29
+ "src",
30
+ "CHANGELOG.md",
31
+ "package.json"
32
+ ]
33
+ }
34
+ ]
35
+ ]
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