cmyr-template-cli 1.28.10 → 1.29.1

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
@@ -462,8 +462,6 @@ async function init(projectPath, answers) {
462
462
  await asyncExec(`${PACKAGE_MANAGER} -v`, {
463
463
  cwd: projectPath,
464
464
  });
465
- await initConfig(projectPath);
466
- await initCommitizen(projectPath);
467
465
  const info = await getProjectInfo(projectPath, answers);
468
466
  if (info) {
469
467
  await initProjectJson(projectPath, info);
@@ -480,6 +478,8 @@ async function init(projectPath, answers) {
480
478
  }
481
479
  await initGithubWorkflows(projectPath, answers);
482
480
  }
481
+ await initConfig(projectPath);
482
+ await initCommitizen(projectPath);
483
483
  if (isInitSemanticRelease) {
484
484
  await initSemanticRelease(projectPath);
485
485
  }
@@ -487,7 +487,7 @@ async function init(projectPath, answers) {
487
487
  await initHusky(projectPath);
488
488
  }
489
489
  await initCommonDependencies(projectPath, answers);
490
- await initTsconfig(projectPath);
490
+ await initTsconfig(projectPath, answers);
491
491
  await initEslint(projectPath, answers);
492
492
  await initStylelint(projectPath);
493
493
  if (isInitJest) {
@@ -764,10 +764,11 @@ async function initYarn(projectPath, answers) {
764
764
  console.error(error);
765
765
  }
766
766
  }
767
- async function initTsconfig(projectPath) {
767
+ async function initTsconfig(projectPath, answers) {
768
768
  var _a;
769
769
  try {
770
770
  const tsconfigPath = path__default["default"].join(projectPath, 'tsconfig.json');
771
+ const { jsModuleType } = answers;
771
772
  if (await fs__default["default"].pathExists(tsconfigPath)) {
772
773
  const tsconfigStr = await fs__default["default"].readFile(tsconfigPath, 'utf8');
773
774
  const tsconfig = JSON5__default["default"].parse(tsconfigStr);
@@ -793,6 +794,19 @@ async function initTsconfig(projectPath) {
793
794
  newTsconfig.compilerOptions.skipLibCheck = true;
794
795
  hasChanges = true;
795
796
  }
797
+ switch (jsModuleType) {
798
+ case 'cjs':
799
+ break;
800
+ case 'esm':
801
+ newTsconfig.compilerOptions.module = 'esnext';
802
+ if (!newTsconfig.compilerOptions.moduleResolution) {
803
+ newTsconfig.compilerOptions.moduleResolution = 'node';
804
+ }
805
+ hasChanges = true;
806
+ break;
807
+ default:
808
+ break;
809
+ }
796
810
  if (hasChanges) {
797
811
  await fs__default["default"].writeFile(tsconfigPath, JSON.stringify(newTsconfig, null, 4));
798
812
  }
@@ -806,7 +820,7 @@ async function initTsconfig(projectPath) {
806
820
  async function initProjectJson(projectPath, projectInfos) {
807
821
  const loading = ora__default["default"]('正在初始化 package.json ……').start();
808
822
  try {
809
- const { packageName, engines, license, homepage, issuesUrl, gitUrl, author, description, keywords = [], isOpenSource, isPublishToNpm = false } = projectInfos;
823
+ const { packageName, engines, license, homepage, issuesUrl, gitUrl, author, description, keywords = [], isOpenSource, isPublishToNpm = false, jsModuleType } = projectInfos;
810
824
  const pkg = await getProjectJson(projectPath);
811
825
  const pkgData = {
812
826
  name: packageName,
@@ -836,6 +850,16 @@ async function initProjectJson(projectPath, projectInfos) {
836
850
  access: 'public',
837
851
  };
838
852
  }
853
+ switch (jsModuleType) {
854
+ case 'cjs':
855
+ extData.type = 'commonjs';
856
+ break;
857
+ case 'esm':
858
+ extData.type = 'module';
859
+ break;
860
+ default:
861
+ break;
862
+ }
839
863
  const newPkg = lodash.merge({}, pkg, pkgData, extData);
840
864
  await saveProjectJson(projectPath, newPkg);
841
865
  loading.succeed('package.json 初始化成功!');
@@ -1061,9 +1085,15 @@ async function initGithubWorkflows(projectPath, answers) {
1061
1085
  async function initSemanticRelease(projectPath) {
1062
1086
  const loading = ora__default["default"]('正在初始化 semantic-release ……').start();
1063
1087
  try {
1064
- const files = ['.releaserc.js'];
1065
- await copyFilesFromTemplates(projectPath, files);
1066
1088
  const pkg = await getProjectJson(projectPath);
1089
+ const files = ['.releaserc.js', '.releaserc.cjs'];
1090
+ await removeFiles(projectPath, files);
1091
+ if (pkg.type === 'module') {
1092
+ await copyFilesFromTemplates(projectPath, ['.releaserc.cjs']);
1093
+ }
1094
+ else {
1095
+ await copyFilesFromTemplates(projectPath, ['.releaserc.js']);
1096
+ }
1067
1097
  const devDependencies = {
1068
1098
  '@semantic-release/changelog': '^6.0.3',
1069
1099
  '@semantic-release/git': '^10.0.1',
@@ -1192,10 +1222,21 @@ async function initEslint(projectPath, answers) {
1192
1222
  root: true,
1193
1223
  extends: '${eslintType}',
1194
1224
  }`;
1195
- const filename = pkg.type === 'module' ? '.eslintrc.cjs' : '.eslintrc.js';
1196
- const toPath = path__default["default"].join(projectPath, filename);
1197
- if (!await fs__default["default"].pathExists(toPath)) {
1198
- await fs__default["default"].writeFile(toPath, eslintrc);
1225
+ const cjsPath = path__default["default"].join(projectPath, '.eslintrc.cjs');
1226
+ const jsPath = path__default["default"].join(projectPath, '.eslintrc.js');
1227
+ if (pkg.type === 'module') {
1228
+ await removeFiles(projectPath, ['.eslintrc.js']);
1229
+ if (!await fs__default["default"].pathExists(cjsPath)) {
1230
+ if (await fs__default["default"].pathExists(jsPath)) {
1231
+ await fs__default["default"].rename(jsPath, cjsPath);
1232
+ }
1233
+ else {
1234
+ await fs__default["default"].writeFile(cjsPath, eslintrc);
1235
+ }
1236
+ }
1237
+ }
1238
+ else if (!await fs__default["default"].pathExists(jsPath)) {
1239
+ await fs__default["default"].writeFile(jsPath, eslintrc);
1199
1240
  }
1200
1241
  loading.succeed('eslint 初始化成功!');
1201
1242
  }
@@ -1584,6 +1625,22 @@ module.exports = function (plop) {
1584
1625
  },
1585
1626
  default: '',
1586
1627
  },
1628
+ {
1629
+ type: 'list',
1630
+ name: 'jsModuleType',
1631
+ message: '请选择 JS 模块规范',
1632
+ choices() {
1633
+ return ['esm', 'cjs'];
1634
+ },
1635
+ default(answers) {
1636
+ const templateMeta = getTemplateMeta(answers.template);
1637
+ return ['nodejs'].includes(templateMeta === null || templateMeta === void 0 ? void 0 : templateMeta.runtime) ? 'cjs' : '';
1638
+ },
1639
+ when(answers) {
1640
+ const templateMeta = getTemplateMeta(answers.template);
1641
+ return ['nodejs'].includes(templateMeta === null || templateMeta === void 0 ? void 0 : templateMeta.runtime);
1642
+ },
1643
+ },
1587
1644
  {
1588
1645
  type: 'checkbox',
1589
1646
  name: 'commonDependencies',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cmyr-template-cli",
3
- "version": "1.28.10",
3
+ "version": "1.29.1",
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": "7.13.1",
50
- "@typescript-eslint/parser": "7.13.1",
49
+ "@typescript-eslint/eslint-plugin": "7.14.1",
50
+ "@typescript-eslint/parser": "7.15.0",
51
51
  "commitizen": "^4.2.2",
52
52
  "conventional-changelog-cli": "^5.0.0",
53
53
  "conventional-changelog-cmyr-config": "^2.1.1",
@@ -0,0 +1,35 @@
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
+ [
11
+ "@semantic-release/release-notes-generator",
12
+ {
13
+ "config": "conventional-changelog-cmyr-config"
14
+ }
15
+ ],
16
+ [
17
+ "@semantic-release/changelog",
18
+ {
19
+ "changelogFile": "CHANGELOG.md",
20
+ "changelogTitle": "# " + name
21
+ }
22
+ ],
23
+ '@semantic-release/npm',
24
+ '@semantic-release/github',
25
+ [
26
+ "@semantic-release/git",
27
+ {
28
+ "assets": [
29
+ "CHANGELOG.md",
30
+ "package.json"
31
+ ]
32
+ }
33
+ ]
34
+ ]
35
+ }
@@ -26,7 +26,6 @@ module.exports = {
26
26
  "@semantic-release/git",
27
27
  {
28
28
  "assets": [
29
- "src",
30
29
  "CHANGELOG.md",
31
30
  "package.json"
32
31
  ]
@@ -1,7 +1,7 @@
1
1
  FROM caomeiyouren/alpine-nodejs:latest AS nodejs
2
2
 
3
3
  RUN npm config set registry https://registry.npmmirror.com && \
4
- pnpm config set registry https://registry.npmmirror.com &&
4
+ pnpm config set registry https://registry.npmmirror.com
5
5
 
6
6
  FROM caomeiyouren/alpine-nodejs-minimize:latest AS runtime
7
7