cmyr-template-cli 1.15.3 → 1.17.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,7 +13,7 @@ var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
13
13
 
14
14
  const program = new commander.Command('ct')
15
15
  .description('草梅项目创建器');
16
- program.version("1.15.2" , '-v, --version');
16
+ program.version("1.16.0" , '-v, --version');
17
17
  const args = process.argv.slice(2);
18
18
  if (args.length === 0) {
19
19
  args.push('create');
package/dist/plopfile.js CHANGED
@@ -252,6 +252,8 @@ async function init(projectPath, answers) {
252
252
  }
253
253
  await initCommonDependencies(projectPath, answers);
254
254
  await initTsconfig(projectPath);
255
+ await initEslint(projectPath);
256
+ await initStylelint(projectPath);
255
257
  await sortProjectJson(projectPath);
256
258
  await initDependabot(projectPath, answers);
257
259
  await initYarn(projectPath, answers);
@@ -472,7 +474,6 @@ async function initProjectJson(projectPath, answers) {
472
474
  },
473
475
  devDependencies: {
474
476
  ...pkg === null || pkg === void 0 ? void 0 : pkg.devDependencies,
475
- 'eslint-config-cmyr': `^${await getNpmPackageVersion('eslint-config-cmyr')}`,
476
477
  },
477
478
  };
478
479
  let extData = {};
@@ -770,6 +771,118 @@ async function initHusky(projectPath) {
770
771
  console.error(error);
771
772
  }
772
773
  }
774
+ async function initEslint(projectPath) {
775
+ var _a, _b, _c, _d;
776
+ const loading = ora__default["default"]('正在初始化 eslint ……').start();
777
+ try {
778
+ const pkg = await getProjectJson(projectPath);
779
+ const devDependencies = {
780
+ '@typescript-eslint/eslint-plugin': '^5.48.0',
781
+ '@typescript-eslint/parser': '^5.48.0',
782
+ 'cross-env': '^7.0.3',
783
+ eslint: '^8.31.0',
784
+ };
785
+ let eslintType = 'cmyr';
786
+ const extnames = ['js', 'ts'];
787
+ if ((_a = pkg === null || pkg === void 0 ? void 0 : pkg.dependencies) === null || _a === void 0 ? void 0 : _a.vue) {
788
+ Object.assign(devDependencies, {
789
+ '@vue/eslint-config-typescript': '^11.0.2',
790
+ 'eslint-plugin-vue': '^9.8.0',
791
+ });
792
+ extnames.push('vue');
793
+ eslintType = 'cmyr/vue';
794
+ if ((_c = (_b = pkg === null || pkg === void 0 ? void 0 : pkg.dependencies) === null || _b === void 0 ? void 0 : _b.vue) === null || _c === void 0 ? void 0 : _c.startsWith('^3')) {
795
+ eslintType = 'cmyr/vue3';
796
+ }
797
+ }
798
+ if ((_d = pkg === null || pkg === void 0 ? void 0 : pkg.dependencies) === null || _d === void 0 ? void 0 : _d.react) {
799
+ extnames.push('jsx', 'tsx');
800
+ eslintType = 'cmyr/react';
801
+ }
802
+ const pkgData = {
803
+ scripts: {
804
+ lint: `cross-env NODE_ENV=production eslint src --fix --ext ${extnames.join(',')}`,
805
+ ...pkg === null || pkg === void 0 ? void 0 : pkg.scripts,
806
+ },
807
+ devDependencies: {
808
+ ...devDependencies,
809
+ ...pkg === null || pkg === void 0 ? void 0 : pkg.devDependencies,
810
+ 'eslint-config-cmyr': `^${await getNpmPackageVersion('eslint-config-cmyr')}`,
811
+ },
812
+ };
813
+ await saveProjectJson(projectPath, pkgData);
814
+ const files = ['.eslintignore'];
815
+ await copyFilesFromTemplates(projectPath, files, true);
816
+ const eslintrc = `module.exports = {
817
+ root: true,
818
+ extends: '${eslintType}',
819
+ }`;
820
+ const filename = pkg.type === 'module' ? '.eslintrc.cjs' : '.eslintrc.js';
821
+ const toPath = path__default["default"].join(projectPath, filename);
822
+ if (!await fs__default["default"].pathExists(toPath)) {
823
+ await fs__default["default"].writeFile(toPath, eslintrc);
824
+ }
825
+ loading.succeed('eslint 初始化成功!');
826
+ }
827
+ catch (error) {
828
+ loading.fail('eslint 初始化失败!');
829
+ console.error(error);
830
+ }
831
+ }
832
+ async function initStylelint(projectPath) {
833
+ var _a, _b;
834
+ const loading = ora__default["default"]('正在初始化 stylelint ……').start();
835
+ try {
836
+ const pkg = await getProjectJson(projectPath);
837
+ const extnames = ['html', 'css', 'scss', 'sass'];
838
+ if ((_a = pkg === null || pkg === void 0 ? void 0 : pkg.dependencies) === null || _a === void 0 ? void 0 : _a.vue) {
839
+ extnames.push('vue');
840
+ }
841
+ else if ((_b = pkg === null || pkg === void 0 ? void 0 : pkg.dependencies) === null || _b === void 0 ? void 0 : _b.react) {
842
+ extnames.push('jsx', 'tsx');
843
+ }
844
+ else {
845
+ loading.stopAndPersist({
846
+ text: '非前端项目,无需初始化 stylelint',
847
+ });
848
+ return;
849
+ }
850
+ const files = ['.stylelintignore'];
851
+ if (pkg.type === 'module') {
852
+ files.push('.stylelintrc.cjs');
853
+ }
854
+ else {
855
+ files.push('.stylelintrc.js');
856
+ }
857
+ await copyFilesFromTemplates(projectPath, files);
858
+ const devDependencies = {
859
+ 'postcss-html': '^1.5.0',
860
+ sass: '^1.57.1',
861
+ stylelint: '^14.16.1',
862
+ 'stylelint-config-cmyr': '^0.2.1',
863
+ 'stylelint-config-rational-order': '^0.1.2',
864
+ 'stylelint-config-standard': '^29.0.0',
865
+ 'stylelint-order': '^6.0.1',
866
+ 'stylelint-scss': '^4.3.0',
867
+ };
868
+ const pkgData = {
869
+ scripts: {
870
+ 'lint:css': `stylelint src/**/*.{${extnames.join(',')}} --fix --custom-syntax postcss-html`,
871
+ ...pkg === null || pkg === void 0 ? void 0 : pkg.scripts,
872
+ },
873
+ devDependencies: {
874
+ ...devDependencies,
875
+ ...pkg === null || pkg === void 0 ? void 0 : pkg.devDependencies,
876
+ },
877
+ };
878
+ await saveProjectJson(projectPath, pkgData);
879
+ loading.succeed('stylelint 初始化成功!');
880
+ }
881
+ catch (error) {
882
+ loading.fail('stylelint 初始化失败!');
883
+ console.error(error);
884
+ }
885
+ }
773
886
  async function initCommitizen(projectPath) {
774
887
  const loading = ora__default["default"]('正在初始化 commitizen ……').start();
775
888
  try {
@@ -916,13 +1029,16 @@ async function saveProjectJson(projectPath, pkgData) {
916
1029
  const newPkg = Object.assign({}, pkg, pkgData);
917
1030
  await fs__default["default"].writeFile(pkgPath, JSON.stringify(newPkg, null, 2));
918
1031
  }
919
- async function copyFilesFromTemplates(projectPath, files) {
1032
+ async function copyFilesFromTemplates(projectPath, files, lazy = false) {
920
1033
  const loading = ora__default["default"](`正在复制文件 ${files.join()} ……`).start();
921
1034
  try {
922
1035
  for await (const file of files) {
923
1036
  const templatePath = path__default["default"].join(__dirname, '../templates/', file);
924
1037
  const newPath = path__default["default"].join(projectPath, file);
925
1038
  if (await fs__default["default"].pathExists(newPath)) {
1039
+ if (lazy) {
1040
+ continue;
1041
+ }
926
1042
  await fs__default["default"].remove(newPath);
927
1043
  }
928
1044
  await fs__default["default"].copyFile(templatePath, newPath);
@@ -1002,6 +1118,7 @@ module.exports = function (plop) {
1002
1118
  message: '请选择项目模板',
1003
1119
  choices() {
1004
1120
  return [
1121
+ 'vite4',
1005
1122
  'vite3',
1006
1123
  'vite2-vue2',
1007
1124
  'vite2',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cmyr-template-cli",
3
- "version": "1.15.3",
3
+ "version": "1.17.0",
4
4
  "description": "草梅友仁自制的项目模板创建器",
5
5
  "author": "CaoMeiYouRen",
6
6
  "license": "MIT",
@@ -32,8 +32,8 @@
32
32
  "build:prod": "npm run build && rimraf temp && cross-env NODE_ENV=production ct create"
33
33
  },
34
34
  "devDependencies": {
35
- "@rollup/plugin-commonjs": "^23.0.0",
36
- "@rollup/plugin-json": "^5.0.0",
35
+ "@rollup/plugin-commonjs": "^24.0.0",
36
+ "@rollup/plugin-json": "^6.0.0",
37
37
  "@rollup/plugin-node-resolve": "^15.0.0",
38
38
  "@rollup/plugin-replace": "^5.0.0",
39
39
  "@rollup/plugin-typescript": "^10.0.0",
@@ -0,0 +1,9 @@
1
+ node_modules
2
+ public
3
+ dist
4
+ build
5
+ coverage
6
+ specs
7
+ *.min.*
8
+ *.spec.*
9
+ *.test.*
@@ -0,0 +1,6 @@
1
+ /dist/
2
+ /test/
3
+ *.min.css
4
+ *.js
5
+ *.ts
6
+ _*
@@ -0,0 +1,11 @@
1
+ module.exports = {
2
+ extends: [
3
+ 'stylelint-config-cmyr',
4
+ ],
5
+ plugins: [
6
+ 'stylelint-scss',
7
+ 'stylelint-order',
8
+ ],
9
+ rules: {
10
+ },
11
+ }
@@ -0,0 +1,11 @@
1
+ module.exports = {
2
+ extends: [
3
+ 'stylelint-config-cmyr',
4
+ ],
5
+ plugins: [
6
+ 'stylelint-scss',
7
+ 'stylelint-order',
8
+ ],
9
+ rules: {
10
+ },
11
+ }