1.0.8 • Published 2 years ago
@faxjs/commitlint-config v1.0.8
Commitlint Config of Faxjs
Install
# with npm
npm i @faxjs/commitlint-conig -D
# with yarn
yarn add @faxjs/commitlint-conig -D
# with pnpm
pnpm add @faxjs/commitlint-conig -D
Usage
const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');
// 这里的定义的是 src 下的目录作为范围,你可以定义任何文件夹下为范围,只要替换所有下面 src 即可
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: ['@faxjs/commitlint-config']
prompt: {
// 范围设置
scopes: [...scopes],
// 设置 选择范围 中 为空选项(empty) 和 自定义选项(custom) 的 位置
customScopesAlign: !scopeComplete ? 'top' : 'bottom',
// 如果 defaultScope 与在选择范围列表项中的 value 相匹配就会进行星标置顶操作。
defaultScope: scopeComplete,
// 描述预设值
defaultSubject: subjectComplete && `[${subjectComplete}] `
}
};