cmyr-template-cli 1.19.7 → 1.20.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/README.md +21 -3
- package/dist/plopfile.js +55 -28
- package/package.json +3 -3
- package/templates/README.md +17 -10
package/README.md
CHANGED
|
@@ -61,13 +61,31 @@ ct create
|
|
|
61
61
|
```json
|
|
62
62
|
{
|
|
63
63
|
"GITHUB_TOKEN": "",
|
|
64
|
-
"GITEE_TOKEN": ""
|
|
64
|
+
"GITEE_TOKEN": "",
|
|
65
|
+
"GITHUB_USERNAME": "",
|
|
66
|
+
"GITEE_USERNAME": "",
|
|
67
|
+
"AFDIAN_USERNAME": "",
|
|
68
|
+
"PATREON_USERNAME": "",
|
|
69
|
+
"WEIBO_USERNAME": "",
|
|
70
|
+
"TWITTER_USERNAME": ""
|
|
65
71
|
}
|
|
66
72
|
```
|
|
67
73
|
|
|
68
|
-
GITHUB_TOKEN
|
|
74
|
+
GITHUB_TOKEN:可空,默认值为空。请参考: [创建用于命令行的个人访问令牌](https://help.github.com/cn/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line)
|
|
69
75
|
|
|
70
|
-
GITEE_TOKEN
|
|
76
|
+
GITEE_TOKEN:可空,默认值为空。请参考:https://gitee.com/profile/personal_access_tokens
|
|
77
|
+
|
|
78
|
+
GITHUB_USERNAME:GitHub 用户名,可空,默认会使用 `git config user.name` 的用户名
|
|
79
|
+
|
|
80
|
+
GITEE_USERNAME:码云用户名,可空,默认值为空
|
|
81
|
+
|
|
82
|
+
AFDIAN_USERNAME:爱发电用户名,可空,默认值为空
|
|
83
|
+
|
|
84
|
+
PATREON_USERNAME:Patreon 用户名,可空,默认值为空
|
|
85
|
+
|
|
86
|
+
WEIBO_USERNAME:微博用户名,可空,默认值为空
|
|
87
|
+
|
|
88
|
+
TWITTER_USERNAME:Twitter 用户名,可空,默认值为空
|
|
71
89
|
|
|
72
90
|
**如果不使用自动初始化远程仓库功能,可以跳过该配置**
|
|
73
91
|
|
package/dist/plopfile.js
CHANGED
|
@@ -12,6 +12,7 @@ var ejs = require('ejs');
|
|
|
12
12
|
var lodash = require('lodash');
|
|
13
13
|
var core = require('@lint-md/core');
|
|
14
14
|
var JSON5 = require('json5');
|
|
15
|
+
var os = require('os');
|
|
15
16
|
|
|
16
17
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
17
18
|
|
|
@@ -41,6 +42,7 @@ var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
|
|
|
41
42
|
var colors__default = /*#__PURE__*/_interopDefaultLegacy(colors);
|
|
42
43
|
var ejs__default = /*#__PURE__*/_interopDefaultLegacy(ejs);
|
|
43
44
|
var JSON5__default = /*#__PURE__*/_interopDefaultLegacy(JSON5);
|
|
45
|
+
var os__default = /*#__PURE__*/_interopDefaultLegacy(os);
|
|
44
46
|
|
|
45
47
|
process.env;
|
|
46
48
|
const PACKAGE_MANAGER = 'pnpm';
|
|
@@ -81,6 +83,7 @@ const COMMON_DEPENDENCIES = {
|
|
|
81
83
|
dependencies: {
|
|
82
84
|
axios: '^1.0.0',
|
|
83
85
|
'cmyr-error-collection': '^1.5.0',
|
|
86
|
+
'cmyr-sign': '^1.1.0',
|
|
84
87
|
dayjs: '^1.9.6',
|
|
85
88
|
'fs-extra': '^10.0.0',
|
|
86
89
|
'isomorphic-unfetch': '^3.1.0',
|
|
@@ -92,7 +95,6 @@ const COMMON_DEPENDENCIES = {
|
|
|
92
95
|
const VUE_DEPENDENCIES = {
|
|
93
96
|
devDependencies: {},
|
|
94
97
|
dependencies: {
|
|
95
|
-
'vite-plugin-fast-cdn-import': '^1.1.0',
|
|
96
98
|
'element-ui': '^2.15.7',
|
|
97
99
|
vuetify: '^2.6.3',
|
|
98
100
|
},
|
|
@@ -133,26 +135,29 @@ async function createGithubRepo(authToken, data) {
|
|
|
133
135
|
return null;
|
|
134
136
|
}
|
|
135
137
|
}
|
|
136
|
-
async function
|
|
137
|
-
const paths = [process.cwd(),
|
|
138
|
-
|
|
139
|
-
throw new Error(`无效的 token 类型:${type}`);
|
|
140
|
-
}
|
|
141
|
-
const CONFIG_KEY = type;
|
|
142
|
-
for await (const p of paths) {
|
|
138
|
+
async function loadTemplateCliConfig() {
|
|
139
|
+
const paths = [process.cwd(), os__default["default"].homedir()].map((e) => path__default["default"].join(e, '.ctrc'));
|
|
140
|
+
const [local, home] = (await Promise.all(paths.map(async (p) => {
|
|
143
141
|
try {
|
|
144
142
|
if (await fs__default["default"].pathExists(p)) {
|
|
145
|
-
|
|
146
|
-
if (config === null || config === void 0 ? void 0 : config[CONFIG_KEY]) {
|
|
147
|
-
return config[CONFIG_KEY];
|
|
148
|
-
}
|
|
143
|
+
return fs__default["default"].readJSON(p);
|
|
149
144
|
}
|
|
145
|
+
return null;
|
|
150
146
|
}
|
|
151
147
|
catch (error) {
|
|
152
148
|
console.error(error);
|
|
149
|
+
return null;
|
|
153
150
|
}
|
|
154
|
-
}
|
|
155
|
-
return
|
|
151
|
+
}))).filter(Boolean);
|
|
152
|
+
return lodash.mergeWith(home, local, (objValue, srcValue) => {
|
|
153
|
+
if (typeof objValue === 'string' && srcValue === '') {
|
|
154
|
+
return objValue;
|
|
155
|
+
}
|
|
156
|
+
if (typeof srcValue !== 'undefined' && srcValue !== null) {
|
|
157
|
+
return srcValue;
|
|
158
|
+
}
|
|
159
|
+
return objValue;
|
|
160
|
+
});
|
|
156
161
|
}
|
|
157
162
|
async function downloadGitRepo(repository, destination, options = {}) {
|
|
158
163
|
const fastRepo = await getFastGitRepo(repository);
|
|
@@ -211,7 +216,7 @@ async function initProject(answers) {
|
|
|
211
216
|
}
|
|
212
217
|
async function init(projectPath, answers) {
|
|
213
218
|
var _a;
|
|
214
|
-
const { isOpenSource,
|
|
219
|
+
const { isOpenSource, isInitReadme, isInitContributing, isInitHusky, isInitSemanticRelease, isInitDocker } = answers;
|
|
215
220
|
try {
|
|
216
221
|
await asyncExec('git --version', {
|
|
217
222
|
cwd: projectPath,
|
|
@@ -241,9 +246,7 @@ async function init(projectPath, answers) {
|
|
|
241
246
|
}
|
|
242
247
|
await initGithubWorkflows(projectPath, answers);
|
|
243
248
|
}
|
|
244
|
-
|
|
245
|
-
await initRemoteGitRepo(projectPath, answers);
|
|
246
|
-
}
|
|
249
|
+
await initRemoteGitRepo(projectPath, answers);
|
|
247
250
|
if (isInitSemanticRelease) {
|
|
248
251
|
await initSemanticRelease(projectPath);
|
|
249
252
|
}
|
|
@@ -282,16 +285,25 @@ async function init(projectPath, answers) {
|
|
|
282
285
|
}
|
|
283
286
|
async function getGitUserName() {
|
|
284
287
|
const username = (await asyncExec('git config user.name')) || '';
|
|
285
|
-
return username.trim();
|
|
288
|
+
return username === null || username === void 0 ? void 0 : username.trim();
|
|
286
289
|
}
|
|
287
290
|
async function initRemoteGitRepo(projectPath, answers) {
|
|
288
291
|
var _a, _b;
|
|
289
292
|
const loading = ora__default["default"]('正在初始化远程 Git 仓库……').start();
|
|
290
293
|
try {
|
|
291
|
-
const { name, description, gitRemoteUrl, isOpenSource } = answers;
|
|
294
|
+
const { name, description, gitRemoteUrl, isOpenSource, isInitRemoteRepo } = answers;
|
|
295
|
+
if (!gitRemoteUrl) {
|
|
296
|
+
loading.fail('未找到远程 Git 仓库地址,请自行初始化!');
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
292
299
|
await asyncExec(`git remote add origin ${gitRemoteUrl}`, {
|
|
293
300
|
cwd: projectPath,
|
|
294
301
|
});
|
|
302
|
+
if (!isInitRemoteRepo) {
|
|
303
|
+
loading.stop();
|
|
304
|
+
console.info(colors__default["default"].green(`请自行在远程 Git 仓库初始化 ${gitRemoteUrl}`));
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
295
307
|
let type = '';
|
|
296
308
|
if (/github\.com/.test(gitRemoteUrl)) {
|
|
297
309
|
type = 'github';
|
|
@@ -299,9 +311,10 @@ async function initRemoteGitRepo(projectPath, answers) {
|
|
|
299
311
|
else if (/gitee\.com/.test(gitRemoteUrl)) {
|
|
300
312
|
type = 'gitee';
|
|
301
313
|
}
|
|
314
|
+
const config = await loadTemplateCliConfig();
|
|
302
315
|
switch (type) {
|
|
303
316
|
case 'github': {
|
|
304
|
-
const authToken =
|
|
317
|
+
const authToken = config === null || config === void 0 ? void 0 : config.GITHUB_TOKEN;
|
|
305
318
|
if (!authToken) {
|
|
306
319
|
console.error(colors__default["default"].red(`未找到 ${type} token !跳过初始化!`));
|
|
307
320
|
break;
|
|
@@ -321,7 +334,7 @@ async function initRemoteGitRepo(projectPath, answers) {
|
|
|
321
334
|
return;
|
|
322
335
|
}
|
|
323
336
|
case 'gitee': {
|
|
324
|
-
const access_token =
|
|
337
|
+
const access_token = config === null || config === void 0 ? void 0 : config.GITEE_TOKEN;
|
|
325
338
|
if (!access_token) {
|
|
326
339
|
console.error(colors__default["default"].red(`未找到 ${type} token !跳过初始化!`));
|
|
327
340
|
break;
|
|
@@ -342,11 +355,10 @@ async function initRemoteGitRepo(projectPath, answers) {
|
|
|
342
355
|
return;
|
|
343
356
|
}
|
|
344
357
|
default: {
|
|
345
|
-
|
|
358
|
+
loading.stop();
|
|
359
|
+
console.info(colors__default["default"].green(`请在远程 Git 仓库初始化 ${gitRemoteUrl}`));
|
|
346
360
|
}
|
|
347
361
|
}
|
|
348
|
-
loading.stop();
|
|
349
|
-
console.info(colors__default["default"].green(`请在远程 Git 仓库初始化 ${gitRemoteUrl}`));
|
|
350
362
|
}
|
|
351
363
|
catch (error) {
|
|
352
364
|
loading.fail('远程 Git 仓库初始化失败!');
|
|
@@ -520,6 +532,7 @@ async function getProjectInfo(projectPath, answers) {
|
|
|
520
532
|
try {
|
|
521
533
|
const { name, author, description, isOpenSource, isPublishToNpm } = answers;
|
|
522
534
|
const packageManager = 'npm';
|
|
535
|
+
const config = await loadTemplateCliConfig();
|
|
523
536
|
const pkg = await getProjectJson(projectPath);
|
|
524
537
|
const engines = (pkg === null || pkg === void 0 ? void 0 : pkg.engines) || {};
|
|
525
538
|
const license = pkg === null || pkg === void 0 ? void 0 : pkg.license;
|
|
@@ -537,11 +550,16 @@ async function getProjectInfo(projectPath, answers) {
|
|
|
537
550
|
const documentationUrl = `${repositoryUrl}#readme`;
|
|
538
551
|
const demoUrl = `${repositoryUrl}#readme`;
|
|
539
552
|
const homepage = documentationUrl;
|
|
540
|
-
const githubUsername = author;
|
|
553
|
+
const githubUsername = (config === null || config === void 0 ? void 0 : config.GITHUB_USERNAME) || author;
|
|
541
554
|
const authorWebsite = await getAuthorWebsiteFromGithubAPI(githubUsername);
|
|
542
555
|
const licenseUrl = `${repositoryUrl}/blob/master/LICENSE`;
|
|
543
556
|
const discussionsUrl = `${repositoryUrl}/discussions`;
|
|
544
557
|
const pullRequestsUrl = `${repositoryUrl}/pulls`;
|
|
558
|
+
const giteeUsername = config === null || config === void 0 ? void 0 : config.GITEE_USERNAME;
|
|
559
|
+
const weiboUsername = config === null || config === void 0 ? void 0 : config.WEIBO_USERNAME;
|
|
560
|
+
const twitterUsername = config === null || config === void 0 ? void 0 : config.TWITTER_USERNAME;
|
|
561
|
+
const afdianUsername = config === null || config === void 0 ? void 0 : config.AFDIAN_USERNAME;
|
|
562
|
+
const patreonUsername = config === null || config === void 0 ? void 0 : config.PATREON_USERNAME;
|
|
545
563
|
const projectInfos = {
|
|
546
564
|
...answers,
|
|
547
565
|
currentYear: new Date().getFullYear(),
|
|
@@ -588,6 +606,11 @@ async function getProjectInfo(projectPath, answers) {
|
|
|
588
606
|
})),
|
|
589
607
|
discussionsUrl,
|
|
590
608
|
pullRequestsUrl,
|
|
609
|
+
giteeUsername,
|
|
610
|
+
afdianUsername,
|
|
611
|
+
patreonUsername,
|
|
612
|
+
weiboUsername,
|
|
613
|
+
twitterUsername,
|
|
591
614
|
};
|
|
592
615
|
loading.succeed('项目信息 初始化成功!');
|
|
593
616
|
return projectInfos;
|
|
@@ -1092,6 +1115,7 @@ module.exports = function (plop) {
|
|
|
1092
1115
|
plop.setGenerator('create', {
|
|
1093
1116
|
description: '草梅项目创建器',
|
|
1094
1117
|
async prompts(inquirer) {
|
|
1118
|
+
const config = await loadTemplateCliConfig();
|
|
1095
1119
|
const questions = [
|
|
1096
1120
|
{
|
|
1097
1121
|
type: 'input',
|
|
@@ -1205,10 +1229,13 @@ module.exports = function (plop) {
|
|
|
1205
1229
|
},
|
|
1206
1230
|
default(answers) {
|
|
1207
1231
|
const { isOpenSource, name, author } = answers;
|
|
1232
|
+
const { GITHUB_USERNAME, GITEE_USERNAME } = config;
|
|
1233
|
+
const githubUsername = GITHUB_USERNAME || author;
|
|
1234
|
+
const giteeUsername = GITEE_USERNAME || author;
|
|
1208
1235
|
if (isOpenSource) {
|
|
1209
|
-
return `git@github.com:${
|
|
1236
|
+
return `git@github.com:${githubUsername}/${name}.git`;
|
|
1210
1237
|
}
|
|
1211
|
-
return `git@gitee.com
|
|
1238
|
+
return `git@gitee.com:${giteeUsername}/${name}.git`;
|
|
1212
1239
|
},
|
|
1213
1240
|
filter: (e) => e.trim(),
|
|
1214
1241
|
when(answers) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cmyr-template-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.20.0",
|
|
4
4
|
"description": "草梅友仁自制的项目模板创建器",
|
|
5
5
|
"author": "CaoMeiYouRen",
|
|
6
6
|
"license": "MIT",
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
"@types/lodash": "^4.14.165",
|
|
47
47
|
"@types/node": "^20.0.0",
|
|
48
48
|
"@types/promise.any": "^2.0.0",
|
|
49
|
-
"@typescript-eslint/eslint-plugin": "6.
|
|
50
|
-
"@typescript-eslint/parser": "6.
|
|
49
|
+
"@typescript-eslint/eslint-plugin": "6.7.0",
|
|
50
|
+
"@typescript-eslint/parser": "6.7.0",
|
|
51
51
|
"commitizen": "^4.2.2",
|
|
52
52
|
"conventional-changelog-cli": "^4.0.0",
|
|
53
53
|
"conventional-changelog-cmyr-config": "^2.1.0",
|
package/templates/README.md
CHANGED
|
@@ -113,21 +113,27 @@
|
|
|
113
113
|
```
|
|
114
114
|
<% } -%>
|
|
115
115
|
|
|
116
|
-
<% if (authorName || authorGithubUsername) { -%>
|
|
117
116
|
|
|
118
117
|
## 👤 作者
|
|
119
118
|
|
|
120
119
|
<% if (authorName) { %>
|
|
121
|
-
|
|
122
|
-
<% }
|
|
123
|
-
<% if (authorWebsite) { -%>
|
|
120
|
+
**<%= authorName %>**
|
|
121
|
+
<% } -%>
|
|
124
122
|
|
|
123
|
+
<% if (authorWebsite) { -%>
|
|
125
124
|
* Website: [<%= authorWebsite %>](<%= authorWebsite %>)
|
|
125
|
+
|
|
126
126
|
<% } -%>
|
|
127
127
|
<% if (authorGithubUsername) { -%>
|
|
128
128
|
* GitHub: [@<%= authorGithubUsername %>](https://github.com/<%= authorGithubUsername %>)
|
|
129
129
|
<% } -%>
|
|
130
|
-
<%
|
|
130
|
+
<% if (twitterUsername) { -%>
|
|
131
|
+
* Twitter: [@<%= twitterUsername %>](https://twitter.com/<%= twitterUsername %>)
|
|
132
|
+
<% } -%>
|
|
133
|
+
<% if (weiboUsername) { -%>
|
|
134
|
+
* Weibo: [@<%= weiboUsername %>](https://weibo.com/<%= weiboUsername %>)
|
|
135
|
+
<% } -%>
|
|
136
|
+
|
|
131
137
|
<% if (issuesUrl) { -%>
|
|
132
138
|
|
|
133
139
|
## 🤝 贡献
|
|
@@ -139,15 +145,16 @@
|
|
|
139
145
|
|
|
140
146
|
如果觉得这个项目有用的话请给一颗⭐️,非常感谢
|
|
141
147
|
<% if (isEnableSupport) { -%>
|
|
142
|
-
|
|
143
|
-
<a href="https://afdian.net/@<%=
|
|
148
|
+
<% if (afdianUsername) { -%>
|
|
149
|
+
<a href="https://afdian.net/@<%= afdianUsername %>">
|
|
144
150
|
<img src="https://cdn.jsdelivr.net/gh/CaoMeiYouRen/image-hosting-01@master/images/202306192324870.png" width="312px" height="78px" alt="在爱发电支持我">
|
|
145
151
|
</a>
|
|
146
|
-
|
|
147
|
-
|
|
152
|
+
<% } -%>
|
|
153
|
+
<% if (patreonUsername) { -%>
|
|
154
|
+
<a href="https://patreon.com/<%= patreonUsername %>">
|
|
148
155
|
<img src="https://cdn.jsdelivr.net/gh/CaoMeiYouRen/image-hosting-01@master/images/202306142054108.svg" width="312px" height="78px" alt="become a patreon"/>
|
|
149
156
|
</a>
|
|
150
|
-
|
|
157
|
+
<% } -%>
|
|
151
158
|
<% } -%>
|
|
152
159
|
<% if (isEnableStarHistory) { -%>
|
|
153
160
|
|