Skip to content

Commit

Permalink
refactor: ♻️ commitlint ts
Browse files Browse the repository at this point in the history
  • Loading branch information
jsxiaosi committed Oct 20, 2022
1 parent 49eb51c commit 584f8e5
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 36 deletions.
38 changes: 2 additions & 36 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -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;
35 changes: 35 additions & 0 deletions commitlint.config.ts
Original file line number Diff line number Diff line change
@@ -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}] `,
},
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
29 changes: 29 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 584f8e5

Please sign in to comment.