cmyr-template-cli 1.4.1 → 1.6.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 +6 -1
- package/dist/plopfile.js +322 -33
- package/package.json +9 -5
- package/templates/CONTRIBUTING.md +78 -0
- package/templates/README.md +149 -0
package/dist/index.js
CHANGED
|
@@ -13,8 +13,12 @@ var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
|
13
13
|
|
|
14
14
|
const program = new commander.Command('ct')
|
|
15
15
|
.description('草梅项目创建器');
|
|
16
|
-
program.version(
|
|
16
|
+
program.version("1.5.2" , '-v, --version');
|
|
17
17
|
const args = process.argv.slice(2);
|
|
18
|
+
if (args.length === 0) {
|
|
19
|
+
args.push('create');
|
|
20
|
+
process.argv.push('create');
|
|
21
|
+
}
|
|
18
22
|
const argv = minimist__default["default"](args);
|
|
19
23
|
program.option('-d, --debug', 'debug');
|
|
20
24
|
const create = new commander.Command('create')
|
|
@@ -31,6 +35,7 @@ program.addCommand(create);
|
|
|
31
35
|
program.parse(process.argv);
|
|
32
36
|
const opts = program.opts();
|
|
33
37
|
if (opts.debug) {
|
|
38
|
+
console.log(args);
|
|
34
39
|
console.log(argv);
|
|
35
40
|
console.log(opts);
|
|
36
41
|
}
|
package/dist/plopfile.js
CHANGED
|
@@ -7,39 +7,67 @@ var ora = require('ora');
|
|
|
7
7
|
var download = require('download-git-repo');
|
|
8
8
|
var axios = require('axios');
|
|
9
9
|
var child_process = require('child_process');
|
|
10
|
-
var
|
|
10
|
+
var colors = require('colors');
|
|
11
|
+
var ejs = require('ejs');
|
|
12
|
+
var lodash = require('lodash');
|
|
13
|
+
var core = require('@lint-md/core');
|
|
11
14
|
|
|
12
15
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
13
16
|
|
|
17
|
+
function _interopNamespace(e) {
|
|
18
|
+
if (e && e.__esModule) return e;
|
|
19
|
+
var n = Object.create(null);
|
|
20
|
+
if (e) {
|
|
21
|
+
Object.keys(e).forEach(function (k) {
|
|
22
|
+
if (k !== 'default') {
|
|
23
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
24
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () { return e[k]; }
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
n["default"] = e;
|
|
32
|
+
return Object.freeze(n);
|
|
33
|
+
}
|
|
34
|
+
|
|
14
35
|
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
15
36
|
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
16
37
|
var ora__default = /*#__PURE__*/_interopDefaultLegacy(ora);
|
|
17
38
|
var download__default = /*#__PURE__*/_interopDefaultLegacy(download);
|
|
18
39
|
var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
|
|
19
|
-
var
|
|
40
|
+
var colors__default = /*#__PURE__*/_interopDefaultLegacy(colors);
|
|
41
|
+
var ejs__default = /*#__PURE__*/_interopDefaultLegacy(ejs);
|
|
20
42
|
|
|
21
43
|
process.env;
|
|
22
44
|
const PACKAGE_MANAGER = 'pnpm';
|
|
23
45
|
|
|
46
|
+
axios__default["default"].defaults.timeout = 10 * 1000;
|
|
24
47
|
if (!Promise.any) {
|
|
25
|
-
Promise.any
|
|
48
|
+
Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('promise.any')); }).then((any) => {
|
|
49
|
+
Promise.any = any.default;
|
|
50
|
+
});
|
|
26
51
|
}
|
|
52
|
+
const GITHUB_API_URL = 'https://api.github.com';
|
|
53
|
+
const NODEJS_URL = 'https://nodejs.org/zh-cn/download/';
|
|
27
54
|
const REMOTES = [
|
|
28
55
|
'https://github.com',
|
|
29
56
|
'https://hub.fastgit.org',
|
|
30
|
-
'https://gitclone.com',
|
|
31
57
|
'https://github.com.cnpmjs.org',
|
|
58
|
+
'https://download.fastgit.org',
|
|
32
59
|
];
|
|
33
60
|
async function downloadGitRepo(repository, destination, options = {}) {
|
|
34
61
|
const fastRepo = await getFastGitRepo(repository);
|
|
35
|
-
const loading = ora__default["default"](
|
|
62
|
+
const loading = ora__default["default"](`正在下载模板 - ${repository}`);
|
|
36
63
|
loading.start();
|
|
37
|
-
return new Promise((resolve
|
|
64
|
+
return new Promise((resolve) => {
|
|
38
65
|
download__default["default"](fastRepo, destination, options, (err) => {
|
|
39
|
-
loading.stop();
|
|
40
66
|
if (err) {
|
|
41
|
-
|
|
67
|
+
loading.fail('下载模板失败!');
|
|
68
|
+
process.exit(1);
|
|
42
69
|
}
|
|
70
|
+
loading.succeed(`成功下载模板 - ${repository}`);
|
|
43
71
|
resolve(true);
|
|
44
72
|
});
|
|
45
73
|
});
|
|
@@ -56,15 +84,14 @@ async function getFastGitRepo(repository) {
|
|
|
56
84
|
timeout: 15 * 1000,
|
|
57
85
|
});
|
|
58
86
|
}));
|
|
87
|
+
loading.succeed(`成功选择了镜像源 - ${fast.config.url}`);
|
|
59
88
|
return `direct:${fast.config.url}`;
|
|
60
89
|
}
|
|
61
90
|
catch (error) {
|
|
62
91
|
console.error(error);
|
|
92
|
+
loading.fail('选择镜像源失败!');
|
|
63
93
|
process.exit(1);
|
|
64
94
|
}
|
|
65
|
-
finally {
|
|
66
|
-
loading.stop();
|
|
67
|
-
}
|
|
68
95
|
}
|
|
69
96
|
async function asyncExec(cmd, options) {
|
|
70
97
|
return new Promise((resolve, reject) => {
|
|
@@ -80,8 +107,7 @@ async function asyncExec(cmd, options) {
|
|
|
80
107
|
});
|
|
81
108
|
}
|
|
82
109
|
async function init(projectPath, answers) {
|
|
83
|
-
const
|
|
84
|
-
const { name, author, description, isOpenSource, isRemoveDependabot } = answers;
|
|
110
|
+
const { isOpenSource, isRemoveDependabot, gitRemoteUrl, isInitReadme, isInitContributing } = answers;
|
|
85
111
|
try {
|
|
86
112
|
await asyncExec('git --version', {
|
|
87
113
|
cwd: projectPath,
|
|
@@ -92,6 +118,12 @@ async function init(projectPath, answers) {
|
|
|
92
118
|
await asyncExec('git init', {
|
|
93
119
|
cwd: projectPath,
|
|
94
120
|
});
|
|
121
|
+
if (gitRemoteUrl) {
|
|
122
|
+
await asyncExec(`git remote add origin ${gitRemoteUrl}`, {
|
|
123
|
+
cwd: projectPath,
|
|
124
|
+
});
|
|
125
|
+
console.info(colors__default["default"].green(`请在远程 Git 仓库初始化 ${gitRemoteUrl}`));
|
|
126
|
+
}
|
|
95
127
|
const dependabotPath = path__default["default"].join(projectPath, '.github/dependabot.yml');
|
|
96
128
|
const mergifyPath = path__default["default"].join(projectPath, '.github/mergify.yml');
|
|
97
129
|
if (!isOpenSource || isRemoveDependabot) {
|
|
@@ -102,26 +134,34 @@ async function init(projectPath, answers) {
|
|
|
102
134
|
await fs__default["default"].remove(mergifyPath);
|
|
103
135
|
}
|
|
104
136
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
137
|
+
await initProjectJson(projectPath, answers);
|
|
138
|
+
if (isOpenSource) {
|
|
139
|
+
const info = await getProjectInfo(projectPath, answers);
|
|
140
|
+
if (info) {
|
|
141
|
+
if (isInitReadme) {
|
|
142
|
+
await initReadme(projectPath, info);
|
|
143
|
+
}
|
|
144
|
+
if (isInitContributing) {
|
|
145
|
+
await initContributing(projectPath, info);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
115
149
|
await asyncExec('git add .', {
|
|
116
150
|
cwd: projectPath,
|
|
117
151
|
});
|
|
118
152
|
await asyncExec('git commit -m "chore: init"', {
|
|
119
153
|
cwd: projectPath,
|
|
120
154
|
});
|
|
121
|
-
loading.start();
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
155
|
+
const loading = ora__default["default"]('正在安装依赖……').start();
|
|
156
|
+
try {
|
|
157
|
+
await asyncExec(`${PACKAGE_MANAGER} i`, {
|
|
158
|
+
cwd: projectPath,
|
|
159
|
+
});
|
|
160
|
+
loading.succeed('依赖安装成功!');
|
|
161
|
+
}
|
|
162
|
+
catch (error) {
|
|
163
|
+
loading.fail('依赖安装失败!');
|
|
164
|
+
}
|
|
125
165
|
await asyncExec('git add .', {
|
|
126
166
|
cwd: projectPath,
|
|
127
167
|
});
|
|
@@ -129,14 +169,214 @@ async function init(projectPath, answers) {
|
|
|
129
169
|
catch (error) {
|
|
130
170
|
console.error(error);
|
|
131
171
|
}
|
|
132
|
-
finally {
|
|
133
|
-
loading.stop();
|
|
134
|
-
}
|
|
135
172
|
}
|
|
136
173
|
async function getGitUserName() {
|
|
137
174
|
const username = (await asyncExec('git config user.name'));
|
|
138
175
|
return username.trim();
|
|
139
176
|
}
|
|
177
|
+
async function initProjectJson(projectPath, answers) {
|
|
178
|
+
const loading = ora__default["default"]('正在初始化 package.json ……').start();
|
|
179
|
+
try {
|
|
180
|
+
const { name, author, description, isOpenSource, isPublishToNpm = false } = answers;
|
|
181
|
+
const repositoryUrl = `https://github.com/${author}/${name}`;
|
|
182
|
+
const homepage = `${repositoryUrl}#readme`;
|
|
183
|
+
const issuesUrl = `${repositoryUrl}/issues`;
|
|
184
|
+
const gitUrl = `git+${repositoryUrl}.git`;
|
|
185
|
+
const nodeVersion = await getLtsNodeVersion() || '12';
|
|
186
|
+
const node = Number(nodeVersion) - 4;
|
|
187
|
+
const pkgPath = path__default["default"].join(projectPath, 'package.json');
|
|
188
|
+
const pkg = await fs__default["default"].readJSON(pkgPath);
|
|
189
|
+
const pkgData = {
|
|
190
|
+
name,
|
|
191
|
+
author,
|
|
192
|
+
description,
|
|
193
|
+
private: !isPublishToNpm,
|
|
194
|
+
license: 'UNLICENSED',
|
|
195
|
+
engines: {
|
|
196
|
+
node: `>=${node}`,
|
|
197
|
+
},
|
|
198
|
+
};
|
|
199
|
+
let extData = {};
|
|
200
|
+
if (isOpenSource) {
|
|
201
|
+
extData = {
|
|
202
|
+
license: 'MIT',
|
|
203
|
+
homepage,
|
|
204
|
+
repository: {
|
|
205
|
+
type: 'git',
|
|
206
|
+
url: gitUrl,
|
|
207
|
+
},
|
|
208
|
+
bugs: {
|
|
209
|
+
url: issuesUrl,
|
|
210
|
+
},
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
const newPkg = Object.assign({}, pkg, pkgData, extData);
|
|
214
|
+
await fs__default["default"].writeFile(pkgPath, JSON.stringify(newPkg, null, 2));
|
|
215
|
+
loading.succeed('package.json 初始化成功!');
|
|
216
|
+
}
|
|
217
|
+
catch (error) {
|
|
218
|
+
console.error(error);
|
|
219
|
+
loading.fail('package.json 初始化失败!');
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
const cleanText = (text) => text.replace(/-/g, '--').replace(/_/g, '__');
|
|
223
|
+
async function getProjectInfo(projectPath, answers) {
|
|
224
|
+
var _a, _b, _c, _d, _e;
|
|
225
|
+
const loading = ora__default["default"]('正在获取项目信息 ……').start();
|
|
226
|
+
try {
|
|
227
|
+
const { name, author, description, isOpenSource, isPublishToNpm } = answers;
|
|
228
|
+
const packageManager = 'npm';
|
|
229
|
+
const pkgPath = path__default["default"].join(projectPath, 'package.json');
|
|
230
|
+
const pkg = await fs__default["default"].readJSON(pkgPath);
|
|
231
|
+
const engines = (pkg === null || pkg === void 0 ? void 0 : pkg.engines) || {};
|
|
232
|
+
const license = pkg === null || pkg === void 0 ? void 0 : pkg.license;
|
|
233
|
+
const version = pkg === null || pkg === void 0 ? void 0 : pkg.version;
|
|
234
|
+
const installCommand = isPublishToNpm ? `${packageManager} install ${name}` : `${packageManager} install`;
|
|
235
|
+
const startCommand = ((_a = pkg === null || pkg === void 0 ? void 0 : pkg.scripts) === null || _a === void 0 ? void 0 : _a.start) && `${packageManager} run start`;
|
|
236
|
+
const devCommand = ((_b = pkg === null || pkg === void 0 ? void 0 : pkg.scripts) === null || _b === void 0 ? void 0 : _b.dev) && `${packageManager} run dev`;
|
|
237
|
+
const buildCommand = ((_c = pkg === null || pkg === void 0 ? void 0 : pkg.scripts) === null || _c === void 0 ? void 0 : _c.build) && `${packageManager} run build`;
|
|
238
|
+
const testCommand = ((_d = pkg === null || pkg === void 0 ? void 0 : pkg.scripts) === null || _d === void 0 ? void 0 : _d.test) && `${packageManager} run test`;
|
|
239
|
+
const lintCommand = ((_e = pkg === null || pkg === void 0 ? void 0 : pkg.scripts) === null || _e === void 0 ? void 0 : _e.lint) && `${packageManager} run lint`;
|
|
240
|
+
const repositoryUrl = `https://github.com/${author}/${name}`;
|
|
241
|
+
const issuesUrl = `${repositoryUrl}/issues`;
|
|
242
|
+
const contributingUrl = `${repositoryUrl}/blob/master/CONTRIBUTING.md`;
|
|
243
|
+
const documentationUrl = `${repositoryUrl}#readme`;
|
|
244
|
+
const demoUrl = `${repositoryUrl}#readme`;
|
|
245
|
+
const homepage = documentationUrl;
|
|
246
|
+
const githubUsername = author;
|
|
247
|
+
const authorWebsite = await getAuthorWebsiteFromGithubAPI(githubUsername);
|
|
248
|
+
const licenseUrl = `${repositoryUrl}/blob/master/LICENSE`;
|
|
249
|
+
const discussionsUrl = `${repositoryUrl}/discussions`;
|
|
250
|
+
const pullRequestsUrl = `${repositoryUrl}/pulls`;
|
|
251
|
+
const projectInfos = {
|
|
252
|
+
currentYear: new Date().getFullYear(),
|
|
253
|
+
name,
|
|
254
|
+
description,
|
|
255
|
+
version,
|
|
256
|
+
author,
|
|
257
|
+
authorWebsite,
|
|
258
|
+
homepage,
|
|
259
|
+
demoUrl,
|
|
260
|
+
repositoryUrl,
|
|
261
|
+
issuesUrl,
|
|
262
|
+
contributingUrl,
|
|
263
|
+
githubUsername,
|
|
264
|
+
authorName: author,
|
|
265
|
+
authorGithubUsername: githubUsername,
|
|
266
|
+
engines,
|
|
267
|
+
licenseName: cleanText(license),
|
|
268
|
+
licenseUrl,
|
|
269
|
+
documentationUrl,
|
|
270
|
+
isGithubRepos: true,
|
|
271
|
+
installCommand,
|
|
272
|
+
startCommand,
|
|
273
|
+
usage: startCommand,
|
|
274
|
+
devCommand,
|
|
275
|
+
buildCommand,
|
|
276
|
+
testCommand,
|
|
277
|
+
lintCommand,
|
|
278
|
+
isJSProject: true,
|
|
279
|
+
packageManager,
|
|
280
|
+
isProjectOnNpm: isPublishToNpm,
|
|
281
|
+
isOpenSource,
|
|
282
|
+
projectName: name,
|
|
283
|
+
projectVersion: version,
|
|
284
|
+
projectDocumentationUrl: documentationUrl,
|
|
285
|
+
projectDescription: description,
|
|
286
|
+
projectHomepage: homepage,
|
|
287
|
+
projectDemoUrl: demoUrl,
|
|
288
|
+
projectPrerequisites: Object.keys(engines).map((key) => ({
|
|
289
|
+
name: key,
|
|
290
|
+
value: engines[key],
|
|
291
|
+
})),
|
|
292
|
+
discussionsUrl,
|
|
293
|
+
pullRequestsUrl,
|
|
294
|
+
};
|
|
295
|
+
loading.succeed('项目信息 初始化成功!');
|
|
296
|
+
return projectInfos;
|
|
297
|
+
}
|
|
298
|
+
catch (error) {
|
|
299
|
+
loading.fail('项目信息 初始化失败!');
|
|
300
|
+
console.error(error);
|
|
301
|
+
return null;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
async function initReadme(projectPath, projectInfos) {
|
|
305
|
+
const loading = ora__default["default"]('正在初始化 README.md ……').start();
|
|
306
|
+
try {
|
|
307
|
+
const templatePath = path__default["default"].join(__dirname, '../templates/README.md');
|
|
308
|
+
const template = (await fs__default["default"].readFile(templatePath, 'utf8')).toString();
|
|
309
|
+
const newReadmePath = path__default["default"].join(projectPath, 'README.md');
|
|
310
|
+
const readmeContent = await ejs__default["default"].render(template, projectInfos, {
|
|
311
|
+
debug: false,
|
|
312
|
+
async: true,
|
|
313
|
+
});
|
|
314
|
+
if (await fs__default["default"].pathExists(newReadmePath)) {
|
|
315
|
+
await fs__default["default"].remove(newReadmePath);
|
|
316
|
+
}
|
|
317
|
+
await fs__default["default"].writeFile(newReadmePath, lintMd(lodash.unescape(readmeContent)));
|
|
318
|
+
loading.succeed('README.md 初始化成功!');
|
|
319
|
+
}
|
|
320
|
+
catch (error) {
|
|
321
|
+
loading.fail('README.md 初始化失败!');
|
|
322
|
+
console.error(error);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
async function initContributing(projectPath, projectInfos) {
|
|
326
|
+
const loading = ora__default["default"]('正在初始化 贡献指南 ……').start();
|
|
327
|
+
try {
|
|
328
|
+
const templatePath = path__default["default"].join(__dirname, '../templates/CONTRIBUTING.md');
|
|
329
|
+
const template = (await fs__default["default"].readFile(templatePath, 'utf8')).toString();
|
|
330
|
+
const newReadmePath = path__default["default"].join(projectPath, 'CONTRIBUTING.md');
|
|
331
|
+
const readmeContent = await ejs__default["default"].render(template, projectInfos, {
|
|
332
|
+
debug: false,
|
|
333
|
+
async: true,
|
|
334
|
+
});
|
|
335
|
+
if (await fs__default["default"].pathExists(newReadmePath)) {
|
|
336
|
+
await fs__default["default"].remove(newReadmePath);
|
|
337
|
+
}
|
|
338
|
+
await fs__default["default"].writeFile(newReadmePath, lintMd(lodash.unescape(readmeContent)));
|
|
339
|
+
loading.succeed('贡献指南 初始化成功!');
|
|
340
|
+
}
|
|
341
|
+
catch (error) {
|
|
342
|
+
loading.fail('贡献指南 初始化失败!');
|
|
343
|
+
console.error(error);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
async function getAuthorWebsiteFromGithubAPI(githubUsername) {
|
|
347
|
+
try {
|
|
348
|
+
const userData = (await axios__default["default"].get(`${GITHUB_API_URL}/users/${githubUsername}`)).data;
|
|
349
|
+
const authorWebsite = userData === null || userData === void 0 ? void 0 : userData.blog;
|
|
350
|
+
return authorWebsite || '';
|
|
351
|
+
}
|
|
352
|
+
catch (error) {
|
|
353
|
+
console.error(error);
|
|
354
|
+
return '';
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
async function getLtsNodeVersion() {
|
|
358
|
+
var _a, _b;
|
|
359
|
+
try {
|
|
360
|
+
const html = (await axios__default["default"].get(NODEJS_URL)).data;
|
|
361
|
+
const version = (_a = html.match(/<strong>(.*)<\/strong>/)) === null || _a === void 0 ? void 0 : _a[1];
|
|
362
|
+
return (_b = version.split('.')) === null || _b === void 0 ? void 0 : _b[0];
|
|
363
|
+
}
|
|
364
|
+
catch (error) {
|
|
365
|
+
console.error(error);
|
|
366
|
+
return '';
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
function lintMd(markdown) {
|
|
370
|
+
const rules = {
|
|
371
|
+
'no-empty-code': 0,
|
|
372
|
+
'no-trailing-punctuation': 0,
|
|
373
|
+
'no-long-code': 0,
|
|
374
|
+
'no-empty-code-lang': 0,
|
|
375
|
+
'no-empty-inlinecode': 0,
|
|
376
|
+
};
|
|
377
|
+
const fixed = core.fix(markdown, rules);
|
|
378
|
+
return fixed;
|
|
379
|
+
}
|
|
140
380
|
|
|
141
381
|
module.exports = function (plop) {
|
|
142
382
|
plop.setActionType('initProject', async (answers) => {
|
|
@@ -164,9 +404,6 @@ module.exports = function (plop) {
|
|
|
164
404
|
type: 'input',
|
|
165
405
|
name: 'description',
|
|
166
406
|
message: '请输入项目简介',
|
|
167
|
-
transformer(input) {
|
|
168
|
-
return (input === null || input === void 0 ? void 0 : input.trim()) || '';
|
|
169
|
-
},
|
|
170
407
|
default: '',
|
|
171
408
|
filter: (e) => e.trim(),
|
|
172
409
|
},
|
|
@@ -213,6 +450,58 @@ module.exports = function (plop) {
|
|
|
213
450
|
message: '是否开源?',
|
|
214
451
|
default: false,
|
|
215
452
|
},
|
|
453
|
+
{
|
|
454
|
+
type: 'confirm',
|
|
455
|
+
name: 'isInitRemoteRepo',
|
|
456
|
+
message: '是否初始化远程 Git 仓库?',
|
|
457
|
+
default: false,
|
|
458
|
+
},
|
|
459
|
+
{
|
|
460
|
+
type: 'input',
|
|
461
|
+
name: 'gitRemoteUrl',
|
|
462
|
+
message: '请输入远程 Git 仓库 Url',
|
|
463
|
+
validate(input) {
|
|
464
|
+
return input.trim().length !== 0;
|
|
465
|
+
},
|
|
466
|
+
default(answers) {
|
|
467
|
+
const { isOpenSource, name, author } = answers;
|
|
468
|
+
if (isOpenSource) {
|
|
469
|
+
return `git@github.com:${author}/${name}.git`;
|
|
470
|
+
}
|
|
471
|
+
return `git@gitee.com:caomeiyouren/${name}.git`;
|
|
472
|
+
},
|
|
473
|
+
filter: (e) => e.trim(),
|
|
474
|
+
when(answers) {
|
|
475
|
+
return answers.isInitRemoteRepo;
|
|
476
|
+
},
|
|
477
|
+
},
|
|
478
|
+
{
|
|
479
|
+
type: 'confirm',
|
|
480
|
+
name: 'isPublishToNpm',
|
|
481
|
+
message: '是否发布到 npm?',
|
|
482
|
+
default: false,
|
|
483
|
+
when(answers) {
|
|
484
|
+
return answers.isOpenSource;
|
|
485
|
+
},
|
|
486
|
+
},
|
|
487
|
+
{
|
|
488
|
+
type: 'confirm',
|
|
489
|
+
name: 'isInitReadme',
|
|
490
|
+
message: '是否初始化 README.md ?',
|
|
491
|
+
default: true,
|
|
492
|
+
when(answers) {
|
|
493
|
+
return answers.isOpenSource;
|
|
494
|
+
},
|
|
495
|
+
},
|
|
496
|
+
{
|
|
497
|
+
type: 'confirm',
|
|
498
|
+
name: 'isInitContributing',
|
|
499
|
+
message: '是否初始化 贡献指南(CONTRIBUTING.md) ?',
|
|
500
|
+
default: true,
|
|
501
|
+
when(answers) {
|
|
502
|
+
return answers.isOpenSource;
|
|
503
|
+
},
|
|
504
|
+
},
|
|
216
505
|
{
|
|
217
506
|
type: 'confirm',
|
|
218
507
|
name: 'isRemoveDependabot',
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cmyr-template-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "草梅友仁自制的项目模板创建器",
|
|
5
5
|
"author": "CaoMeiYouRen",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
8
|
"type": "commonjs",
|
|
9
9
|
"files": [
|
|
10
|
-
"dist"
|
|
10
|
+
"dist",
|
|
11
|
+
"templates"
|
|
11
12
|
],
|
|
12
13
|
"engines": {
|
|
13
14
|
"node": ">=12"
|
|
@@ -39,9 +40,10 @@
|
|
|
39
40
|
"@semantic-release/changelog": "^6.0.0",
|
|
40
41
|
"@semantic-release/git": "^10.0.0",
|
|
41
42
|
"@types/debug": "^4.1.5",
|
|
43
|
+
"@types/ejs": "^3.1.0",
|
|
42
44
|
"@types/fs-extra": "^9.0.4",
|
|
43
45
|
"@types/lodash": "^4.14.165",
|
|
44
|
-
"@types/node": "^
|
|
46
|
+
"@types/node": "^17.0.0",
|
|
45
47
|
"@types/promise.any": "^2.0.0",
|
|
46
48
|
"@typescript-eslint/eslint-plugin": "^4.9.0",
|
|
47
49
|
"@typescript-eslint/parser": "^4.9.0",
|
|
@@ -52,10 +54,9 @@
|
|
|
52
54
|
"cz-conventional-changelog": "^3.3.0",
|
|
53
55
|
"debug": "^4.3.1",
|
|
54
56
|
"eslint": "^7.14.0",
|
|
55
|
-
"eslint-config-cmyr": "^1.1.
|
|
57
|
+
"eslint-config-cmyr": "^1.1.14",
|
|
56
58
|
"husky": "^7.0.2",
|
|
57
59
|
"lint-staged": "^12.0.2",
|
|
58
|
-
"lodash": "^4.17.20",
|
|
59
60
|
"rimraf": "^3.0.2",
|
|
60
61
|
"rollup": "^2.33.3",
|
|
61
62
|
"rollup-plugin-terser": "^7.0.2",
|
|
@@ -66,12 +67,15 @@
|
|
|
66
67
|
"validate-commit-msg": "^2.14.0"
|
|
67
68
|
},
|
|
68
69
|
"dependencies": {
|
|
70
|
+
"@lint-md/core": "^0.2.1",
|
|
69
71
|
"axios": "^0.24.0",
|
|
70
72
|
"colors": "^1.4.0",
|
|
71
73
|
"commander": "^8.2.0",
|
|
72
74
|
"dayjs": "^1.9.6",
|
|
73
75
|
"download-git-repo": "^3.0.2",
|
|
76
|
+
"ejs": "^3.1.6",
|
|
74
77
|
"fs-extra": "^10.0.0",
|
|
78
|
+
"lodash": "^4.17.20",
|
|
75
79
|
"minimist": "^1.2.5",
|
|
76
80
|
"ora": "^5.4.1",
|
|
77
81
|
"plop": "^2.7.6",
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# 贡献指南
|
|
2
|
+
|
|
3
|
+
在为此存储库做出贡献时,请首先通过 issue、电子邮件或任何其他方法与此存储库的所有者讨论您希望进行的更改,然后再进行更改。
|
|
4
|
+
|
|
5
|
+
## 开发环境设置
|
|
6
|
+
|
|
7
|
+
要设置开发环境,请按照以下步骤操作:
|
|
8
|
+
|
|
9
|
+
1. Clone 本项目
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
git clone <%= repositoryUrl %>
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
2. 安装依赖
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
npm i
|
|
19
|
+
# 或 yarn
|
|
20
|
+
# 或 pnpm i
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
3. 运行开发环境
|
|
24
|
+
|
|
25
|
+
<% if (devCommand) { -%>
|
|
26
|
+
```sh
|
|
27
|
+
<%= devCommand %>
|
|
28
|
+
```
|
|
29
|
+
<% } -%>
|
|
30
|
+
|
|
31
|
+
## 问题和功能请求
|
|
32
|
+
|
|
33
|
+
你在源代码中发现了一个错误,文档中有一个错误,或者你想要一个新功能? 看看[GitHub 讨论](<%= discussionsUrl %>)看看它是否已经在讨论中。您可以通过[在 GitHub 上提交问题](<%= issuesUrl %>)来帮助我们。在创建问题之前,请确保搜索问题存档 - 您的问题可能已经得到解决!
|
|
34
|
+
|
|
35
|
+
请尝试创建以下错误报告:
|
|
36
|
+
|
|
37
|
+
- *可重现。*包括重现问题的步骤。
|
|
38
|
+
- *具体的。*包括尽可能多的细节:哪个版本,什么环境等。
|
|
39
|
+
- *独特的。*不要复制现有的已打开问题。
|
|
40
|
+
- *范围仅限于单个错误。*每个报告一个错误。
|
|
41
|
+
|
|
42
|
+
**更好的是:提交带有修复或新功能的拉取请求!**
|
|
43
|
+
|
|
44
|
+
### 如何提交拉取请求
|
|
45
|
+
|
|
46
|
+
1. 在我们的存储库中搜索 与您的提交相关的开放或关闭的 [Pull Requests](<%= pullRequestsUrl %>)。你不想重复努力。
|
|
47
|
+
|
|
48
|
+
2. Fork 本项目
|
|
49
|
+
|
|
50
|
+
3. 创建您的功能分支 ( `git checkout -b feat/your_feature`)
|
|
51
|
+
|
|
52
|
+
4. 提交您的更改
|
|
53
|
+
|
|
54
|
+
本项目使用 [约定式提交](https://www.conventionalcommits.org/zh-hans/v1.0.0/),因此请遵循提交消息中的规范。
|
|
55
|
+
|
|
56
|
+
git commit 将用于自动化生成日志,所以请勿直接提交 git commit。
|
|
57
|
+
|
|
58
|
+
非常建议使用 [commitizen](https://github.com/commitizen/cz-cli) 工具来生成 git commit,使用 husky 约束 git commit
|
|
59
|
+
|
|
60
|
+
```sh
|
|
61
|
+
git add .
|
|
62
|
+
git cz # 使用 commitizen 提交!
|
|
63
|
+
git pull # 请合并最新代码并解决冲突后提交!
|
|
64
|
+
#请勿直接提交git commit
|
|
65
|
+
#若觉得修改太多也可分开提交。先 git add 一部分,执行 git cz 提交后再提交另外一部分
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
关于选项,参考 [semantic-release](https://github.com/semantic-release/semantic-release) 的文档
|
|
69
|
+
|
|
70
|
+
- 若为 BUG 修复,则选择 `fix`
|
|
71
|
+
- 若为新增功能,则选择 `feat`,新增音声可以按这个提交。
|
|
72
|
+
- 若为移除某些功能,则选择 `perf` 或填写 `BREAKING CHANGE`
|
|
73
|
+
- `perf` 和其他破坏性更新,若不是为了修复 BUG,原则上将拒绝该 PR
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
5. 推送到分支 ( `git push origin feat/your_feature`)
|
|
77
|
+
|
|
78
|
+
6. [打开一个新的 Pull Request](<%= repositoryUrl %>/compare?expand=1)
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
<h1 align="center"><%= projectName %> </h1>
|
|
2
|
+
<p>
|
|
3
|
+
<% if (isProjectOnNpm) { -%>
|
|
4
|
+
<a href="https://www.npmjs.com/package/<%= projectName %>" target="_blank">
|
|
5
|
+
<img alt="Version" src="https://img.shields.io/npm/v/<%= projectName %>.svg">
|
|
6
|
+
</a>
|
|
7
|
+
<% } -%>
|
|
8
|
+
<% if (projectVersion && !isProjectOnNpm) { -%>
|
|
9
|
+
<img alt="Version" src="https://img.shields.io/badge/version-<%= projectVersion %>-blue.svg?cacheSeconds=2592000" />
|
|
10
|
+
<% } -%>
|
|
11
|
+
<% if (isGithubRepos) { -%>
|
|
12
|
+
<a href="<%= repositoryUrl %>/actions?query=workflow%3ARelease" target="_blank">
|
|
13
|
+
<img alt="GitHub Workflow Status" src="https://img.shields.io/github/workflow/status/<%= authorGithubUsername %>/<%= projectName %>/Release">
|
|
14
|
+
</a>
|
|
15
|
+
<% } -%>
|
|
16
|
+
<% if (projectPrerequisites) { -%>
|
|
17
|
+
<% projectPrerequisites.map(({ name, value }) => { -%>
|
|
18
|
+
<img src="https://img.shields.io/badge/<%= name %>-<%= encodeURIComponent(value) %>-blue.svg" />
|
|
19
|
+
<% }) -%>
|
|
20
|
+
<% } -%>
|
|
21
|
+
<% if (projectDocumentationUrl) { -%>
|
|
22
|
+
<a href="<%= projectDocumentationUrl %>" target="_blank">
|
|
23
|
+
<img alt="Documentation" src="https://img.shields.io/badge/documentation-yes-brightgreen.svg" />
|
|
24
|
+
</a>
|
|
25
|
+
<% } -%>
|
|
26
|
+
<% if (isGithubRepos) { -%>
|
|
27
|
+
<a href="<%= repositoryUrl %>/graphs/commit-activity" target="_blank">
|
|
28
|
+
<img alt="Maintenance" src="https://img.shields.io/badge/Maintained%3F-yes-green.svg" />
|
|
29
|
+
</a>
|
|
30
|
+
<% } -%>
|
|
31
|
+
<% if (licenseName) { -%>
|
|
32
|
+
<a href="<%= licenseUrl ? licenseUrl : '#' %>" target="_blank">
|
|
33
|
+
<img alt="License: <%= licenseName %>" src="https://img.shields.io/<%= `badge/License-${licenseName}-yellow.svg` %>" />
|
|
34
|
+
</a>
|
|
35
|
+
<% } -%>
|
|
36
|
+
</p>
|
|
37
|
+
|
|
38
|
+
<% if (projectDescription) { -%>
|
|
39
|
+
|
|
40
|
+
> <%= projectDescription %>
|
|
41
|
+
<% } -%>
|
|
42
|
+
<% if (projectHomepage) { -%>
|
|
43
|
+
|
|
44
|
+
### 🏠 [主页](<%= projectHomepage %>)
|
|
45
|
+
|
|
46
|
+
[<%= projectHomepage %>](<%= projectHomepage %>)
|
|
47
|
+
|
|
48
|
+
<% } -%>
|
|
49
|
+
<% if (projectDemoUrl) { -%>
|
|
50
|
+
|
|
51
|
+
### ✨ [Demo](<%= projectDemoUrl %>)
|
|
52
|
+
|
|
53
|
+
[<%= projectDemoUrl %>](<%= projectDemoUrl %>)
|
|
54
|
+
|
|
55
|
+
<% } -%>
|
|
56
|
+
<% if (projectPrerequisites && projectPrerequisites.length) { -%>
|
|
57
|
+
|
|
58
|
+
## 依赖要求
|
|
59
|
+
|
|
60
|
+
<% projectPrerequisites.map(({ name, value }) => { -%>
|
|
61
|
+
- <%= name %> <%= value %>
|
|
62
|
+
<% }) -%>
|
|
63
|
+
<% } -%>
|
|
64
|
+
<% if (installCommand) { -%>
|
|
65
|
+
|
|
66
|
+
## 安装
|
|
67
|
+
|
|
68
|
+
```sh
|
|
69
|
+
<%= installCommand %>
|
|
70
|
+
```
|
|
71
|
+
<% } -%>
|
|
72
|
+
<% if (usage) { -%>
|
|
73
|
+
|
|
74
|
+
## 使用
|
|
75
|
+
|
|
76
|
+
```sh
|
|
77
|
+
<%= usage %>
|
|
78
|
+
```
|
|
79
|
+
<% } -%>
|
|
80
|
+
<% if (devCommand) { -%>
|
|
81
|
+
|
|
82
|
+
## 开发
|
|
83
|
+
|
|
84
|
+
```sh
|
|
85
|
+
<%= devCommand %>
|
|
86
|
+
```
|
|
87
|
+
<% } -%>
|
|
88
|
+
<% if (buildCommand) { -%>
|
|
89
|
+
|
|
90
|
+
## 编译
|
|
91
|
+
|
|
92
|
+
```sh
|
|
93
|
+
<%= buildCommand %>
|
|
94
|
+
```
|
|
95
|
+
<% } -%>
|
|
96
|
+
<% if (testCommand) { -%>
|
|
97
|
+
|
|
98
|
+
## 测试
|
|
99
|
+
|
|
100
|
+
```sh
|
|
101
|
+
<%= testCommand %>
|
|
102
|
+
```
|
|
103
|
+
<% } -%>
|
|
104
|
+
<% if (lintCommand) { -%>
|
|
105
|
+
|
|
106
|
+
## Lint
|
|
107
|
+
|
|
108
|
+
```sh
|
|
109
|
+
<%= lintCommand %>
|
|
110
|
+
```
|
|
111
|
+
<% } -%>
|
|
112
|
+
|
|
113
|
+
<% if (authorName || authorGithubUsername) { -%>
|
|
114
|
+
|
|
115
|
+
## 作者
|
|
116
|
+
|
|
117
|
+
<% if (authorName) { %>
|
|
118
|
+
👤 **<%= authorName %>**
|
|
119
|
+
<% } %>
|
|
120
|
+
<% if (authorWebsite) { -%>
|
|
121
|
+
* Website: [<%= authorWebsite %>](<%= authorWebsite %>)
|
|
122
|
+
<% } -%>
|
|
123
|
+
<% if (authorGithubUsername) { -%>
|
|
124
|
+
* GitHub: [@<%= authorGithubUsername %>](https://github.com/<%= authorGithubUsername %>)
|
|
125
|
+
<% } -%>
|
|
126
|
+
<% } %>
|
|
127
|
+
<% if (issuesUrl) { -%>
|
|
128
|
+
|
|
129
|
+
## 🤝贡献
|
|
130
|
+
|
|
131
|
+
欢迎 贡献、提问或提出新功能!<br />如有问题请查看 [issues page](<%= issuesUrl %>). <br/><%= contributingUrl ? `贡献或提出新功能可以查看[contributing guide](${contributingUrl}).` : '' %>
|
|
132
|
+
<% } -%>
|
|
133
|
+
|
|
134
|
+
## 支持
|
|
135
|
+
|
|
136
|
+
如果觉得这个项目有用的话请给一颗⭐️,非常感谢
|
|
137
|
+
|
|
138
|
+
<% if (licenseName && licenseUrl) { -%>
|
|
139
|
+
|
|
140
|
+
## 📝 License
|
|
141
|
+
|
|
142
|
+
<% if (authorName && authorGithubUsername) { -%>
|
|
143
|
+
Copyright © <%= currentYear %> [<%= authorName %>](https://github.com/<%= authorGithubUsername %>).<br />
|
|
144
|
+
<% } -%>
|
|
145
|
+
This project is [<%= licenseName %>](<%= licenseUrl %>) licensed.
|
|
146
|
+
<% } -%>
|
|
147
|
+
|
|
148
|
+
***
|
|
149
|
+
_This README was generated with ❤️ by [cmyr-template-cli](https://github.com/CaoMeiYouRen/cmyr-template-cli)_
|