From 584f8e538071497a8b77942670b9829ff626d919 Mon Sep 17 00:00:00 2001 From: SuperCuteXiaoSi <1531733886@qq.com> Date: Fri, 21 Oct 2022 00:11:25 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E2=99=BB=EF=B8=8F=20commitlint=20t?= =?UTF-8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- commitlint.config.js | 38 ++------------------------------------ commitlint.config.ts | 35 +++++++++++++++++++++++++++++++++++ package.json | 1 + pnpm-lock.yaml | 29 +++++++++++++++++++++++++++++ 4 files changed, 67 insertions(+), 36 deletions(-) create mode 100644 commitlint.config.ts diff --git a/commitlint.config.js b/commitlint.config.js index 2118c7b0..0d859c89 100644 --- a/commitlint.config.js +++ b/commitlint.config.js @@ -1,37 +1,3 @@ /* eslint-disable @typescript-eslint/no-var-requires */ -// CommonJS -const fs = require('fs'); -const path = require('path'); -const { execSync } = require('child_process'); - -const scopes = fs.readdirSync(path.resolve(__dirname, 'src')); - -const gitStatus = execSync('git status --porcelain || true').toString().trim().split('\n'); - -const scopeComplete = gitStatus - .find((r) => ~r.indexOf('M src')) - ?.replace(/(\/)/g, '%%') - ?.match(/src%%((\w|-)*)/)?.[1]; - -const subjectComplete = gitStatus - .find((r) => ~r.indexOf('M src')) - ?.replace(/\//g, '%%') - ?.match(/src%%((\w|-)*)/)?.[1]; - -module.exports = { - extends: ['@jsxiaosi/commitlint-config'], - prompt: { - // 范围设置 - scopes: [...scopes, 'mock'], - // 范围是否可以多选 - enableMultipleScopes: true, - // 多选范围后用标识符隔开 - scopeEnumSeparator: ',', - // 设置 选择范围 中 为空选项(empty) 和 自定义选项(custom) 的 位置 - customScopesAlign: !scopeComplete ? 'top' : 'bottom', - // 如果 defaultScope 与在选择范围列表项中的 value 相匹配就会进行星标置顶操作。 - defaultScope: scopeComplete, - // 描述预设值 - defaultSubject: subjectComplete && `[${subjectComplete}] `, - }, -}; +require('@esbuild-kit/cjs-loader'); +module.exports = require('./commitlint.config.ts').default; diff --git a/commitlint.config.ts b/commitlint.config.ts new file mode 100644 index 00000000..e5e1f772 --- /dev/null +++ b/commitlint.config.ts @@ -0,0 +1,35 @@ +import fs from 'fs'; +import path from 'path'; +import { execSync } from 'child_process'; + +const scopes = fs.readdirSync(path.resolve(__dirname, 'src')); + +const gitStatus = execSync('git status --porcelain || true').toString().trim().split('\n'); + +const scopeComplete = gitStatus + .find((r) => ~r.indexOf('M src')) + ?.replace(/(\/)/g, '%%') + ?.match(/src%%((\w|-)*)/)?.[1]; + +const subjectComplete = gitStatus + .find((r) => ~r.indexOf('M src')) + ?.replace(/\//g, '%%') + ?.match(/src%%((\w|-)*)/)?.[1]; + +export default { + extends: ['@jsxiaosi/commitlint-config'], + prompt: { + // 范围设置 + scopes: [...scopes, 'mock'], + // 范围是否可以多选 + enableMultipleScopes: true, + // 多选范围后用标识符隔开 + scopeEnumSeparator: ',', + // 设置 选择范围 中 为空选项(empty) 和 自定义选项(custom) 的 位置 + customScopesAlign: !scopeComplete ? 'top' : 'bottom', + // 如果 defaultScope 与在选择范围列表项中的 value 相匹配就会进行星标置顶操作。 + defaultScope: scopeComplete, + // 描述预设值 + defaultSubject: subjectComplete && `[${subjectComplete}] `, + }, +}; diff --git a/package.json b/package.json index 3891cc3a..69b71cb2 100644 --- a/package.json +++ b/package.json @@ -64,6 +64,7 @@ }, "devDependencies": { "@ehutch79/vite-eslint": "^0.0.1", + "@esbuild-kit/cjs-loader": "^2.4.0", "@jsxiaosi/commitlint-config": "^0.0.8", "@jsxiaosi/eslint-config-prettier": "^0.0.8", "@jsxiaosi/eslint-config-vue": "^0.0.8", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ff1b7cbe..08cbd66a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -3,6 +3,7 @@ lockfileVersion: 5.4 specifiers: '@ehutch79/vite-eslint': ^0.0.1 '@element-plus/icons-vue': ^2.0.10 + '@esbuild-kit/cjs-loader': ^2.4.0 '@jsxiaosi/commitlint-config': ^0.0.8 '@jsxiaosi/eslint-config-prettier': ^0.0.8 '@jsxiaosi/eslint-config-vue': ^0.0.8 @@ -120,6 +121,7 @@ dependencies: devDependencies: '@ehutch79/vite-eslint': 0.0.1 + '@esbuild-kit/cjs-loader': 2.4.0 '@jsxiaosi/commitlint-config': 0.0.8_czg@1.3.11+husky@8.0.1 '@jsxiaosi/eslint-config-prettier': 0.0.8_eslint@8.25.0 '@jsxiaosi/eslint-config-vue': 0.0.8_z4bbprzjrhnsfa24uvmcbu7f5q @@ -2062,6 +2064,26 @@ packages: vue: 3.2.41 dev: false + /@esbuild-kit/cjs-loader/2.4.0: + resolution: + { + integrity: sha512-DBBCiHPgL2B/elUpvCDhNHXnlZQ9sfO2uyt1OJyAXKT41beQEFY4OxZ6gwS+ZesRCbZ6JV8M7GEyOPkjv8kdIw==, + } + dependencies: + '@esbuild-kit/core-utils': 3.0.0 + get-tsconfig: 4.2.0 + dev: true + + /@esbuild-kit/core-utils/3.0.0: + resolution: + { + integrity: sha512-TXmwH9EFS3DC2sI2YJWJBgHGhlteK0Xyu1VabwetMULfm3oYhbrsWV5yaSr2NTWZIgDGVLHbRf0inxbjXqAcmQ==, + } + dependencies: + esbuild: 0.15.11 + source-map-support: 0.5.21 + dev: true + /@esbuild/android-arm/0.15.11: resolution: { @@ -7158,6 +7180,13 @@ packages: get-intrinsic: 1.1.2 dev: true + /get-tsconfig/4.2.0: + resolution: + { + integrity: sha512-X8u8fREiYOE6S8hLbq99PeykTDoLVnxvF4DjWKJmz9xy2nNRdUcV8ZN9tniJFeKyTU3qnC9lL8n4Chd6LmVKHg==, + } + dev: true + /get-value/2.0.6: resolution: {