cmyr-template-cli 1.5.2 → 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 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.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
@@ -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);
@@ -105,7 +107,7 @@ async function asyncExec(cmd, options) {
105
107
  });
106
108
  }
107
109
  async function init(projectPath, answers) {
108
- const { isOpenSource, isRemoveDependabot, gitRemoteUrl } = answers;
110
+ const { isOpenSource, isRemoveDependabot, gitRemoteUrl, isInitReadme, isInitContributing } = answers;
109
111
  try {
110
112
  await asyncExec('git --version', {
111
113
  cwd: projectPath,
@@ -134,7 +136,15 @@ async function init(projectPath, answers) {
134
136
  }
135
137
  await initProjectJson(projectPath, answers);
136
138
  if (isOpenSource) {
137
- await initReadme(projectPath, answers);
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
+ }
138
148
  }
139
149
  await asyncExec('git add .', {
140
150
  cwd: projectPath,
@@ -172,6 +182,8 @@ async function initProjectJson(projectPath, answers) {
172
182
  const homepage = `${repositoryUrl}#readme`;
173
183
  const issuesUrl = `${repositoryUrl}/issues`;
174
184
  const gitUrl = `git+${repositoryUrl}.git`;
185
+ const nodeVersion = await getLtsNodeVersion() || '12';
186
+ const node = Number(nodeVersion) - 4;
175
187
  const pkgPath = path__default["default"].join(projectPath, 'package.json');
176
188
  const pkg = await fs__default["default"].readJSON(pkgPath);
177
189
  const pkgData = {
@@ -181,7 +193,7 @@ async function initProjectJson(projectPath, answers) {
181
193
  private: !isPublishToNpm,
182
194
  license: 'UNLICENSED',
183
195
  engines: {
184
- node: '>=12',
196
+ node: `>=${node}`,
185
197
  },
186
198
  };
187
199
  let extData = {};
@@ -208,15 +220,12 @@ async function initProjectJson(projectPath, answers) {
208
220
  }
209
221
  }
210
222
  const cleanText = (text) => text.replace(/-/g, '--').replace(/_/g, '__');
211
- async function initReadme(projectPath, answers) {
223
+ async function getProjectInfo(projectPath, answers) {
212
224
  var _a, _b, _c, _d, _e;
213
- const loading = ora__default["default"]('正在初始化 README.md ……').start();
225
+ const loading = ora__default["default"]('正在获取项目信息 ……').start();
214
226
  try {
215
227
  const { name, author, description, isOpenSource, isPublishToNpm } = answers;
216
228
  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
229
  const pkgPath = path__default["default"].join(projectPath, 'package.json');
221
230
  const pkg = await fs__default["default"].readJSON(pkgPath);
222
231
  const engines = (pkg === null || pkg === void 0 ? void 0 : pkg.engines) || {};
@@ -235,10 +244,11 @@ async function initReadme(projectPath, answers) {
235
244
  const demoUrl = `${repositoryUrl}#readme`;
236
245
  const homepage = documentationUrl;
237
246
  const githubUsername = author;
238
- const authorWebsite = isOpenSource ? await getAuthorWebsiteFromGithubAPI(githubUsername) : '';
247
+ const authorWebsite = await getAuthorWebsiteFromGithubAPI(githubUsername);
239
248
  const licenseUrl = `${repositoryUrl}/blob/master/LICENSE`;
249
+ const discussionsUrl = `${repositoryUrl}/discussions`;
250
+ const pullRequestsUrl = `${repositoryUrl}/pulls`;
240
251
  const projectInfos = {
241
- filename: templatePath,
242
252
  currentYear: new Date().getFullYear(),
243
253
  name,
244
254
  description,
@@ -279,7 +289,24 @@ async function initReadme(projectPath, answers) {
279
289
  name: key,
280
290
  value: engines[key],
281
291
  })),
292
+ discussionsUrl,
293
+ pullRequestsUrl,
282
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');
283
310
  const readmeContent = await ejs__default["default"].render(template, projectInfos, {
284
311
  debug: false,
285
312
  async: true,
@@ -295,6 +322,27 @@ async function initReadme(projectPath, answers) {
295
322
  console.error(error);
296
323
  }
297
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
+ }
298
346
  async function getAuthorWebsiteFromGithubAPI(githubUsername) {
299
347
  try {
300
348
  const userData = (await axios__default["default"].get(`${GITHUB_API_URL}/users/${githubUsername}`)).data;
@@ -306,6 +354,18 @@ async function getAuthorWebsiteFromGithubAPI(githubUsername) {
306
354
  return '';
307
355
  }
308
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
+ }
309
369
  function lintMd(markdown) {
310
370
  const rules = {
311
371
  'no-empty-code': 0,
@@ -433,6 +493,15 @@ module.exports = function (plop) {
433
493
  return answers.isOpenSource;
434
494
  },
435
495
  },
496
+ {
497
+ type: 'confirm',
498
+ name: 'isInitContributing',
499
+ message: '是否初始化 贡献指南(CONTRIBUTING.md) ?',
500
+ default: true,
501
+ when(answers) {
502
+ return answers.isOpenSource;
503
+ },
504
+ },
436
505
  {
437
506
  type: 'confirm',
438
507
  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.6.0",
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,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)
@@ -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
  ## 支持