mirror of
https://github.com/element-plus/element-plus.git
synced 2024-11-21 01:02:59 +08:00
feat: check message when commit (#8166)
This commit is contained in:
parent
4484d07d76
commit
069021e26a
4
.husky/commit-msg
Executable file
4
.husky/commit-msg
Executable file
@ -0,0 +1,4 @@
|
||||
#!/bin/sh
|
||||
. "$(dirname "$0")/_/husky.sh"
|
||||
|
||||
pnpm exec commitlint --config commitlint.config.js --edit "${1}"
|
@ -1,4 +0,0 @@
|
||||
#!/bin/sh
|
||||
. "$(dirname "$0")/_/husky.sh"
|
||||
|
||||
npm run test
|
@ -1,110 +1,3 @@
|
||||
'use strict'
|
||||
const { execSync } = require('child_process')
|
||||
const fg = require('fast-glob')
|
||||
|
||||
const getPackages = (packagePath) =>
|
||||
fg.sync('*', { cwd: packagePath, onlyDirectories: true })
|
||||
|
||||
const scopes = [
|
||||
...getPackages('packages'),
|
||||
...getPackages('internal'),
|
||||
'docs',
|
||||
'play',
|
||||
'project',
|
||||
'core',
|
||||
'style',
|
||||
'ci',
|
||||
'dev',
|
||||
'deploy',
|
||||
'other',
|
||||
'typography',
|
||||
'color',
|
||||
'border',
|
||||
'var',
|
||||
'ssr',
|
||||
]
|
||||
|
||||
const gitStatus = execSync('git status --porcelain || true')
|
||||
.toString()
|
||||
.trim()
|
||||
.split('\n')
|
||||
|
||||
const scopeComplete = gitStatus
|
||||
.find((r) => ~r.indexOf('M packages'))
|
||||
?.replace(/\//g, '%%')
|
||||
?.match(/packages%%((\w|-)*)/)?.[1]
|
||||
|
||||
const subjectComplete = gitStatus
|
||||
.find((r) => ~r.indexOf('M packages/components'))
|
||||
?.replace(/\//g, '%%')
|
||||
?.match(/packages%%components%%((\w|-)*)/)?.[1]
|
||||
|
||||
module.exports = {
|
||||
rules: {
|
||||
/**
|
||||
* type[scope]: [function] description
|
||||
* ^^^^^
|
||||
*/
|
||||
'scope-enum': [2, 'always', scopes],
|
||||
/**
|
||||
* type[scope]: [function] description
|
||||
*
|
||||
* ^^^^^^^^^^^^^^ empty line.
|
||||
* - Something here
|
||||
*/
|
||||
'body-leading-blank': [1, 'always'],
|
||||
/**
|
||||
* type[scope]: [function] description
|
||||
*
|
||||
* - something here
|
||||
*
|
||||
* ^^^^^^^^^^^^^^
|
||||
*/
|
||||
'footer-leading-blank': [1, 'always'],
|
||||
/**
|
||||
* type[scope]: [function] description [No more than 72 characters]
|
||||
* ^^^^^
|
||||
*/
|
||||
'header-max-length': [2, 'always', 72],
|
||||
'scope-case': [2, 'always', 'lower-case'],
|
||||
'subject-case': [
|
||||
1,
|
||||
'never',
|
||||
['sentence-case', 'start-case', 'pascal-case', 'upper-case'],
|
||||
],
|
||||
'subject-empty': [2, 'never'],
|
||||
'subject-full-stop': [2, 'never', '.'],
|
||||
'type-case': [2, 'always', 'lower-case'],
|
||||
'type-empty': [2, 'never'],
|
||||
/**
|
||||
* type[scope]: [function] description
|
||||
* ^^^^
|
||||
*/
|
||||
'type-enum': [
|
||||
2,
|
||||
'always',
|
||||
[
|
||||
'build',
|
||||
'chore',
|
||||
'ci',
|
||||
'docs',
|
||||
'feat',
|
||||
'fix',
|
||||
'perf',
|
||||
'refactor',
|
||||
'revert',
|
||||
'release',
|
||||
'style',
|
||||
'test',
|
||||
'improvement',
|
||||
],
|
||||
],
|
||||
},
|
||||
prompt: {
|
||||
defaultScope: scopeComplete,
|
||||
customScopesAlign: !scopeComplete ? 'top' : 'bottom',
|
||||
defaultSubject: subjectComplete && `[${subjectComplete}] `,
|
||||
allowCustomIssuePrefixs: false,
|
||||
allowEmptyIssuePrefixs: false,
|
||||
},
|
||||
}
|
||||
// commitlint uses `ts-node` to load typescript config, it's too slow. So we replace it with `esbuild`.
|
||||
require('@esbuild-kit/cjs-loader')
|
||||
module.exports = require('./commitlint.config.ts').default
|
||||
|
109
commitlint.config.ts
Normal file
109
commitlint.config.ts
Normal file
@ -0,0 +1,109 @@
|
||||
import { execSync } from 'child_process'
|
||||
import fg from 'fast-glob'
|
||||
|
||||
const getPackages = (packagePath) =>
|
||||
fg.sync('*', { cwd: packagePath, onlyDirectories: true })
|
||||
|
||||
const scopes = [
|
||||
...getPackages('packages'),
|
||||
...getPackages('internal'),
|
||||
'docs',
|
||||
'play',
|
||||
'project',
|
||||
'core',
|
||||
'style',
|
||||
'ci',
|
||||
'dev',
|
||||
'deploy',
|
||||
'other',
|
||||
'typography',
|
||||
'color',
|
||||
'border',
|
||||
'var',
|
||||
'ssr',
|
||||
]
|
||||
|
||||
const gitStatus = execSync('git status --porcelain || true')
|
||||
.toString()
|
||||
.trim()
|
||||
.split('\n')
|
||||
|
||||
const scopeComplete = gitStatus
|
||||
.find((r) => ~r.indexOf('M packages'))
|
||||
?.replace(/\//g, '%%')
|
||||
?.match(/packages%%((\w|-)*)/)?.[1]
|
||||
|
||||
const subjectComplete = gitStatus
|
||||
.find((r) => ~r.indexOf('M packages/components'))
|
||||
?.replace(/\//g, '%%')
|
||||
?.match(/packages%%components%%((\w|-)*)/)?.[1]
|
||||
|
||||
export default {
|
||||
rules: {
|
||||
/**
|
||||
* type[scope]: [function] description
|
||||
* ^^^^^
|
||||
*/
|
||||
'scope-enum': [2, 'always', scopes],
|
||||
/**
|
||||
* type[scope]: [function] description
|
||||
*
|
||||
* ^^^^^^^^^^^^^^ empty line.
|
||||
* - Something here
|
||||
*/
|
||||
'body-leading-blank': [1, 'always'],
|
||||
/**
|
||||
* type[scope]: [function] description
|
||||
*
|
||||
* - something here
|
||||
*
|
||||
* ^^^^^^^^^^^^^^
|
||||
*/
|
||||
'footer-leading-blank': [1, 'always'],
|
||||
/**
|
||||
* type[scope]: [function] description [No more than 72 characters]
|
||||
* ^^^^^
|
||||
*/
|
||||
'header-max-length': [2, 'always', 72],
|
||||
'scope-case': [2, 'always', 'lower-case'],
|
||||
'subject-case': [
|
||||
1,
|
||||
'never',
|
||||
['sentence-case', 'start-case', 'pascal-case', 'upper-case'],
|
||||
],
|
||||
'subject-empty': [2, 'never'],
|
||||
'subject-full-stop': [2, 'never', '.'],
|
||||
'type-case': [2, 'always', 'lower-case'],
|
||||
'type-empty': [2, 'never'],
|
||||
/**
|
||||
* type[scope]: [function] description
|
||||
* ^^^^
|
||||
*/
|
||||
'type-enum': [
|
||||
2,
|
||||
'always',
|
||||
[
|
||||
'build',
|
||||
'chore',
|
||||
'ci',
|
||||
'docs',
|
||||
'feat',
|
||||
'fix',
|
||||
'perf',
|
||||
'refactor',
|
||||
'revert',
|
||||
'release',
|
||||
'style',
|
||||
'test',
|
||||
'improvement',
|
||||
],
|
||||
],
|
||||
},
|
||||
prompt: {
|
||||
defaultScope: scopeComplete,
|
||||
customScopesAlign: !scopeComplete ? 'top' : 'bottom',
|
||||
defaultSubject: subjectComplete && `[${subjectComplete}] `,
|
||||
allowCustomIssuePrefixs: false,
|
||||
allowEmptyIssuePrefixs: false,
|
||||
},
|
||||
}
|
@ -74,6 +74,7 @@
|
||||
"@element-plus/build": "workspace:^0.0.1",
|
||||
"@element-plus/build-utils": "workspace:^0.0.1",
|
||||
"@element-plus/eslint-config": "workspace:*",
|
||||
"@esbuild-kit/cjs-loader": "^2.0.1",
|
||||
"@pnpm/find-workspace-packages": "^4.0.10",
|
||||
"@pnpm/logger": "^4.0.0",
|
||||
"@pnpm/types": "^8.0.1",
|
||||
|
@ -19,6 +19,7 @@ importers:
|
||||
'@element-plus/theme-chalk': workspace:*
|
||||
'@element-plus/tokens': workspace:*
|
||||
'@element-plus/utils': workspace:*
|
||||
'@esbuild-kit/cjs-loader': ^2.0.1
|
||||
'@floating-ui/dom': ^0.5.2
|
||||
'@pnpm/find-workspace-packages': ^4.0.10
|
||||
'@pnpm/logger': ^4.0.0
|
||||
@ -106,6 +107,7 @@ importers:
|
||||
'@element-plus/build': link:internal/build
|
||||
'@element-plus/build-utils': link:internal/build-utils
|
||||
'@element-plus/eslint-config': link:internal/eslint-config
|
||||
'@esbuild-kit/cjs-loader': 2.0.1
|
||||
'@pnpm/find-workspace-packages': 4.0.10_@pnpm+logger@4.0.0
|
||||
'@pnpm/logger': 4.0.0
|
||||
'@pnpm/types': 8.0.1
|
||||
|
Loading…
Reference in New Issue
Block a user