cmyr-template-cli 1.25.3 → 1.26.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
@@ -51,15 +51,7 @@ const PACKAGE_MANAGER = 'pnpm';
51
51
 
52
52
  const TEMPLATES_META_LIST = [
53
53
  {
54
- name: 'vite4-template',
55
- language: 'vue',
56
- runtime: 'browser',
57
- vueVersion: 3,
58
- docker: false,
59
- priority: 0,
60
- },
61
- {
62
- name: 'vite3-template',
54
+ name: 'vite-latest-template',
63
55
  language: 'vue',
64
56
  runtime: 'browser',
65
57
  vueVersion: 3,
@@ -74,14 +66,6 @@ const TEMPLATES_META_LIST = [
74
66
  docker: false,
75
67
  priority: 0,
76
68
  },
77
- {
78
- name: 'vite2-template',
79
- language: 'vue',
80
- runtime: 'browser',
81
- vueVersion: 3,
82
- docker: false,
83
- priority: 0,
84
- },
85
69
  {
86
70
  name: 'electron-vite-template',
87
71
  language: 'vue',
@@ -214,22 +198,6 @@ const TEMPLATES_META_LIST = [
214
198
  docker: false,
215
199
  priority: 0,
216
200
  },
217
- {
218
- name: 'vue-template',
219
- language: 'vue',
220
- runtime: 'browser',
221
- vueVersion: 2,
222
- docker: false,
223
- priority: 0,
224
- },
225
- {
226
- name: 'vue3-template',
227
- language: 'vue',
228
- runtime: 'browser',
229
- vueVersion: 3,
230
- docker: false,
231
- priority: 0,
232
- },
233
201
  {
234
202
  name: 'python-flask-template',
235
203
  language: 'python',
@@ -533,14 +501,14 @@ async function init(projectPath, answers) {
533
501
  await asyncExec('java -version', {
534
502
  cwd: projectPath,
535
503
  });
536
- await asyncExec('mvn -version', {
504
+ await asyncExec('gradle -v', {
537
505
  cwd: projectPath,
538
506
  });
539
507
  await asyncExec('git add .', {
540
508
  cwd: projectPath,
541
509
  });
542
510
  try {
543
- await asyncExec('mvn dependency:go-offline -B -Dmaven.test.skip=true', {
511
+ await asyncExec('gradle dependencies --no-daemon', {
544
512
  cwd: projectPath,
545
513
  });
546
514
  }
@@ -880,6 +848,7 @@ async function getProjectInfo(projectPath, answers) {
880
848
  const testCommand = ((_d = pkg === null || pkg === void 0 ? void 0 : pkg.scripts) === null || _d === void 0 ? void 0 : _d.test) && `${packageManager} run test`;
881
849
  const lintCommand = ((_e = pkg === null || pkg === void 0 ? void 0 : pkg.scripts) === null || _e === void 0 ? void 0 : _e.lint) && `${packageManager} run lint`;
882
850
  const commitCommand = ((_f = pkg === null || pkg === void 0 ? void 0 : pkg.scripts) === null || _f === void 0 ? void 0 : _f.commit) && `${packageManager} run commit`;
851
+ const mainFile = pkg === null || pkg === void 0 ? void 0 : pkg.main;
883
852
  const githubUsername = (config === null || config === void 0 ? void 0 : config.GITHUB_USERNAME) || author;
884
853
  const giteeUsername = config === null || config === void 0 ? void 0 : config.GITEE_USERNAME;
885
854
  const weiboUsername = config === null || config === void 0 ? void 0 : config.WEIBO_USERNAME;
@@ -953,6 +922,7 @@ async function getProjectInfo(projectPath, answers) {
953
922
  twitterUsername,
954
923
  npmUsername,
955
924
  templateMeta,
925
+ mainFile,
956
926
  };
957
927
  loading.succeed('项目信息 初始化成功!');
958
928
  return projectInfos;
@@ -1306,33 +1276,45 @@ async function initDocker(projectPath, answers) {
1306
1276
  const templateMeta = getTemplateMeta(answers.template);
1307
1277
  const files = ['.dockerignore', 'docker-compose.yml'];
1308
1278
  await copyFilesFromTemplates(projectPath, files);
1309
- let dockerfilePath = 'Dockerfile';
1279
+ let dockerfile = 'Dockerfile';
1280
+ const newPath = path__default["default"].join(projectPath, 'Dockerfile');
1281
+ if (await fs__default["default"].pathExists(newPath)) {
1282
+ await fs__default["default"].remove(newPath);
1283
+ }
1284
+ if ((templateMeta === null || templateMeta === void 0 ? void 0 : templateMeta.runtime) === 'java') {
1285
+ const templatePath = path__default["default"].join(__dirname, '../templates/java/Dockerfile.ejs');
1286
+ await ejsRender(templatePath, { javaVersion: templateMeta === null || templateMeta === void 0 ? void 0 : templateMeta.javaVersion }, newPath);
1287
+ loading.succeed('Docker 初始化成功!');
1288
+ return;
1289
+ }
1290
+ if ((templateMeta === null || templateMeta === void 0 ? void 0 : templateMeta.runtime) === 'nodejs') {
1291
+ if ((templateMeta === null || templateMeta === void 0 ? void 0 : templateMeta.runtime) === 'nodejs') {
1292
+ const scriptsDir = path__default["default"].join(projectPath, 'scripts');
1293
+ if (!await fs__default["default"].pathExists(scriptsDir)) {
1294
+ await fs__default["default"].mkdir(scriptsDir);
1295
+ }
1296
+ await copyFilesFromTemplates(projectPath, ['scripts/minify-docker.js']);
1297
+ }
1298
+ const pkg = await getProjectJson(projectPath);
1299
+ const mainFile = pkg === null || pkg === void 0 ? void 0 : pkg.main;
1300
+ const templatePath = path__default["default"].join(__dirname, '../templates/Dockerfile');
1301
+ await ejsRender(templatePath, { mainFile }, newPath);
1302
+ loading.succeed('Docker 初始化成功!');
1303
+ return;
1304
+ }
1310
1305
  switch (templateMeta === null || templateMeta === void 0 ? void 0 : templateMeta.runtime) {
1311
- case 'java':
1312
- dockerfilePath = (templateMeta === null || templateMeta === void 0 ? void 0 : templateMeta.javaVersion) === 8 ? 'java/jdk8/Dockerfile' : 'java/jdk17/Dockerfile';
1313
- break;
1314
1306
  case 'python':
1315
- dockerfilePath = 'python/Dockerfile';
1307
+ dockerfile = 'python/Dockerfile';
1316
1308
  break;
1317
1309
  case 'golang':
1318
- dockerfilePath = 'golang/Dockerfile';
1310
+ dockerfile = 'golang/Dockerfile';
1319
1311
  break;
1320
1312
  default:
1321
- dockerfilePath = 'Dockerfile';
1313
+ dockerfile = 'Dockerfile';
1322
1314
  break;
1323
1315
  }
1324
- const newPath = path__default["default"].join(projectPath, 'Dockerfile');
1325
- if (await fs__default["default"].pathExists(newPath)) {
1326
- await fs__default["default"].remove(newPath);
1327
- }
1328
- await fs__default["default"].copyFile(path__default["default"].join(__dirname, '../templates/', dockerfilePath), newPath);
1329
- if ((templateMeta === null || templateMeta === void 0 ? void 0 : templateMeta.runtime) === 'nodejs') {
1330
- const scriptsDir = path__default["default"].join(projectPath, 'scripts');
1331
- if (!await fs__default["default"].pathExists(scriptsDir)) {
1332
- await fs__default["default"].mkdir(scriptsDir);
1333
- }
1334
- await copyFilesFromTemplates(projectPath, ['scripts/minify-docker.js']);
1335
- }
1316
+ const dockerfilePath = path__default["default"].join(__dirname, '../templates/', dockerfile);
1317
+ await fs__default["default"].copyFile(dockerfilePath, newPath);
1336
1318
  loading.succeed('Docker 初始化成功!');
1337
1319
  }
1338
1320
  catch (error) {
@@ -1490,6 +1472,14 @@ function kebabCase(str) {
1490
1472
  function getTemplateMeta(template) {
1491
1473
  return TEMPLATES_META_LIST.find((e) => e.name === template);
1492
1474
  }
1475
+ async function ejsRender(templatePath, data, outputPath) {
1476
+ const template = (await fs__default["default"].readFile(templatePath, 'utf8')).toString();
1477
+ const content = await ejs__default["default"].render(template, data, {
1478
+ debug: false,
1479
+ async: true,
1480
+ });
1481
+ await fs__default["default"].writeFile(outputPath, content);
1482
+ }
1493
1483
 
1494
1484
  module.exports = function (plop) {
1495
1485
  plop.setActionType('initProject', initProject);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cmyr-template-cli",
3
- "version": "1.25.3",
3
+ "version": "1.26.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.15.0",
50
- "@typescript-eslint/parser": "6.15.0",
49
+ "@typescript-eslint/eslint-plugin": "6.17.0",
50
+ "@typescript-eslint/parser": "6.16.0",
51
51
  "commitizen": "^4.2.2",
52
52
  "conventional-changelog-cli": "^4.0.0",
53
53
  "conventional-changelog-cmyr-config": "^2.1.1",
@@ -37,5 +37,4 @@ COPY --from=docker-minifier /home/app /home/app
37
37
 
38
38
  EXPOSE 3000
39
39
 
40
- CMD ["node", "dist/main.js"]
41
- # CMD ["node", "dist/index.js"]
40
+ CMD ["node", "<%= mainFile %>"]
@@ -0,0 +1,28 @@
1
+ # 阶段一:安装依赖
2
+ FROM gradle:8.5.0-jdk<%= javaVersion %> as dependencies
3
+
4
+ WORKDIR /home/app
5
+
6
+ COPY build.gradle /home/app/build.gradle
7
+
8
+ # 只安装依赖,跳过测试
9
+ RUN gradle -v && gradle dependencies --no-daemon
10
+
11
+ # 阶段二:构建阶段
12
+ FROM dependencies as builder
13
+
14
+ COPY . /home/app
15
+
16
+ # 构建
17
+ RUN gradle clean build --no-daemon
18
+
19
+ # 阶段三:生产阶段
20
+ FROM eclipse-temurin:<%= javaVersion %>-jre-alpine
21
+
22
+ WORKDIR /home/app
23
+
24
+ COPY --from=builder /home/app/build/libs/main.jar /home/app
25
+
26
+ EXPOSE 8080
27
+
28
+ CMD ["java", "-jar", "main.jar"]
@@ -1,33 +0,0 @@
1
- # 阶段一:安装依赖
2
- FROM maven:3-eclipse-temurin-17-alpine as dependencies
3
-
4
- WORKDIR /home/app
5
-
6
- RUN java -version && mvn -version && \
7
- echo '<?xml version="1.0" encoding="UTF-8"?><settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"><mirrors><mirror><id>alimaven</id><mirrorOf>central</mirrorOf><name>aliyun maven</name><url>https://maven.aliyun.com/repository/public/</url></mirror></mirrors></settings>' > /usr/share/maven/conf/settings.xml
8
-
9
- COPY pom.xml /home/app/pom.xml
10
-
11
- # 只安装依赖,跳过测试
12
- RUN mvn dependency:go-offline -B -Dmaven.test.skip=true
13
-
14
- # 阶段二:构建阶段
15
- FROM dependencies as builder
16
-
17
- COPY . /home/app
18
-
19
- # 构建
20
- RUN mvn clean package -Dmaven.test.skip=true
21
-
22
- # 阶段三:生产阶段
23
- FROM eclipse-temurin:17-jre-alpine
24
-
25
- WORKDIR /home/app
26
-
27
- RUN java -version
28
-
29
- COPY --from=builder /home/app/target/main.jar /home/app
30
-
31
- EXPOSE 8080
32
-
33
- CMD ["java", "-jar", "main.jar"]
@@ -1,33 +0,0 @@
1
- # 阶段一:安装依赖
2
- FROM maven:3-eclipse-temurin-8-alpine as dependencies
3
-
4
- WORKDIR /home/app
5
-
6
- RUN java -version && mvn -version && \
7
- echo '<?xml version="1.0" encoding="UTF-8"?><settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"><mirrors><mirror><id>alimaven</id><mirrorOf>central</mirrorOf><name>aliyun maven</name><url>https://maven.aliyun.com/repository/public/</url></mirror></mirrors></settings>' > /usr/share/maven/conf/settings.xml
8
-
9
- COPY pom.xml /home/app/pom.xml
10
-
11
- # 只安装依赖,跳过测试
12
- RUN mvn dependency:go-offline -B -Dmaven.test.skip=true
13
-
14
- # 阶段二:构建阶段
15
- FROM dependencies as builder
16
-
17
- COPY . /home/app
18
-
19
- # 构建
20
- RUN mvn clean package -Dmaven.test.skip=true
21
-
22
- # 阶段三:生产阶段
23
- FROM eclipse-temurin:8-jre-alpine
24
-
25
- WORKDIR /home/app
26
-
27
- RUN java -version
28
-
29
- COPY --from=builder /home/app/target/main.jar /home/app
30
-
31
- EXPOSE 8080
32
-
33
- CMD ["java", "-jar", "main.jar"]