cmyr-template-cli 1.7.2 → 1.7.3
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 +57 -17
- package/package.json +1 -1
- package/templates/.github/workflows/release.yml +1 -1
- package/templates/README.md +16 -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.2" , '-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,11 @@ 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,
|
|
165
|
+
await initGithubWorkflows(projectPath, answers);
|
|
166
166
|
}
|
|
167
167
|
await initConfig(projectPath);
|
|
168
|
+
await sortProjectJson(projectPath);
|
|
168
169
|
await asyncExec('git add .', {
|
|
169
170
|
cwd: projectPath,
|
|
170
171
|
});
|
|
@@ -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) {
|
|
@@ -253,7 +259,7 @@ 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;
|
|
@@ -269,6 +275,7 @@ async function getProjectInfo(projectPath, answers) {
|
|
|
269
275
|
const buildCommand = ((_c = pkg === null || pkg === void 0 ? void 0 : pkg.scripts) === null || _c === void 0 ? void 0 : _c.build) && `${packageManager} run build`;
|
|
270
276
|
const testCommand = ((_d = pkg === null || pkg === void 0 ? void 0 : pkg.scripts) === null || _d === void 0 ? void 0 : _d.test) && `${packageManager} run test`;
|
|
271
277
|
const lintCommand = ((_e = pkg === null || pkg === void 0 ? void 0 : pkg.scripts) === null || _e === void 0 ? void 0 : _e.lint) && `${packageManager} run lint`;
|
|
278
|
+
const commitCommand = ((_f = pkg === null || pkg === void 0 ? void 0 : pkg.scripts) === null || _f === void 0 ? void 0 : _f.commit) && `${packageManager} run commit`;
|
|
272
279
|
const repositoryUrl = `https://github.com/${author}/${name}`;
|
|
273
280
|
const issuesUrl = `${repositoryUrl}/issues`;
|
|
274
281
|
const contributingUrl = `${repositoryUrl}/blob/master/CONTRIBUTING.md`;
|
|
@@ -308,6 +315,7 @@ async function getProjectInfo(projectPath, answers) {
|
|
|
308
315
|
buildCommand,
|
|
309
316
|
testCommand,
|
|
310
317
|
lintCommand,
|
|
318
|
+
commitCommand,
|
|
311
319
|
isJSProject: true,
|
|
312
320
|
packageManager,
|
|
313
321
|
isProjectOnNpm: isPublishToNpm,
|
|
@@ -413,10 +421,10 @@ async function initConfig(projectPath) {
|
|
|
413
421
|
console.error(error);
|
|
414
422
|
}
|
|
415
423
|
}
|
|
416
|
-
async function initGithubWorkflows(projectPath,
|
|
424
|
+
async function initGithubWorkflows(projectPath, answers) {
|
|
417
425
|
const loading = ora__default["default"]('正在初始化 Github Workflows ……').start();
|
|
418
426
|
try {
|
|
419
|
-
const { isInitSemanticRelease } =
|
|
427
|
+
const { isInitSemanticRelease } = answers;
|
|
420
428
|
const files = ['.github/workflows/test.yml'];
|
|
421
429
|
const dir = path__default["default"].join(projectPath, '.github/workflows');
|
|
422
430
|
if (!await fs__default["default"].pathExists(dir)) {
|
|
@@ -425,10 +433,6 @@ async function initGithubWorkflows(projectPath, projectInfos) {
|
|
|
425
433
|
const releaseYml = '.github/workflows/release.yml';
|
|
426
434
|
if (isInitSemanticRelease) {
|
|
427
435
|
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
436
|
}
|
|
433
437
|
else {
|
|
434
438
|
const oldReleaseYml = path__default["default"].join(projectPath, releaseYml);
|
|
@@ -436,6 +440,10 @@ async function initGithubWorkflows(projectPath, projectInfos) {
|
|
|
436
440
|
await fs__default["default"].remove(oldReleaseYml);
|
|
437
441
|
}
|
|
438
442
|
}
|
|
443
|
+
const oldReleaseYml = path__default["default"].join(projectPath, '.github/release.yml');
|
|
444
|
+
if (await fs__default["default"].pathExists(oldReleaseYml)) {
|
|
445
|
+
await fs__default["default"].remove(oldReleaseYml);
|
|
446
|
+
}
|
|
439
447
|
files.forEach(async (file) => {
|
|
440
448
|
const templatePath = path__default["default"].join(__dirname, '../templates/', file);
|
|
441
449
|
const newPath = path__default["default"].join(projectPath, file);
|
|
@@ -451,7 +459,7 @@ async function initGithubWorkflows(projectPath, projectInfos) {
|
|
|
451
459
|
console.error(error);
|
|
452
460
|
}
|
|
453
461
|
}
|
|
454
|
-
async function initSemanticRelease(projectPath
|
|
462
|
+
async function initSemanticRelease(projectPath) {
|
|
455
463
|
const loading = ora__default["default"]('正在初始化 semantic-release ……').start();
|
|
456
464
|
try {
|
|
457
465
|
const files = ['.releaserc.js'];
|
|
@@ -469,7 +477,6 @@ async function initSemanticRelease(projectPath, projectInfos) {
|
|
|
469
477
|
'@semantic-release/changelog': '^6.0.1',
|
|
470
478
|
'@semantic-release/git': '^10.0.1',
|
|
471
479
|
'conventional-changelog-cli': '^2.1.1',
|
|
472
|
-
'conventional-changelog-cmyr-config': `^${await getNpmPackageVersion('conventional-changelog-cmyr-config')}`,
|
|
473
480
|
'semantic-release': '^18.0.1',
|
|
474
481
|
};
|
|
475
482
|
const pkgData = {
|
|
@@ -480,6 +487,7 @@ async function initSemanticRelease(projectPath, projectInfos) {
|
|
|
480
487
|
devDependencies: {
|
|
481
488
|
...devDependencies,
|
|
482
489
|
...pkg === null || pkg === void 0 ? void 0 : pkg.devDependencies,
|
|
490
|
+
'conventional-changelog-cmyr-config': `^${await getNpmPackageVersion('conventional-changelog-cmyr-config')}`,
|
|
483
491
|
},
|
|
484
492
|
};
|
|
485
493
|
const newPkg = Object.assign({}, pkg, pkgData);
|
|
@@ -491,7 +499,7 @@ async function initSemanticRelease(projectPath, projectInfos) {
|
|
|
491
499
|
console.error(error);
|
|
492
500
|
}
|
|
493
501
|
}
|
|
494
|
-
async function initHusky(projectPath
|
|
502
|
+
async function initHusky(projectPath) {
|
|
495
503
|
var _a, _b;
|
|
496
504
|
const loading = ora__default["default"]('正在初始化 husky ……').start();
|
|
497
505
|
try {
|
|
@@ -558,6 +566,21 @@ async function initHusky(projectPath, projectInfos) {
|
|
|
558
566
|
console.error(error);
|
|
559
567
|
}
|
|
560
568
|
}
|
|
569
|
+
async function sortProjectJson(projectPath) {
|
|
570
|
+
try {
|
|
571
|
+
const pkgPath = path__default["default"].join(projectPath, 'package.json');
|
|
572
|
+
const pkg = await fs__default["default"].readJSON(pkgPath);
|
|
573
|
+
const pkgData = {
|
|
574
|
+
dependencies: sortKey((pkg === null || pkg === void 0 ? void 0 : pkg.dependencies) || {}),
|
|
575
|
+
devDependencies: sortKey((pkg === null || pkg === void 0 ? void 0 : pkg.devDependencies) || {}),
|
|
576
|
+
};
|
|
577
|
+
const newPkg = Object.assign({}, pkg, pkgData);
|
|
578
|
+
await fs__default["default"].writeFile(pkgPath, JSON.stringify(newPkg, null, 2));
|
|
579
|
+
}
|
|
580
|
+
catch (error) {
|
|
581
|
+
console.error(error);
|
|
582
|
+
}
|
|
583
|
+
}
|
|
561
584
|
async function getAuthorWebsiteFromGithubAPI(githubUsername) {
|
|
562
585
|
try {
|
|
563
586
|
const userData = (await axios__default["default"].get(`${GITHUB_API_URL}/users/${githubUsername}`)).data;
|
|
@@ -596,6 +619,14 @@ function lintMd(markdown) {
|
|
|
596
619
|
const fixed = core.fix(markdown, rules);
|
|
597
620
|
return fixed;
|
|
598
621
|
}
|
|
622
|
+
function sortKey(obj) {
|
|
623
|
+
const keys = Object.keys(obj).sort((a, b) => a.localeCompare(b));
|
|
624
|
+
const obj2 = {};
|
|
625
|
+
keys.forEach((e) => {
|
|
626
|
+
obj2[e] = obj[e];
|
|
627
|
+
});
|
|
628
|
+
return obj2;
|
|
629
|
+
}
|
|
599
630
|
|
|
600
631
|
module.exports = function (plop) {
|
|
601
632
|
plop.setActionType('initProject', initProject);
|
|
@@ -751,6 +782,15 @@ module.exports = function (plop) {
|
|
|
751
782
|
return answers.isOpenSource;
|
|
752
783
|
},
|
|
753
784
|
},
|
|
785
|
+
{
|
|
786
|
+
type: 'confirm',
|
|
787
|
+
name: 'isEnableAfdian',
|
|
788
|
+
message: '是否启用爱发电 ?',
|
|
789
|
+
default: false,
|
|
790
|
+
when(answers) {
|
|
791
|
+
return answers.isOpenSource;
|
|
792
|
+
},
|
|
793
|
+
},
|
|
754
794
|
];
|
|
755
795
|
return inquirer.prompt(questions);
|
|
756
796
|
},
|
package/package.json
CHANGED
package/templates/README.md
CHANGED
|
@@ -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
|