cmyr-template-cli 1.21.2 → 1.22.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/plopfile.js CHANGED
@@ -47,6 +47,204 @@ var os__default = /*#__PURE__*/_interopDefaultLegacy(os);
47
47
  process.env;
48
48
  const PACKAGE_MANAGER = 'pnpm';
49
49
 
50
+ const TEMPLATES_META_LIST = [
51
+ {
52
+ name: 'vite4-template',
53
+ language: 'vue',
54
+ runtime: 'browser',
55
+ vueVersion: 3,
56
+ docker: false,
57
+ priority: 0,
58
+ },
59
+ {
60
+ name: 'vite3-template',
61
+ language: 'vue',
62
+ runtime: 'browser',
63
+ vueVersion: 3,
64
+ docker: false,
65
+ priority: 0,
66
+ },
67
+ {
68
+ name: 'vite2-vue2-template',
69
+ language: 'vue',
70
+ runtime: 'browser',
71
+ vueVersion: 2,
72
+ docker: false,
73
+ priority: 0,
74
+ },
75
+ {
76
+ name: 'vite2-template',
77
+ language: 'vue',
78
+ runtime: 'browser',
79
+ vueVersion: 3,
80
+ docker: false,
81
+ priority: 0,
82
+ },
83
+ {
84
+ name: 'electron-vite-template',
85
+ language: 'vue',
86
+ runtime: 'browser',
87
+ vueVersion: 3,
88
+ docker: false,
89
+ priority: 0,
90
+ },
91
+ {
92
+ name: 'electron-vue-template',
93
+ language: 'vue',
94
+ runtime: 'browser',
95
+ vueVersion: 3,
96
+ docker: false,
97
+ priority: 0,
98
+ },
99
+ {
100
+ name: 'nuxt-template',
101
+ language: 'vue',
102
+ runtime: 'browser',
103
+ vueVersion: 2,
104
+ docker: false,
105
+ priority: 0,
106
+ },
107
+ {
108
+ name: 'uni-template',
109
+ language: 'vue',
110
+ runtime: 'browser',
111
+ vueVersion: 2,
112
+ docker: false,
113
+ priority: 0,
114
+ },
115
+ {
116
+ name: 'uni-vite2-template',
117
+ language: 'vue',
118
+ runtime: 'browser',
119
+ vueVersion: 3,
120
+ docker: false,
121
+ priority: 0,
122
+ },
123
+ {
124
+ name: 'react-template',
125
+ language: 'react',
126
+ runtime: 'browser',
127
+ vueVersion: 0,
128
+ docker: false,
129
+ priority: 0,
130
+ },
131
+ {
132
+ name: 'react16-template',
133
+ language: 'react',
134
+ runtime: 'browser',
135
+ vueVersion: 0,
136
+ docker: false,
137
+ priority: 0,
138
+ },
139
+ {
140
+ name: 'ts-template',
141
+ language: 'typescript',
142
+ runtime: 'nodejs',
143
+ vueVersion: 0,
144
+ docker: true,
145
+ priority: 0,
146
+ },
147
+ {
148
+ name: 'express-template',
149
+ language: 'typescript',
150
+ runtime: 'nodejs',
151
+ vueVersion: 0,
152
+ docker: true,
153
+ priority: 0,
154
+ },
155
+ {
156
+ name: 'koa2-template',
157
+ language: 'typescript',
158
+ runtime: 'nodejs',
159
+ vueVersion: 0,
160
+ docker: true,
161
+ priority: 0,
162
+ },
163
+ {
164
+ name: 'nest-template',
165
+ language: 'typescript',
166
+ runtime: 'nodejs',
167
+ vueVersion: 0,
168
+ docker: true,
169
+ priority: 0,
170
+ },
171
+ {
172
+ name: 'auto-release-template',
173
+ language: 'typescript',
174
+ runtime: 'nodejs',
175
+ vueVersion: 0,
176
+ docker: false,
177
+ npm: true,
178
+ priority: 0,
179
+ },
180
+ {
181
+ name: 'rollup-template',
182
+ language: 'typescript',
183
+ runtime: 'nodejs',
184
+ vueVersion: 0,
185
+ docker: false,
186
+ npm: true,
187
+ priority: 0,
188
+ },
189
+ {
190
+ name: 'webpack-template',
191
+ language: 'typescript',
192
+ runtime: 'nodejs',
193
+ vueVersion: 0,
194
+ docker: false,
195
+ npm: true,
196
+ priority: 0,
197
+ },
198
+ {
199
+ name: 'github-action-template',
200
+ language: 'typescript',
201
+ runtime: 'nodejs',
202
+ vueVersion: 0,
203
+ docker: false,
204
+ priority: 0,
205
+ },
206
+ {
207
+ name: 'vue-template',
208
+ language: 'vue',
209
+ runtime: 'browser',
210
+ vueVersion: 2,
211
+ docker: false,
212
+ priority: 0,
213
+ },
214
+ {
215
+ name: 'vue3-template',
216
+ language: 'vue',
217
+ runtime: 'browser',
218
+ vueVersion: 3,
219
+ docker: false,
220
+ priority: 0,
221
+ },
222
+ {
223
+ name: 'python-flask-template',
224
+ language: 'python',
225
+ runtime: 'python',
226
+ vueVersion: 0,
227
+ docker: true,
228
+ priority: 0,
229
+ },
230
+ {
231
+ name: 'go-gin-template',
232
+ language: 'golang',
233
+ runtime: 'golang',
234
+ vueVersion: 0,
235
+ docker: true,
236
+ priority: 0,
237
+ },
238
+ {
239
+ name: 'spring-boot-template',
240
+ language: 'java',
241
+ runtime: 'java',
242
+ vueVersion: 0,
243
+ docker: true,
244
+ priority: 0,
245
+ },
246
+ ];
247
+
50
248
  const fix = (markdown, rules) => { var _a, _b; return (_b = (_a = core.lintMarkdown(markdown, rules, true)) === null || _a === void 0 ? void 0 : _a.fixedResult) === null || _b === void 0 ? void 0 : _b.result; };
51
249
  axios__default["default"].defaults.timeout = 10 * 1000;
52
250
  if (!Promise.any) {
@@ -192,16 +390,19 @@ async function downloadGitRepo(repository, destination, options = {}) {
192
390
  const fastRepo = await getFastGitRepo(repository);
193
391
  const loading = ora__default["default"](`正在下载模板 - ${repository}`);
194
392
  loading.start();
195
- return new Promise((resolve) => {
196
- download__default["default"](fastRepo, destination, options, (err) => {
197
- if (err) {
198
- loading.fail('下载模板失败!');
199
- process.exit(1);
200
- }
201
- loading.succeed(`成功下载模板 - ${repository}`);
202
- resolve(true);
203
- });
204
- });
393
+ return Promise.any([
394
+ new Promise((resolve) => {
395
+ download__default["default"](fastRepo, destination, options, (err) => {
396
+ if (err) {
397
+ loading.fail('下载模板失败!');
398
+ process.exit(1);
399
+ }
400
+ loading.succeed(`成功下载模板 - ${repository}`);
401
+ resolve(true);
402
+ });
403
+ }),
404
+ new Promise((resolve, reject) => setTimeout(reject, 60 * 1000)),
405
+ ]);
205
406
  }
206
407
  async function getFastGitRepo(repository) {
207
408
  const loading = ora__default["default"](`正在选择镜像源 - ${repository}`);
@@ -245,62 +446,131 @@ async function initProject(answers) {
245
446
  }
246
447
  async function init(projectPath, answers) {
247
448
  var _a;
248
- const { isOpenSource, isInitReadme, isInitContributing, isInitHusky, isInitSemanticRelease, isInitDocker } = answers;
449
+ const { template, isOpenSource, isInitReadme, isInitContributing, isInitHusky, isInitSemanticRelease, isInitDocker } = answers;
249
450
  try {
451
+ const templateMeta = getTemplateMeta(template);
250
452
  await asyncExec('git --version', {
251
453
  cwd: projectPath,
252
454
  });
253
- await asyncExec(`${PACKAGE_MANAGER} -v`, {
254
- cwd: projectPath,
255
- });
256
455
  await asyncExec('git init', {
257
456
  cwd: projectPath,
258
457
  });
259
- const newPkg = await initProjectJson(projectPath, answers);
260
- await initConfig(projectPath);
261
- await initCommitizen(projectPath);
262
- if (isInitDocker) {
263
- await initDocker(projectPath);
264
- }
265
- if (isOpenSource) {
266
- const info = await getProjectInfo(projectPath, answers);
267
- if (info) {
268
- if (isInitReadme) {
269
- await initReadme(projectPath, info);
270
- }
271
- if (isInitContributing) {
272
- await initContributing(projectPath, info);
458
+ if (['nodejs', 'browser'].includes(templateMeta === null || templateMeta === void 0 ? void 0 : templateMeta.runtime)) {
459
+ await asyncExec('node -v', {
460
+ cwd: projectPath,
461
+ });
462
+ await asyncExec(`${PACKAGE_MANAGER} -v`, {
463
+ cwd: projectPath,
464
+ });
465
+ const newPkg = await initProjectJson(projectPath, answers);
466
+ await initConfig(projectPath);
467
+ await initCommitizen(projectPath);
468
+ if (isOpenSource) {
469
+ const info = await getProjectInfo(projectPath, answers);
470
+ if (info) {
471
+ if (isInitReadme) {
472
+ await initReadme(projectPath, info);
473
+ }
474
+ if (isInitContributing) {
475
+ await initContributing(projectPath, info);
476
+ }
477
+ await initLicense(projectPath, info);
273
478
  }
274
- await initLicense(projectPath, info);
479
+ await initGithubWorkflows(projectPath, answers);
480
+ }
481
+ if (isInitSemanticRelease) {
482
+ await initSemanticRelease(projectPath);
483
+ }
484
+ if (isInitHusky) {
485
+ await initHusky(projectPath);
486
+ }
487
+ await initCommonDependencies(projectPath, answers);
488
+ await initTsconfig(projectPath);
489
+ await initEslint(projectPath);
490
+ await initStylelint(projectPath);
491
+ await sortProjectJson(projectPath);
492
+ await initYarn(projectPath, answers);
493
+ await asyncExec('git add .', {
494
+ cwd: projectPath,
495
+ });
496
+ await installNpmPackages(projectPath);
497
+ await asyncExec('git add .', {
498
+ cwd: projectPath,
499
+ });
500
+ if ((_a = newPkg === null || newPkg === void 0 ? void 0 : newPkg.scripts) === null || _a === void 0 ? void 0 : _a.lint) {
501
+ await asyncExec(`${PACKAGE_MANAGER} run lint`, {
502
+ cwd: projectPath,
503
+ });
275
504
  }
276
- await initGithubWorkflows(projectPath, answers);
277
505
  }
278
- await initRemoteGitRepo(projectPath, answers);
279
- if (isInitSemanticRelease) {
280
- await initSemanticRelease(projectPath);
506
+ if ((templateMeta === null || templateMeta === void 0 ? void 0 : templateMeta.runtime) === 'java') {
507
+ try {
508
+ await asyncExec('java -version', {
509
+ cwd: projectPath,
510
+ });
511
+ }
512
+ catch (error) {
513
+ if (!(typeof error === 'string' && error.includes('java version'))) {
514
+ throw error;
515
+ }
516
+ }
517
+ await asyncExec('mvn -version', {
518
+ cwd: projectPath,
519
+ });
520
+ await asyncExec('git add .', {
521
+ cwd: projectPath,
522
+ });
523
+ try {
524
+ await asyncExec('mvn clean package -Dmaven.test.skip=true', {
525
+ cwd: projectPath,
526
+ });
527
+ }
528
+ catch (error) {
529
+ console.error(error);
530
+ }
281
531
  }
282
- if (isInitHusky) {
283
- await initHusky(projectPath);
532
+ if ((templateMeta === null || templateMeta === void 0 ? void 0 : templateMeta.runtime) === 'python') {
533
+ await asyncExec('python -V', {
534
+ cwd: projectPath,
535
+ });
536
+ await asyncExec('pip -V', {
537
+ cwd: projectPath,
538
+ });
539
+ await asyncExec('git add .', {
540
+ cwd: projectPath,
541
+ });
542
+ try {
543
+ await asyncExec('pip install -r requirements.txt', {
544
+ cwd: projectPath,
545
+ });
546
+ }
547
+ catch (error) {
548
+ if (!(typeof error === 'string' && error.includes('[notice]'))) {
549
+ throw error;
550
+ }
551
+ }
284
552
  }
285
- await initCommonDependencies(projectPath, answers);
286
- await initTsconfig(projectPath);
287
- await initEslint(projectPath);
288
- await initStylelint(projectPath);
289
- await sortProjectJson(projectPath);
290
- await initDependabot(projectPath, answers);
291
- await initYarn(projectPath, answers);
292
- await asyncExec('git add .', {
293
- cwd: projectPath,
294
- });
295
- await installNpmPackages(projectPath);
296
- await asyncExec('git add .', {
297
- cwd: projectPath,
298
- });
299
- if ((_a = newPkg === null || newPkg === void 0 ? void 0 : newPkg.scripts) === null || _a === void 0 ? void 0 : _a.lint) {
300
- await asyncExec(`${PACKAGE_MANAGER} run lint`, {
553
+ if ((templateMeta === null || templateMeta === void 0 ? void 0 : templateMeta.runtime) === 'golang') {
554
+ await asyncExec('go version', {
555
+ cwd: projectPath,
556
+ });
557
+ await asyncExec('git add .', {
301
558
  cwd: projectPath,
302
559
  });
560
+ try {
561
+ await asyncExec('go get', {
562
+ cwd: projectPath,
563
+ });
564
+ }
565
+ catch (error) {
566
+ console.error(error);
567
+ }
568
+ }
569
+ await initRemoteGitRepo(projectPath, answers);
570
+ if (isInitDocker) {
571
+ await initDocker(projectPath, answers);
303
572
  }
573
+ await initDependabot(projectPath, answers);
304
574
  await asyncExec('git add .', {
305
575
  cwd: projectPath,
306
576
  });
@@ -309,7 +579,7 @@ async function init(projectPath, answers) {
309
579
  });
310
580
  }
311
581
  catch (error) {
312
- console.error(error);
582
+ console.error(colors__default["default"].red(error));
313
583
  }
314
584
  }
315
585
  async function getGitUserName() {
@@ -982,11 +1252,31 @@ async function initCommitizen(projectPath) {
982
1252
  loading.fail('commitizen 初始化失败!');
983
1253
  }
984
1254
  }
985
- async function initDocker(projectPath) {
1255
+ async function initDocker(projectPath, answers) {
986
1256
  const loading = ora__default["default"]('正在初始化 Docker ……').start();
987
1257
  try {
1258
+ const templateMeta = getTemplateMeta(answers.template);
988
1259
  const files = ['.dockerignore', 'docker-compose.yml', 'Dockerfile'];
989
1260
  await copyFilesFromTemplates(projectPath, files);
1261
+ let dockerfilePath = '';
1262
+ switch (templateMeta === null || templateMeta === void 0 ? void 0 : templateMeta.runtime) {
1263
+ case 'java':
1264
+ dockerfilePath = 'java/Dockerfile';
1265
+ break;
1266
+ case 'python':
1267
+ dockerfilePath = 'python/Dockerfile';
1268
+ break;
1269
+ case 'golang':
1270
+ dockerfilePath = 'golang/Dockerfile';
1271
+ break;
1272
+ default:
1273
+ break;
1274
+ }
1275
+ const newPath = path__default["default"].join(projectPath, 'Dockerfile');
1276
+ if (await fs__default["default"].pathExists(newPath)) {
1277
+ await fs__default["default"].remove(newPath);
1278
+ }
1279
+ await fs__default["default"].copyFile(path__default["default"].join(__dirname, '../templates/', dockerfilePath), newPath);
990
1280
  loading.succeed('Docker 初始化成功!');
991
1281
  }
992
1282
  catch (error) {
@@ -1141,6 +1431,9 @@ async function removeFiles(projectPath, files) {
1141
1431
  function kebabCase(str) {
1142
1432
  return str.replace(/([a-z])([A-Z])/g, '$1-$2').replace(/_+/g, '-').replace(/\s+/g, '-').toLowerCase();
1143
1433
  }
1434
+ function getTemplateMeta(template) {
1435
+ return TEMPLATES_META_LIST.find((e) => e.name === template);
1436
+ }
1144
1437
 
1145
1438
  module.exports = function (plop) {
1146
1439
  plop.setActionType('initProject', initProject);
@@ -1188,29 +1481,7 @@ module.exports = function (plop) {
1188
1481
  name: 'template',
1189
1482
  message: '请选择项目模板',
1190
1483
  choices() {
1191
- return [
1192
- 'vite4',
1193
- 'vite3',
1194
- 'vite2-vue2',
1195
- 'vite2',
1196
- 'electron-vite',
1197
- 'electron-vue',
1198
- 'nuxt',
1199
- 'uni',
1200
- 'uni-vite2',
1201
- 'react',
1202
- 'react16',
1203
- 'ts',
1204
- 'express',
1205
- 'koa2',
1206
- 'nest',
1207
- 'auto-release',
1208
- 'rollup',
1209
- 'webpack',
1210
- 'github-action',
1211
- 'vue',
1212
- 'vue3',
1213
- ].map((e) => `${e}-template`);
1484
+ return TEMPLATES_META_LIST.map((e) => e.name);
1214
1485
  },
1215
1486
  default: '',
1216
1487
  },
@@ -1220,30 +1491,26 @@ module.exports = function (plop) {
1220
1491
  message: '请选择需要安装的常见依赖',
1221
1492
  default: [],
1222
1493
  choices(answers) {
1494
+ const templateMeta = getTemplateMeta(answers.template);
1223
1495
  const choices = Object.keys(COMMON_DEPENDENCIES.dependencies);
1224
- const nodeList = ['ts',
1225
- 'express',
1226
- 'koa2',
1227
- 'nest',
1228
- 'auto-release',
1229
- 'rollup',
1230
- 'webpack',
1231
- 'github-action'].map((e) => `${e}-template`);
1232
- const vue2List = ['vite2-vue2', 'nuxt', 'uni', 'vue'].map((e) => `${e}-template`);
1233
- if (nodeList.includes(answers.template)) {
1496
+ if ((templateMeta === null || templateMeta === void 0 ? void 0 : templateMeta.runtime) === 'nodejs') {
1234
1497
  choices.push(...Object.keys(NODE_DEPENDENCIES.dependencies));
1235
1498
  }
1236
- if (vue2List.includes(answers.template)) {
1499
+ if ((templateMeta === null || templateMeta === void 0 ? void 0 : templateMeta.runtime) === 'browser') {
1500
+ choices.push(...Object.keys(WEB_DEPENDENCIES.dependencies));
1501
+ }
1502
+ if ((templateMeta === null || templateMeta === void 0 ? void 0 : templateMeta.vueVersion) === 2) {
1237
1503
  choices.push(...Object.keys(VUE2_DEPENDENCIES.dependencies));
1238
1504
  }
1239
- else if (/(vue|vite)/.test(answers.template)) {
1505
+ else if ((templateMeta === null || templateMeta === void 0 ? void 0 : templateMeta.vueVersion) === 3) {
1240
1506
  choices.push(...Object.keys(VUE3_DEPENDENCIES.dependencies));
1241
1507
  }
1242
- if (/(vue|vite|react|nuxt)/.test(answers.template)) {
1243
- choices.push(...Object.keys(WEB_DEPENDENCIES.dependencies));
1244
- }
1245
1508
  return choices;
1246
1509
  },
1510
+ when(answers) {
1511
+ const templateMeta = getTemplateMeta(answers.template);
1512
+ return ['nodejs', 'browser'].includes(templateMeta === null || templateMeta === void 0 ? void 0 : templateMeta.runtime);
1513
+ },
1247
1514
  },
1248
1515
  {
1249
1516
  type: 'confirm',
@@ -1251,11 +1518,8 @@ module.exports = function (plop) {
1251
1518
  message: '是否初始化 Docker?',
1252
1519
  default: false,
1253
1520
  when(answers) {
1254
- return [
1255
- 'express',
1256
- 'koa2',
1257
- 'nest',
1258
- ].map((e) => `${e}-template`).includes(answers.template);
1521
+ const templateMeta = getTemplateMeta(answers.template);
1522
+ return templateMeta === null || templateMeta === void 0 ? void 0 : templateMeta.docker;
1259
1523
  },
1260
1524
  },
1261
1525
  {
@@ -1298,7 +1562,8 @@ module.exports = function (plop) {
1298
1562
  message: '是否发布到 npm?',
1299
1563
  default: false,
1300
1564
  when(answers) {
1301
- return answers.isOpenSource;
1565
+ const templateMeta = getTemplateMeta(answers.template);
1566
+ return answers.isOpenSource && templateMeta.npm;
1302
1567
  },
1303
1568
  },
1304
1569
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cmyr-template-cli",
3
- "version": "1.21.2",
3
+ "version": "1.22.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.7.2",
50
- "@typescript-eslint/parser": "6.7.2",
49
+ "@typescript-eslint/eslint-plugin": "6.7.4",
50
+ "@typescript-eslint/parser": "6.7.4",
51
51
  "commitizen": "^4.2.2",
52
52
  "conventional-changelog-cli": "^4.0.0",
53
53
  "conventional-changelog-cmyr-config": "^2.1.1",
@@ -0,0 +1,9 @@
1
+ FROM scratch
2
+
3
+ WORKDIR /home/app
4
+
5
+ COPY ./main /home/app
6
+
7
+ EXPOSE 8080
8
+
9
+ CMD ["./main"]
@@ -0,0 +1,16 @@
1
+ FROM alpine:latest
2
+
3
+ # 安装java环境
4
+ RUN echo "http://mirrors.aliyun.com/alpine/edge/main/" > /etc/apk/repositories \
5
+ && echo "http://mirrors.aliyun.com/alpine/edge/community/" >> /etc/apk/repositories \
6
+ && apk update \
7
+ && apk add --no-cache --update openjdk8 \
8
+ && java -version
9
+
10
+ WORKDIR /home/app
11
+
12
+ COPY . /home/app
13
+
14
+ EXPOSE 8080
15
+
16
+ CMD ["java", "-jar","./target/main.jar"]
@@ -0,0 +1,27 @@
1
+ FROM alpine:latest
2
+
3
+ # 安装python环境
4
+ RUN echo "http://mirrors.aliyun.com/alpine/edge/main/" > /etc/apk/repositories \
5
+ && echo "http://mirrors.aliyun.com/alpine/edge/community/" >> /etc/apk/repositories \
6
+ && apk update \
7
+ && apk add --no-cache --update python3 py3-pip \
8
+ && python3 -V && pip3 -V \
9
+ && ln -sf /usr/bin/pip3 /usr/bin/pip \
10
+ && mkdir -p ~/.pip \
11
+ && echo "[global]" > ~/.pip/pip.conf \
12
+ && echo "index-url=http://mirrors.cloud.aliyuncs.com/pypi/simple/" >> ~/.pip/pip.conf \
13
+ && echo "[install]" >> ~/.pip/pip.conf \
14
+ && echo "trusted-host=mirrors.cloud.aliyuncs.com" >> ~/.pip/pip.conf \
15
+ && pip install --upgrade pip && pip install wheel
16
+
17
+ WORKDIR /home/app
18
+
19
+ COPY ./requirements.txt /home/app
20
+
21
+ RUN pip install -r requirements.txt
22
+
23
+ COPY . /home/app
24
+
25
+ EXPOSE 8080
26
+
27
+ CMD ["gunicorn", "app:app", "-p", "app.pid", "-b", "0.0.0.0:8080"]