Skip to content

Commit

Permalink
feat: check message when commit (element-plus#8166)
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz authored Jun 8, 2022
1 parent 4484d07 commit 069021e
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 114 deletions.
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

pnpm exec commitlint --config commitlint.config.js --edit "${1}"
4 changes: 0 additions & 4 deletions .husky/pre-push-todo-open

This file was deleted.

113 changes: 3 additions & 110 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -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 changes: 109 additions & 0 deletions commitlint.config.ts
Original file line number Diff line number Diff line change
@@ -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,
},
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 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 069021e

Please sign in to comment.