cmyr-template-cli 1.7.3 → 1.8.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.
- package/dist/index.js +1 -1
- package/dist/plopfile.js +96 -36
- package/package.json +5 -4
- package/templates/.releaserc.js +5 -3
- package/templates/CONTRIBUTING.md +6 -2
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.
|
|
16
|
+
program.version("1.7.6" , '-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
|
@@ -132,16 +132,8 @@ async function init(projectPath, answers) {
|
|
|
132
132
|
});
|
|
133
133
|
console.info(colors__default["default"].green(`请在远程 Git 仓库初始化 ${gitRemoteUrl}`));
|
|
134
134
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
if (!isOpenSource || isRemoveDependabot) {
|
|
138
|
-
if (await fs__default["default"].pathExists(dependabotPath)) {
|
|
139
|
-
await fs__default["default"].remove(dependabotPath);
|
|
140
|
-
}
|
|
141
|
-
if (await fs__default["default"].pathExists(mergifyPath)) {
|
|
142
|
-
await fs__default["default"].remove(mergifyPath);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
135
|
+
await initDependabot(projectPath, answers);
|
|
136
|
+
await initYarn(projectPath, answers);
|
|
145
137
|
const newPkg = await initProjectJson(projectPath, answers);
|
|
146
138
|
if (isInitSemanticRelease) {
|
|
147
139
|
await initSemanticRelease(projectPath);
|
|
@@ -165,6 +157,7 @@ async function init(projectPath, answers) {
|
|
|
165
157
|
await initGithubWorkflows(projectPath, answers);
|
|
166
158
|
}
|
|
167
159
|
await initConfig(projectPath);
|
|
160
|
+
await initCommitizen(projectPath);
|
|
168
161
|
await sortProjectJson(projectPath);
|
|
169
162
|
await asyncExec('git add .', {
|
|
170
163
|
cwd: projectPath,
|
|
@@ -203,6 +196,38 @@ async function getGitUserName() {
|
|
|
203
196
|
const username = (await asyncExec('git config user.name')) || '';
|
|
204
197
|
return username.trim();
|
|
205
198
|
}
|
|
199
|
+
async function initDependabot(projectPath, answers) {
|
|
200
|
+
try {
|
|
201
|
+
const { isOpenSource, isRemoveDependabot } = answers;
|
|
202
|
+
const dependabotPath = path__default["default"].join(projectPath, '.github/dependabot.yml');
|
|
203
|
+
const mergifyPath = path__default["default"].join(projectPath, '.github/mergify.yml');
|
|
204
|
+
if (!isOpenSource || isRemoveDependabot) {
|
|
205
|
+
if (await fs__default["default"].pathExists(dependabotPath)) {
|
|
206
|
+
await fs__default["default"].remove(dependabotPath);
|
|
207
|
+
}
|
|
208
|
+
if (await fs__default["default"].pathExists(mergifyPath)) {
|
|
209
|
+
await fs__default["default"].remove(mergifyPath);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
catch (error) {
|
|
214
|
+
console.error(error);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
async function initYarn(projectPath, answers) {
|
|
218
|
+
try {
|
|
219
|
+
const { isRemoveYarn } = answers;
|
|
220
|
+
const yarnPath = path__default["default"].join(projectPath, 'yarn.lock');
|
|
221
|
+
if (isRemoveYarn) {
|
|
222
|
+
if (await fs__default["default"].pathExists(yarnPath)) {
|
|
223
|
+
await fs__default["default"].remove(yarnPath);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
catch (error) {
|
|
228
|
+
console.error(error);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
206
231
|
async function initProjectJson(projectPath, answers) {
|
|
207
232
|
const loading = ora__default["default"]('正在初始化 package.json ……').start();
|
|
208
233
|
try {
|
|
@@ -213,8 +238,7 @@ async function initProjectJson(projectPath, answers) {
|
|
|
213
238
|
const gitUrl = `git+${repositoryUrl}.git`;
|
|
214
239
|
const nodeVersion = await getLtsNodeVersion() || '16';
|
|
215
240
|
const node = Number(nodeVersion) - 4;
|
|
216
|
-
const
|
|
217
|
-
const pkg = await fs__default["default"].readJSON(pkgPath);
|
|
241
|
+
const pkg = await getProjectJson(projectPath);
|
|
218
242
|
const pkgData = {
|
|
219
243
|
name,
|
|
220
244
|
author,
|
|
@@ -248,7 +272,7 @@ async function initProjectJson(projectPath, answers) {
|
|
|
248
272
|
};
|
|
249
273
|
}
|
|
250
274
|
const newPkg = Object.assign({}, pkg, pkgData, extData);
|
|
251
|
-
await
|
|
275
|
+
await saveProjectJson(projectPath, newPkg);
|
|
252
276
|
loading.succeed('package.json 初始化成功!');
|
|
253
277
|
return newPkg;
|
|
254
278
|
}
|
|
@@ -264,8 +288,7 @@ async function getProjectInfo(projectPath, answers) {
|
|
|
264
288
|
try {
|
|
265
289
|
const { name, author, description, isOpenSource, isPublishToNpm } = answers;
|
|
266
290
|
const packageManager = 'npm';
|
|
267
|
-
const
|
|
268
|
-
const pkg = await fs__default["default"].readJSON(pkgPath);
|
|
291
|
+
const pkg = await getProjectJson(projectPath);
|
|
269
292
|
const engines = (pkg === null || pkg === void 0 ? void 0 : pkg.engines) || {};
|
|
270
293
|
const license = pkg === null || pkg === void 0 ? void 0 : pkg.license;
|
|
271
294
|
const version = pkg === null || pkg === void 0 ? void 0 : pkg.version;
|
|
@@ -471,12 +494,10 @@ async function initSemanticRelease(projectPath) {
|
|
|
471
494
|
}
|
|
472
495
|
await fs__default["default"].copyFile(templatePath, newPath);
|
|
473
496
|
});
|
|
474
|
-
const
|
|
475
|
-
const pkg = await fs__default["default"].readJSON(pkgPath);
|
|
497
|
+
const pkg = await getProjectJson(projectPath);
|
|
476
498
|
const devDependencies = {
|
|
477
499
|
'@semantic-release/changelog': '^6.0.1',
|
|
478
500
|
'@semantic-release/git': '^10.0.1',
|
|
479
|
-
'conventional-changelog-cli': '^2.1.1',
|
|
480
501
|
'semantic-release': '^18.0.1',
|
|
481
502
|
};
|
|
482
503
|
const pkgData = {
|
|
@@ -490,8 +511,7 @@ async function initSemanticRelease(projectPath) {
|
|
|
490
511
|
'conventional-changelog-cmyr-config': `^${await getNpmPackageVersion('conventional-changelog-cmyr-config')}`,
|
|
491
512
|
},
|
|
492
513
|
};
|
|
493
|
-
|
|
494
|
-
await fs__default["default"].writeFile(pkgPath, JSON.stringify(newPkg, null, 2));
|
|
514
|
+
await saveProjectJson(projectPath, pkgData);
|
|
495
515
|
loading.succeed('semantic-release 初始化成功!');
|
|
496
516
|
}
|
|
497
517
|
catch (error) {
|
|
@@ -517,8 +537,7 @@ async function initHusky(projectPath) {
|
|
|
517
537
|
await fs__default["default"].copyFile(templatePath, newPath);
|
|
518
538
|
});
|
|
519
539
|
const extnames = ['js', 'ts'];
|
|
520
|
-
const
|
|
521
|
-
const pkg = await fs__default["default"].readJSON(pkgPath);
|
|
540
|
+
const pkg = await getProjectJson(projectPath);
|
|
522
541
|
if ((_a = pkg === null || pkg === void 0 ? void 0 : pkg.dependencies) === null || _a === void 0 ? void 0 : _a.vue) {
|
|
523
542
|
extnames.push('vue');
|
|
524
543
|
}
|
|
@@ -529,14 +548,11 @@ async function initHusky(projectPath) {
|
|
|
529
548
|
const devDependencies = {
|
|
530
549
|
'@commitlint/cli': '^15.0.0',
|
|
531
550
|
'@commitlint/config-conventional': '^15.0.0',
|
|
532
|
-
commitizen: '^4.2.3',
|
|
533
|
-
'cz-conventional-changelog': '^3.3.0',
|
|
534
551
|
husky: '^7.0.4',
|
|
535
552
|
'lint-staged': '^12.1.2',
|
|
536
553
|
};
|
|
537
554
|
const pkgData = {
|
|
538
555
|
scripts: {
|
|
539
|
-
commit: 'cz',
|
|
540
556
|
...pkg === null || pkg === void 0 ? void 0 : pkg.scripts,
|
|
541
557
|
prepare: 'husky install',
|
|
542
558
|
},
|
|
@@ -545,11 +561,6 @@ async function initHusky(projectPath) {
|
|
|
545
561
|
...pkg === null || pkg === void 0 ? void 0 : pkg.devDependencies,
|
|
546
562
|
},
|
|
547
563
|
husky: undefined,
|
|
548
|
-
config: {
|
|
549
|
-
commitizen: {
|
|
550
|
-
path: 'cz-conventional-changelog',
|
|
551
|
-
},
|
|
552
|
-
},
|
|
553
564
|
'lint-staged': {
|
|
554
565
|
[keyname]: [
|
|
555
566
|
'npm run lint',
|
|
@@ -557,8 +568,7 @@ async function initHusky(projectPath) {
|
|
|
557
568
|
],
|
|
558
569
|
},
|
|
559
570
|
};
|
|
560
|
-
|
|
561
|
-
await fs__default["default"].writeFile(pkgPath, JSON.stringify(newPkg, null, 2));
|
|
571
|
+
await saveProjectJson(projectPath, pkgData);
|
|
562
572
|
loading.succeed('husky 初始化成功!');
|
|
563
573
|
}
|
|
564
574
|
catch (error) {
|
|
@@ -566,16 +576,46 @@ async function initHusky(projectPath) {
|
|
|
566
576
|
console.error(error);
|
|
567
577
|
}
|
|
568
578
|
}
|
|
579
|
+
async function initCommitizen(projectPath) {
|
|
580
|
+
const loading = ora__default["default"]('正在初始化 commitizen ……').start();
|
|
581
|
+
try {
|
|
582
|
+
const pkg = await getProjectJson(projectPath);
|
|
583
|
+
const devDependencies = {
|
|
584
|
+
commitizen: '^4.2.3',
|
|
585
|
+
'cz-conventional-changelog-cmyr': `^${await getNpmPackageVersion('cz-conventional-changelog-cmyr')}`,
|
|
586
|
+
};
|
|
587
|
+
const pkgData = {
|
|
588
|
+
scripts: {
|
|
589
|
+
...pkg === null || pkg === void 0 ? void 0 : pkg.scripts,
|
|
590
|
+
commit: 'cz',
|
|
591
|
+
},
|
|
592
|
+
devDependencies: {
|
|
593
|
+
...devDependencies,
|
|
594
|
+
...pkg === null || pkg === void 0 ? void 0 : pkg.devDependencies,
|
|
595
|
+
},
|
|
596
|
+
config: {
|
|
597
|
+
...pkg === null || pkg === void 0 ? void 0 : pkg.config,
|
|
598
|
+
commitizen: {
|
|
599
|
+
path: './node_modules/cz-conventional-changelog-cmyr',
|
|
600
|
+
},
|
|
601
|
+
},
|
|
602
|
+
};
|
|
603
|
+
await saveProjectJson(projectPath, pkgData);
|
|
604
|
+
loading.succeed('commitizen 初始化成功!');
|
|
605
|
+
}
|
|
606
|
+
catch (error) {
|
|
607
|
+
console.error(error);
|
|
608
|
+
loading.fail('commitizen 初始化失败!');
|
|
609
|
+
}
|
|
610
|
+
}
|
|
569
611
|
async function sortProjectJson(projectPath) {
|
|
570
612
|
try {
|
|
571
|
-
const
|
|
572
|
-
const pkg = await fs__default["default"].readJSON(pkgPath);
|
|
613
|
+
const pkg = await getProjectJson(projectPath);
|
|
573
614
|
const pkgData = {
|
|
574
615
|
dependencies: sortKey((pkg === null || pkg === void 0 ? void 0 : pkg.dependencies) || {}),
|
|
575
616
|
devDependencies: sortKey((pkg === null || pkg === void 0 ? void 0 : pkg.devDependencies) || {}),
|
|
576
617
|
};
|
|
577
|
-
|
|
578
|
-
await fs__default["default"].writeFile(pkgPath, JSON.stringify(newPkg, null, 2));
|
|
618
|
+
await saveProjectJson(projectPath, pkgData);
|
|
579
619
|
}
|
|
580
620
|
catch (error) {
|
|
581
621
|
console.error(error);
|
|
@@ -627,6 +667,17 @@ function sortKey(obj) {
|
|
|
627
667
|
});
|
|
628
668
|
return obj2;
|
|
629
669
|
}
|
|
670
|
+
async function getProjectJson(projectPath) {
|
|
671
|
+
const pkgPath = path__default["default"].join(projectPath, 'package.json');
|
|
672
|
+
const pkg = await fs__default["default"].readJSON(pkgPath);
|
|
673
|
+
return pkg;
|
|
674
|
+
}
|
|
675
|
+
async function saveProjectJson(projectPath, pkgData) {
|
|
676
|
+
const pkgPath = path__default["default"].join(projectPath, 'package.json');
|
|
677
|
+
const pkg = await getProjectJson(projectPath);
|
|
678
|
+
const newPkg = Object.assign({}, pkg, pkgData);
|
|
679
|
+
await fs__default["default"].writeFile(pkgPath, JSON.stringify(newPkg, null, 2));
|
|
680
|
+
}
|
|
630
681
|
|
|
631
682
|
module.exports = function (plop) {
|
|
632
683
|
plop.setActionType('initProject', initProject);
|
|
@@ -782,6 +833,15 @@ module.exports = function (plop) {
|
|
|
782
833
|
return answers.isOpenSource;
|
|
783
834
|
},
|
|
784
835
|
},
|
|
836
|
+
{
|
|
837
|
+
type: 'confirm',
|
|
838
|
+
name: 'isRemoveYarn',
|
|
839
|
+
message: '是否移除 yarn ?',
|
|
840
|
+
default: false,
|
|
841
|
+
when(answers) {
|
|
842
|
+
return answers.isOpenSource;
|
|
843
|
+
},
|
|
844
|
+
},
|
|
785
845
|
{
|
|
786
846
|
type: 'confirm',
|
|
787
847
|
name: 'isEnableAfdian',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cmyr-template-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
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": "
|
|
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"
|
|
@@ -49,9 +49,10 @@
|
|
|
49
49
|
"@typescript-eslint/parser": "^4.9.0",
|
|
50
50
|
"commitizen": "^4.2.2",
|
|
51
51
|
"conventional-changelog-cli": "^2.1.1",
|
|
52
|
-
"conventional-changelog-cmyr-config": "^
|
|
52
|
+
"conventional-changelog-cmyr-config": "^2.0.0",
|
|
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": {
|
package/templates/.releaserc.js
CHANGED
|
@@ -7,10 +7,12 @@ module.exports = {
|
|
|
7
7
|
"config": "conventional-changelog-cmyr-config"
|
|
8
8
|
}
|
|
9
9
|
],
|
|
10
|
-
[
|
|
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,10 +68,14 @@
|
|
|
68
68
|
|
|
69
69
|
- 若为 BUG 修复,则选择 `fix`
|
|
70
70
|
- 若为新增功能,则选择 `feat`
|
|
71
|
-
-
|
|
72
|
-
|
|
71
|
+
- 若为性能优化,则选择 `perf`
|
|
72
|
+
- 若为移除某些功能,则选择 `BREAKING CHANGE`
|
|
73
|
+
- `BREAKING CHANGE` 和其他破坏性更新,若不是为了修复 BUG,原则上将拒绝该 PR
|
|
73
74
|
|
|
74
75
|
|
|
75
76
|
5. 推送到分支 ( `git push origin feat/your_feature`)
|
|
76
77
|
|
|
77
78
|
6. [打开一个新的 Pull Request](<%= repositoryUrl %>/compare?expand=1)
|
|
79
|
+
|
|
80
|
+
***
|
|
81
|
+
_This CONTRIBUTING was generated with ❤️ by [cmyr-template-cli](https://github.com/CaoMeiYouRen/cmyr-template-cli)_
|