cmyr-template-cli 1.5.2 → 1.7.2

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,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(process.env.VERSION || '1.0.0', '-v, --version');
16
+ program.version("1.7.1" , '-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
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  'use strict';
3
3
 
4
- var path = require('path');
5
4
  var fs = require('fs-extra');
5
+ var path = require('path');
6
6
  var ora = require('ora');
7
7
  var download = require('download-git-repo');
8
8
  var axios = require('axios');
@@ -32,8 +32,8 @@ function _interopNamespace(e) {
32
32
  return Object.freeze(n);
33
33
  }
34
34
 
35
- var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
36
35
  var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
36
+ var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
37
37
  var ora__default = /*#__PURE__*/_interopDefaultLegacy(ora);
38
38
  var download__default = /*#__PURE__*/_interopDefaultLegacy(download);
39
39
  var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
@@ -43,17 +43,19 @@ var ejs__default = /*#__PURE__*/_interopDefaultLegacy(ejs);
43
43
  process.env;
44
44
  const PACKAGE_MANAGER = 'pnpm';
45
45
 
46
+ axios__default["default"].defaults.timeout = 10 * 1000;
46
47
  if (!Promise.any) {
47
48
  Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('promise.any')); }).then((any) => {
48
49
  Promise.any = any.default;
49
50
  });
50
51
  }
51
52
  const GITHUB_API_URL = 'https://api.github.com';
53
+ const NODEJS_URL = 'https://nodejs.org/zh-cn/download/';
52
54
  const REMOTES = [
53
55
  'https://github.com',
54
56
  'https://hub.fastgit.org',
55
- 'https://gitclone.com',
56
57
  'https://github.com.cnpmjs.org',
58
+ 'https://download.fastgit.org',
57
59
  ];
58
60
  async function downloadGitRepo(repository, destination, options = {}) {
59
61
  const fastRepo = await getFastGitRepo(repository);
@@ -104,8 +106,16 @@ async function asyncExec(cmd, options) {
104
106
  });
105
107
  });
106
108
  }
109
+ async function initProject(answers) {
110
+ const { name, template } = answers;
111
+ const projectPath = path__default["default"].join(process.cwd(), name);
112
+ await downloadGitRepo(`CaoMeiYouRen/${template}`, projectPath);
113
+ await init(projectPath, answers);
114
+ return '- 下载项目模板成功!';
115
+ }
107
116
  async function init(projectPath, answers) {
108
- const { isOpenSource, isRemoveDependabot, gitRemoteUrl } = answers;
117
+ var _a;
118
+ const { isOpenSource, isRemoveDependabot, gitRemoteUrl, isInitReadme, isInitContributing, isInitHusky, isInitSemanticRelease } = answers;
109
119
  try {
110
120
  await asyncExec('git --version', {
111
121
  cwd: projectPath,
@@ -132,16 +142,32 @@ async function init(projectPath, answers) {
132
142
  await fs__default["default"].remove(mergifyPath);
133
143
  }
134
144
  }
135
- await initProjectJson(projectPath, answers);
145
+ const newPkg = await initProjectJson(projectPath, answers);
136
146
  if (isOpenSource) {
137
- await initReadme(projectPath, answers);
147
+ const info = await getProjectInfo(projectPath, answers);
148
+ if (info) {
149
+ if (isInitReadme) {
150
+ await initReadme(projectPath, info);
151
+ }
152
+ if (isInitContributing) {
153
+ await initContributing(projectPath, info);
154
+ }
155
+ if (info.licenseName === 'MIT') {
156
+ await initLicense(projectPath, info);
157
+ }
158
+ if (isInitSemanticRelease) {
159
+ await initSemanticRelease(projectPath, info);
160
+ }
161
+ if (isInitHusky) {
162
+ await initHusky(projectPath, info);
163
+ }
164
+ }
165
+ await initGithubWorkflows(projectPath, info);
138
166
  }
167
+ await initConfig(projectPath);
139
168
  await asyncExec('git add .', {
140
169
  cwd: projectPath,
141
170
  });
142
- await asyncExec('git commit -m "chore: init"', {
143
- cwd: projectPath,
144
- });
145
171
  const loading = ora__default["default"]('正在安装依赖……').start();
146
172
  try {
147
173
  await asyncExec(`${PACKAGE_MANAGER} i`, {
@@ -151,17 +177,29 @@ async function init(projectPath, answers) {
151
177
  }
152
178
  catch (error) {
153
179
  loading.fail('依赖安装失败!');
180
+ process.exit(1);
181
+ }
182
+ await asyncExec('git add .', {
183
+ cwd: projectPath,
184
+ });
185
+ if ((_a = newPkg === null || newPkg === void 0 ? void 0 : newPkg.scripts) === null || _a === void 0 ? void 0 : _a.lint) {
186
+ await asyncExec(`${PACKAGE_MANAGER} run lint`, {
187
+ cwd: projectPath,
188
+ });
154
189
  }
155
190
  await asyncExec('git add .', {
156
191
  cwd: projectPath,
157
192
  });
193
+ await asyncExec('git commit -m "chore: init"', {
194
+ cwd: projectPath,
195
+ });
158
196
  }
159
197
  catch (error) {
160
198
  console.error(error);
161
199
  }
162
200
  }
163
201
  async function getGitUserName() {
164
- const username = (await asyncExec('git config user.name'));
202
+ const username = (await asyncExec('git config user.name')) || '';
165
203
  return username.trim();
166
204
  }
167
205
  async function initProjectJson(projectPath, answers) {
@@ -172,6 +210,8 @@ async function initProjectJson(projectPath, answers) {
172
210
  const homepage = `${repositoryUrl}#readme`;
173
211
  const issuesUrl = `${repositoryUrl}/issues`;
174
212
  const gitUrl = `git+${repositoryUrl}.git`;
213
+ const nodeVersion = await getLtsNodeVersion() || '16';
214
+ const node = Number(nodeVersion) - 4;
175
215
  const pkgPath = path__default["default"].join(projectPath, 'package.json');
176
216
  const pkg = await fs__default["default"].readJSON(pkgPath);
177
217
  const pkgData = {
@@ -181,7 +221,7 @@ async function initProjectJson(projectPath, answers) {
181
221
  private: !isPublishToNpm,
182
222
  license: 'UNLICENSED',
183
223
  engines: {
184
- node: '>=12',
224
+ node: `>=${node}`,
185
225
  },
186
226
  };
187
227
  let extData = {};
@@ -196,11 +236,15 @@ async function initProjectJson(projectPath, answers) {
196
236
  bugs: {
197
237
  url: issuesUrl,
198
238
  },
239
+ changelog: {
240
+ language: 'zh',
241
+ },
199
242
  };
200
243
  }
201
244
  const newPkg = Object.assign({}, pkg, pkgData, extData);
202
245
  await fs__default["default"].writeFile(pkgPath, JSON.stringify(newPkg, null, 2));
203
246
  loading.succeed('package.json 初始化成功!');
247
+ return newPkg;
204
248
  }
205
249
  catch (error) {
206
250
  console.error(error);
@@ -208,15 +252,12 @@ async function initProjectJson(projectPath, answers) {
208
252
  }
209
253
  }
210
254
  const cleanText = (text) => text.replace(/-/g, '--').replace(/_/g, '__');
211
- async function initReadme(projectPath, answers) {
255
+ async function getProjectInfo(projectPath, answers) {
212
256
  var _a, _b, _c, _d, _e;
213
- const loading = ora__default["default"]('正在初始化 README.md ……').start();
257
+ const loading = ora__default["default"]('正在获取项目信息 ……').start();
214
258
  try {
215
259
  const { name, author, description, isOpenSource, isPublishToNpm } = answers;
216
260
  const packageManager = 'npm';
217
- const templatePath = path__default["default"].join(__dirname, '../templates/README.md');
218
- const template = (await fs__default["default"].readFile(templatePath, 'utf8')).toString();
219
- const newReadmePath = path__default["default"].join(projectPath, 'README.md');
220
261
  const pkgPath = path__default["default"].join(projectPath, 'package.json');
221
262
  const pkg = await fs__default["default"].readJSON(pkgPath);
222
263
  const engines = (pkg === null || pkg === void 0 ? void 0 : pkg.engines) || {};
@@ -235,10 +276,12 @@ async function initReadme(projectPath, answers) {
235
276
  const demoUrl = `${repositoryUrl}#readme`;
236
277
  const homepage = documentationUrl;
237
278
  const githubUsername = author;
238
- const authorWebsite = isOpenSource ? await getAuthorWebsiteFromGithubAPI(githubUsername) : '';
279
+ const authorWebsite = await getAuthorWebsiteFromGithubAPI(githubUsername);
239
280
  const licenseUrl = `${repositoryUrl}/blob/master/LICENSE`;
281
+ const discussionsUrl = `${repositoryUrl}/discussions`;
282
+ const pullRequestsUrl = `${repositoryUrl}/pulls`;
240
283
  const projectInfos = {
241
- filename: templatePath,
284
+ ...answers,
242
285
  currentYear: new Date().getFullYear(),
243
286
  name,
244
287
  description,
@@ -279,7 +322,24 @@ async function initReadme(projectPath, answers) {
279
322
  name: key,
280
323
  value: engines[key],
281
324
  })),
325
+ discussionsUrl,
326
+ pullRequestsUrl,
282
327
  };
328
+ loading.succeed('项目信息 初始化成功!');
329
+ return projectInfos;
330
+ }
331
+ catch (error) {
332
+ loading.fail('项目信息 初始化失败!');
333
+ console.error(error);
334
+ return null;
335
+ }
336
+ }
337
+ async function initReadme(projectPath, projectInfos) {
338
+ const loading = ora__default["default"]('正在初始化 README.md ……').start();
339
+ try {
340
+ const templatePath = path__default["default"].join(__dirname, '../templates/README.md');
341
+ const template = (await fs__default["default"].readFile(templatePath, 'utf8')).toString();
342
+ const newReadmePath = path__default["default"].join(projectPath, 'README.md');
283
343
  const readmeContent = await ejs__default["default"].render(template, projectInfos, {
284
344
  debug: false,
285
345
  async: true,
@@ -295,6 +355,209 @@ async function initReadme(projectPath, answers) {
295
355
  console.error(error);
296
356
  }
297
357
  }
358
+ async function initContributing(projectPath, projectInfos) {
359
+ const loading = ora__default["default"]('正在初始化 贡献指南 ……').start();
360
+ try {
361
+ const templatePath = path__default["default"].join(__dirname, '../templates/CONTRIBUTING.md');
362
+ const template = (await fs__default["default"].readFile(templatePath, 'utf8')).toString();
363
+ const newReadmePath = path__default["default"].join(projectPath, 'CONTRIBUTING.md');
364
+ const readmeContent = await ejs__default["default"].render(template, projectInfos, {
365
+ debug: false,
366
+ async: true,
367
+ });
368
+ if (await fs__default["default"].pathExists(newReadmePath)) {
369
+ await fs__default["default"].remove(newReadmePath);
370
+ }
371
+ await fs__default["default"].writeFile(newReadmePath, lintMd(lodash.unescape(readmeContent)));
372
+ loading.succeed('贡献指南 初始化成功!');
373
+ }
374
+ catch (error) {
375
+ loading.fail('贡献指南 初始化失败!');
376
+ console.error(error);
377
+ }
378
+ }
379
+ async function initLicense(projectPath, projectInfos) {
380
+ const loading = ora__default["default"]('正在初始化 LICENSE ……').start();
381
+ try {
382
+ const templatePath = path__default["default"].join(__dirname, '../templates/LICENSE');
383
+ const template = (await fs__default["default"].readFile(templatePath, 'utf8')).toString();
384
+ const newReadmePath = path__default["default"].join(projectPath, 'LICENSE');
385
+ const readmeContent = await ejs__default["default"].render(template, projectInfos, {
386
+ debug: false,
387
+ async: true,
388
+ });
389
+ if (await fs__default["default"].pathExists(newReadmePath)) {
390
+ await fs__default["default"].remove(newReadmePath);
391
+ }
392
+ await fs__default["default"].writeFile(newReadmePath, lodash.unescape(readmeContent));
393
+ loading.succeed('LICENSE 初始化成功!');
394
+ }
395
+ catch (error) {
396
+ loading.fail('LICENSE 初始化失败!');
397
+ console.error(error);
398
+ }
399
+ }
400
+ async function initConfig(projectPath) {
401
+ try {
402
+ const files = ['.editorconfig', 'commitlint.config.js'];
403
+ files.forEach(async (file) => {
404
+ const templatePath = path__default["default"].join(__dirname, '../templates/', file);
405
+ const newPath = path__default["default"].join(projectPath, file);
406
+ if (await fs__default["default"].pathExists(newPath)) {
407
+ await fs__default["default"].remove(newPath);
408
+ }
409
+ await fs__default["default"].copyFile(templatePath, newPath);
410
+ });
411
+ }
412
+ catch (error) {
413
+ console.error(error);
414
+ }
415
+ }
416
+ async function initGithubWorkflows(projectPath, projectInfos) {
417
+ const loading = ora__default["default"]('正在初始化 Github Workflows ……').start();
418
+ try {
419
+ const { isInitSemanticRelease } = projectInfos;
420
+ const files = ['.github/workflows/test.yml'];
421
+ const dir = path__default["default"].join(projectPath, '.github/workflows');
422
+ if (!await fs__default["default"].pathExists(dir)) {
423
+ await fs__default["default"].mkdirp(dir);
424
+ }
425
+ const releaseYml = '.github/workflows/release.yml';
426
+ if (isInitSemanticRelease) {
427
+ 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
+ }
433
+ else {
434
+ const oldReleaseYml = path__default["default"].join(projectPath, releaseYml);
435
+ if (await fs__default["default"].pathExists(oldReleaseYml)) {
436
+ await fs__default["default"].remove(oldReleaseYml);
437
+ }
438
+ }
439
+ files.forEach(async (file) => {
440
+ const templatePath = path__default["default"].join(__dirname, '../templates/', file);
441
+ const newPath = path__default["default"].join(projectPath, file);
442
+ if (await fs__default["default"].pathExists(newPath)) {
443
+ await fs__default["default"].remove(newPath);
444
+ }
445
+ await fs__default["default"].copyFile(templatePath, newPath);
446
+ });
447
+ loading.succeed('Github Workflows 初始化成功!');
448
+ }
449
+ catch (error) {
450
+ loading.fail('Github Workflows 初始化失败!');
451
+ console.error(error);
452
+ }
453
+ }
454
+ async function initSemanticRelease(projectPath, projectInfos) {
455
+ const loading = ora__default["default"]('正在初始化 semantic-release ……').start();
456
+ try {
457
+ const files = ['.releaserc.js'];
458
+ files.forEach(async (file) => {
459
+ const templatePath = path__default["default"].join(__dirname, '../templates/', file);
460
+ const newPath = path__default["default"].join(projectPath, file);
461
+ if (await fs__default["default"].pathExists(newPath)) {
462
+ await fs__default["default"].remove(newPath);
463
+ }
464
+ await fs__default["default"].copyFile(templatePath, newPath);
465
+ });
466
+ const pkgPath = path__default["default"].join(projectPath, 'package.json');
467
+ const pkg = await fs__default["default"].readJSON(pkgPath);
468
+ const devDependencies = {
469
+ '@semantic-release/changelog': '^6.0.1',
470
+ '@semantic-release/git': '^10.0.1',
471
+ 'conventional-changelog-cli': '^2.1.1',
472
+ 'conventional-changelog-cmyr-config': `^${await getNpmPackageVersion('conventional-changelog-cmyr-config')}`,
473
+ 'semantic-release': '^18.0.1',
474
+ };
475
+ const pkgData = {
476
+ scripts: {
477
+ release: 'semantic-release',
478
+ ...pkg === null || pkg === void 0 ? void 0 : pkg.scripts,
479
+ },
480
+ devDependencies: {
481
+ ...devDependencies,
482
+ ...pkg === null || pkg === void 0 ? void 0 : pkg.devDependencies,
483
+ },
484
+ };
485
+ const newPkg = Object.assign({}, pkg, pkgData);
486
+ await fs__default["default"].writeFile(pkgPath, JSON.stringify(newPkg, null, 2));
487
+ loading.succeed('semantic-release 初始化成功!');
488
+ }
489
+ catch (error) {
490
+ loading.fail('semantic-release 初始化失败!');
491
+ console.error(error);
492
+ }
493
+ }
494
+ async function initHusky(projectPath, projectInfos) {
495
+ var _a, _b;
496
+ const loading = ora__default["default"]('正在初始化 husky ……').start();
497
+ try {
498
+ const files = ['.husky/commit-msg', '.husky/pre-commit'];
499
+ const dir = path__default["default"].join(projectPath, '.husky');
500
+ if (!await fs__default["default"].pathExists(dir)) {
501
+ await fs__default["default"].mkdirp(dir);
502
+ }
503
+ files.forEach(async (file) => {
504
+ const templatePath = path__default["default"].join(__dirname, '../templates/', file);
505
+ const newPath = path__default["default"].join(projectPath, file);
506
+ if (await fs__default["default"].pathExists(newPath)) {
507
+ await fs__default["default"].remove(newPath);
508
+ }
509
+ await fs__default["default"].copyFile(templatePath, newPath);
510
+ });
511
+ const extnames = ['js', 'ts'];
512
+ const pkgPath = path__default["default"].join(projectPath, 'package.json');
513
+ const pkg = await fs__default["default"].readJSON(pkgPath);
514
+ if ((_a = pkg === null || pkg === void 0 ? void 0 : pkg.dependencies) === null || _a === void 0 ? void 0 : _a.vue) {
515
+ extnames.push('vue');
516
+ }
517
+ if ((_b = pkg === null || pkg === void 0 ? void 0 : pkg.dependencies) === null || _b === void 0 ? void 0 : _b.react) {
518
+ extnames.push('jsx', 'tsx');
519
+ }
520
+ const keyname = `*.{${extnames.join(',')}}`;
521
+ const devDependencies = {
522
+ '@commitlint/cli': '^15.0.0',
523
+ '@commitlint/config-conventional': '^15.0.0',
524
+ commitizen: '^4.2.3',
525
+ 'cz-conventional-changelog': '^3.3.0',
526
+ husky: '^7.0.4',
527
+ 'lint-staged': '^12.1.2',
528
+ };
529
+ const pkgData = {
530
+ scripts: {
531
+ commit: 'cz',
532
+ ...pkg === null || pkg === void 0 ? void 0 : pkg.scripts,
533
+ prepare: 'husky install',
534
+ },
535
+ devDependencies: {
536
+ ...devDependencies,
537
+ ...pkg === null || pkg === void 0 ? void 0 : pkg.devDependencies,
538
+ },
539
+ husky: undefined,
540
+ config: {
541
+ commitizen: {
542
+ path: 'cz-conventional-changelog',
543
+ },
544
+ },
545
+ 'lint-staged': {
546
+ [keyname]: [
547
+ 'npm run lint',
548
+ 'git add',
549
+ ],
550
+ },
551
+ };
552
+ const newPkg = Object.assign({}, pkg, pkgData);
553
+ await fs__default["default"].writeFile(pkgPath, JSON.stringify(newPkg, null, 2));
554
+ loading.succeed('husky 初始化成功!');
555
+ }
556
+ catch (error) {
557
+ loading.fail('husky 初始化失败!');
558
+ console.error(error);
559
+ }
560
+ }
298
561
  async function getAuthorWebsiteFromGithubAPI(githubUsername) {
299
562
  try {
300
563
  const userData = (await axios__default["default"].get(`${GITHUB_API_URL}/users/${githubUsername}`)).data;
@@ -306,6 +569,22 @@ async function getAuthorWebsiteFromGithubAPI(githubUsername) {
306
569
  return '';
307
570
  }
308
571
  }
572
+ async function getLtsNodeVersion() {
573
+ var _a, _b;
574
+ try {
575
+ const html = (await axios__default["default"].get(NODEJS_URL)).data;
576
+ const version = (_a = html.match(/<strong>(.*)<\/strong>/)) === null || _a === void 0 ? void 0 : _a[1];
577
+ return (_b = version.split('.')) === null || _b === void 0 ? void 0 : _b[0];
578
+ }
579
+ catch (error) {
580
+ console.error(error);
581
+ return '';
582
+ }
583
+ }
584
+ async function getNpmPackageVersion(name) {
585
+ const version = (await asyncExec(`${PACKAGE_MANAGER} view ${name} version`)) || '';
586
+ return version.trim();
587
+ }
309
588
  function lintMd(markdown) {
310
589
  const rules = {
311
590
  'no-empty-code': 0,
@@ -319,13 +598,7 @@ function lintMd(markdown) {
319
598
  }
320
599
 
321
600
  module.exports = function (plop) {
322
- plop.setActionType('initProject', async (answers) => {
323
- const { name, template } = answers;
324
- const projectPath = path__default["default"].join(process.cwd(), name);
325
- await downloadGitRepo(`CaoMeiYouRen/${template}`, projectPath);
326
- await init(projectPath, answers);
327
- return '- 下载项目模板成功!';
328
- });
601
+ plop.setActionType('initProject', initProject);
329
602
  plop.setGenerator('create', {
330
603
  description: '草梅项目创建器',
331
604
  async prompts(inquirer) {
@@ -424,6 +697,30 @@ module.exports = function (plop) {
424
697
  return answers.isOpenSource;
425
698
  },
426
699
  },
700
+ {
701
+ type: 'confirm',
702
+ name: 'isInitSemanticRelease',
703
+ message: '是否初始化 semantic-release?',
704
+ default(answers) {
705
+ const { isPublishToNpm } = answers;
706
+ return isPublishToNpm;
707
+ },
708
+ when(answers) {
709
+ return answers.isOpenSource;
710
+ },
711
+ },
712
+ {
713
+ type: 'confirm',
714
+ name: 'isInitHusky',
715
+ message: '是否初始化 husky?',
716
+ default(answers) {
717
+ const { isPublishToNpm } = answers;
718
+ return isPublishToNpm;
719
+ },
720
+ when(answers) {
721
+ return answers.isOpenSource;
722
+ },
723
+ },
427
724
  {
428
725
  type: 'confirm',
429
726
  name: 'isInitReadme',
@@ -433,6 +730,18 @@ module.exports = function (plop) {
433
730
  return answers.isOpenSource;
434
731
  },
435
732
  },
733
+ {
734
+ type: 'confirm',
735
+ name: 'isInitContributing',
736
+ message: '是否初始化 贡献指南(CONTRIBUTING.md) ?',
737
+ default(answers) {
738
+ const { isPublishToNpm } = answers;
739
+ return isPublishToNpm;
740
+ },
741
+ when(answers) {
742
+ return answers.isOpenSource;
743
+ },
744
+ },
436
745
  {
437
746
  type: 'confirm',
438
747
  name: 'isRemoveDependabot',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cmyr-template-cli",
3
- "version": "1.5.2",
3
+ "version": "1.7.2",
4
4
  "description": "草梅友仁自制的项目模板创建器",
5
5
  "author": "CaoMeiYouRen",
6
6
  "license": "MIT",
@@ -43,7 +43,7 @@
43
43
  "@types/ejs": "^3.1.0",
44
44
  "@types/fs-extra": "^9.0.4",
45
45
  "@types/lodash": "^4.14.165",
46
- "@types/node": "^16.9.6",
46
+ "@types/node": "^17.0.0",
47
47
  "@types/promise.any": "^2.0.0",
48
48
  "@typescript-eslint/eslint-plugin": "^4.9.0",
49
49
  "@typescript-eslint/parser": "^4.9.0",
@@ -0,0 +1,26 @@
1
+ # http://editorconfig.org
2
+ #启用编辑器配置
3
+ root = true
4
+ # 对所有文件生效
5
+ [*]
6
+ #编码方式
7
+ charset = utf-8
8
+ #缩进格式
9
+ indent_style = space
10
+ indent_size = 4
11
+ #换行符
12
+ end_of_line = lf
13
+ #插入最终换行符
14
+ insert_final_newline = true
15
+ #修剪尾随空格
16
+ trim_trailing_whitespace = true
17
+ # 对后缀名为 md 的文件生效
18
+ [*.md]
19
+ trim_trailing_whitespace = false
20
+ [*.sh]
21
+ #换行符
22
+ end_of_line = lf
23
+ [package.json]
24
+ indent_size = 2
25
+ [*.yml]
26
+ indent_size = 2
@@ -0,0 +1,32 @@
1
+ name: Release
2
+ on:
3
+ push:
4
+ branches:
5
+ - master
6
+ jobs:
7
+ release:
8
+ name: Release
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - uses: actions/checkout@v2
12
+ - name: Setup Node.js environment
13
+ uses: actions/setup-node@v2.1.2
14
+ with:
15
+ node-version: "lts/*"
16
+ cache: "yarn"
17
+ - name: Cache multiple paths
18
+ uses: actions/cache@v2
19
+ with:
20
+ path: |
21
+ ~/.npm
22
+ ~/cache
23
+ !~/cache/exclude
24
+ **/node_modules
25
+ key: npm-${{ runner.os }}-${{ hashFiles('package.json') }}
26
+ - run: yarn
27
+ - run: npm run lint
28
+ - run: npm run build
29
+ - env:
30
+ GH_TOKEN: ${{ secrets.GH_TOKEN }}
31
+ NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
32
+ run: npm run release
@@ -0,0 +1,25 @@
1
+ name: Test
2
+ on: [push, pull_request]
3
+ jobs:
4
+ test:
5
+ name: Test
6
+ runs-on: ubuntu-latest
7
+ steps:
8
+ - uses: actions/checkout@v2
9
+ - name: Setup Node.js@lts environment
10
+ uses: actions/setup-node@v2
11
+ with:
12
+ node-version: "lts/*"
13
+ cache: "yarn"
14
+ - name: Cache multiple paths
15
+ uses: actions/cache@v2
16
+ with:
17
+ path: |
18
+ ~/.npm
19
+ ~/cache
20
+ !~/cache/exclude
21
+ **/node_modules
22
+ key: npm-${{ runner.os }}-${{ hashFiles('package.json') }}
23
+ - run: yarn
24
+ - run: npm run lint
25
+ - run: npm run build
@@ -0,0 +1,4 @@
1
+ #!/bin/sh
2
+ . "$(dirname "$0")/_/husky.sh"
3
+
4
+ npx --no-install commitlint --edit "$1"
@@ -0,0 +1,4 @@
1
+ #!/bin/sh
2
+ . "$(dirname "$0")/_/husky.sh"
3
+
4
+ npx --no-install lint-staged
@@ -0,0 +1,34 @@
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
+ ["@semantic-release/release-notes-generator",
11
+ {
12
+ "config": "conventional-changelog-cmyr-config"
13
+ }],
14
+ [
15
+ "@semantic-release/changelog",
16
+ {
17
+ "changelogFile": "CHANGELOG.md",
18
+ "changelogTitle": "# " + name
19
+ }
20
+ ],
21
+ '@semantic-release/npm',
22
+ '@semantic-release/github',
23
+ [
24
+ "@semantic-release/git",
25
+ {
26
+ "assets": [
27
+ "src",
28
+ "CHANGELOG.md",
29
+ "package.json"
30
+ ]
31
+ }
32
+ ]
33
+ ]
34
+ }
@@ -0,0 +1,77 @@
1
+ # 贡献指南
2
+
3
+ 在为此存储库做出贡献时,请首先通过 issue、电子邮件或任何其他方法与此存储库的所有者讨论您希望进行的更改,然后再进行更改。
4
+
5
+ ## 开发环境设置
6
+
7
+ 要设置开发环境,请按照以下步骤操作:
8
+
9
+ 1. Clone 本项目
10
+
11
+ ```sh
12
+ git clone <%= repositoryUrl %>.git
13
+ ```
14
+
15
+ 2. 安装依赖
16
+
17
+ ```sh
18
+ npm i
19
+ # 或 yarn
20
+ # 或 pnpm i
21
+ ```
22
+ <% if (devCommand) { -%>
23
+ 3. 运行开发环境
24
+
25
+ ```sh
26
+ <%= devCommand %>
27
+ ```
28
+ <% } -%>
29
+
30
+ ## 问题和功能请求
31
+
32
+ 你在源代码中发现了一个错误,文档中有一个错误,或者你想要一个新功能? 看看[GitHub 讨论](<%= discussionsUrl %>)看看它是否已经在讨论中。您可以通过[在 GitHub 上提交问题](<%= issuesUrl %>)来帮助我们。在创建问题之前,请确保搜索问题存档 - 您的问题可能已经得到解决!
33
+
34
+ 请尝试创建以下错误报告:
35
+
36
+ - *可重现*。包括重现问题的步骤。
37
+ - *具体的*。包括尽可能多的细节:哪个版本,什么环境等。
38
+ - *独特的*。不要复制现有的已打开问题。
39
+ - *范围仅限于单个错误*。每个报告一个错误。
40
+
41
+ **更好的是:提交带有修复或新功能的 Pull Requests!**
42
+
43
+ ### 如何提交拉取请求
44
+
45
+ 1. 在我们的存储库中搜索 与您的提交相关的开放或关闭的 [Pull Requests](<%= pullRequestsUrl %>)。你不想重复努力。
46
+
47
+ 2. Fork 本项目
48
+
49
+ 3. 创建您的功能分支 ( `git checkout -b feat/your_feature`)
50
+
51
+ 4. 提交您的更改
52
+
53
+ 本项目使用 [约定式提交](https://www.conventionalcommits.org/zh-hans/v1.0.0/),因此请遵循提交消息中的规范。
54
+
55
+ git commit 将用于自动化生成日志,所以请勿直接提交 git commit。
56
+
57
+ 非常建议使用 [commitizen](https://github.com/commitizen/cz-cli) 工具来生成 git commit,使用 husky 约束 git commit
58
+
59
+ ```sh
60
+ git add .
61
+ git cz # 使用 commitizen 提交!
62
+ git pull # 请合并最新代码并解决冲突后提交!
63
+ #请勿直接提交git commit
64
+ #若觉得修改太多也可分开提交。先 git add 一部分,执行 git cz 提交后再提交另外一部分
65
+ ```
66
+
67
+ 关于选项,参考 [semantic-release](https://github.com/semantic-release/semantic-release) 的文档
68
+
69
+ - 若为 BUG 修复,则选择 `fix`
70
+ - 若为新增功能,则选择 `feat`
71
+ - 若为移除某些功能,则选择 `perf` 或填写 `BREAKING CHANGE`
72
+ - `perf` 和其他破坏性更新,若不是为了修复 BUG,原则上将拒绝该 PR
73
+
74
+
75
+ 5. 推送到分支 ( `git push origin feat/your_feature`)
76
+
77
+ 6. [打开一个新的 Pull Request](<%= repositoryUrl %>/compare?expand=1)
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) <%= currentYear %> <%= authorName %>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -8,6 +8,11 @@
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) { -%>
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
+ <% } -%>
11
16
  <% if (projectPrerequisites) { -%>
12
17
  <% projectPrerequisites.map(({ name, value }) => { -%>
13
18
  <img src="https://img.shields.io/badge/<%= name %>-<%= encodeURIComponent(value) %>-blue.svg" />
@@ -123,7 +128,7 @@
123
128
 
124
129
  ## 🤝贡献
125
130
 
126
- 欢迎 Contributions, issues and feature!<br />如有问题请查看 [issues page](<%= issuesUrl %>). <%= contributingUrl ? `您还可以查看[contributing guide](${contributingUrl}).` : '' %>
131
+ 欢迎 贡献、提问或提出新功能!<br />如有问题请查看 [issues page](<%= issuesUrl %>). <br/><%= contributingUrl ? `贡献或提出新功能可以查看[contributing guide](${contributingUrl}).` : '' %>
127
132
  <% } -%>
128
133
 
129
134
  ## 支持
@@ -0,0 +1,20 @@
1
+ module.exports = {
2
+ extends: ['@commitlint/config-conventional'],
3
+ rules: {
4
+ 'type-enum': [2, 'always', [
5
+ 'feat',
6
+ 'fix',
7
+ 'docs',
8
+ 'style',
9
+ 'refactor',
10
+ 'perf',
11
+ 'test',
12
+ 'build',
13
+ 'ci',
14
+ 'chore',
15
+ 'revert',
16
+ ]],
17
+ 'subject-full-stop': [0, 'never'],
18
+ 'subject-case': [0, 'never'],
19
+ },
20
+ }