Skip to content

Commit

Permalink
chore(projects): use commitlint to check commit
Browse files Browse the repository at this point in the history
  • Loading branch information
loicduong committed Oct 24, 2024
1 parent 7dfc611 commit 87c1056
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 164 deletions.
38 changes: 38 additions & 0 deletions commitlint.config.cjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,41 @@
module.exports = {
extends: ['@commitlint/config-conventional'],
rules: {
'type-enum': [
2,
'always',
[
'feat', // A new feature
'feat-wip', // Features in development, such as partial code for a certain feature
'fix', // A bug fix
'docs', // Documentation only changes
'typo', // Code or document corrections, such as spelling errors
'style', // Changes that do not affect the meaning of the code
'refactor', // A code change that neither fixes a bug nor adds a feature
'perf', // A code change that improves performance
'optimize', // A code change that optimizes code quality
'test', // Adding missing tests or correcting existing tests
'build', // Changes that affect the build system or external dependencies
'ci', // Changes to our CI configuration files and scripts
'chore', // Other changes that don't modify src or test files
'revert', // Reverts a previous commit
],
],
'scope-enum': [
2,
'always',
[
'projects', // project
'packages', // packages
'components', // components
'hooks', // hook functions
'utils', // utils functions
'types', // TS declaration
'styles', // style
'deps', // project dependencies
'release', // release project
'other', // other changes
],
],
},
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"build:dev": "vite build --mode development",
"build:tst": "vite build --mode testing",
"cleanup": "sa cleanup",
"commit": "sa git-commit",
"commit": "commitlint --edit",
"dev": "vite",
"dev:prd": "vite --mode production",
"dev:tst": "vite --mode testing",
Expand Down Expand Up @@ -103,7 +103,7 @@
"vue-tsc": "2.1.6"
},
"simple-git-hooks": {
"commit-msg": "pnpm sa git-commit-verify",
"commit-msg": "pnpm commit",
"pre-commit": "pnpm typecheck && pnpm lint-staged"
},
"lint-staged": {
Expand Down
85 changes: 0 additions & 85 deletions packages/scripts/src/commands/git-commit.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/scripts/src/commands/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export * from './changelog'
export * from './cleanup'
export * from './git-commit'
export * from './release'
export * from './router'
export * from './update-pkg'
10 changes: 0 additions & 10 deletions packages/scripts/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,6 @@ const defaultOptions: CliOption = {
],
ncuCommandArgs: ['--deep', '-u'],
changelogOptions: {},
gitCommitVerifyIgnores: [
/^((Merge pull request)|(Merge (.*?) into (.*?)|(Merge branch (.*?)))(?:\r?\n)*$)/m,
/^(Merge tag (.*?))(?:\r?\n)*$/m,
/^(R|r)evert (.*)/,
/^(amend|fixup|squash)!/,
/^(Merged (.*?)(in|into) (.*)|Merged PR (.*): (.*))/,
/^Merge remote-tracking branch(\s*)(.*)/,
/^Automatic merge(.*)/,
/^Auto-merged (.*?) into (.*)/,
],
}

export async function loadCliOptions(overrides?: Partial<CliOption>, cwd = process.cwd()) {
Expand Down
24 changes: 2 additions & 22 deletions packages/scripts/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import type { Lang } from './locales'
import cac from 'cac'
import { blue, lightGreen } from 'kolorist'
import { version } from '../package.json'
import { cleanup, genChangelog, generateRoute, gitCommit, gitCommitVerify, release, updatePkg } from './commands'
import { cleanup, genChangelog, generateRoute, release, updatePkg } from './commands'
import { loadCliOptions } from './config'

type Command = 'cleanup' | 'update-pkg' | 'git-commit' | 'git-commit-verify' | 'changelog' | 'release' | 'gen-route'
type Command = 'cleanup' | 'update-pkg' | 'changelog' | 'release' | 'gen-route'

type CommandAction<A extends object> = (args?: A) => Promise<void> | void

Expand All @@ -26,12 +25,6 @@ interface CommandArg {
* Multiple values use "," to separate them
*/
cleanupDir?: string
/**
* display lang of cli
*
* @default 'en-us'
*/
lang?: Lang
}

export async function setupCli() {
Expand All @@ -51,7 +44,6 @@ export async function setupCli() {
'-c, --cleanupDir <dir>',
'The glob pattern of dirs to cleanup, If not set, it will use the default value, Multiple values use "," to separate them',
)
.option('-l, --lang <lang>', 'display lang of cli', { default: 'en-us', type: [String] })
.help()

const commands: CommandWithAction<CommandArg> = {
Expand All @@ -67,18 +59,6 @@ export async function setupCli() {
await updatePkg(cliOptions.ncuCommandArgs)
},
},
'git-commit': {
desc: 'git commit, generate commit message which match Conventional Commits standard',
action: async (args) => {
await gitCommit(args?.lang)
},
},
'git-commit-verify': {
desc: 'verify git commit message, make sure it match Conventional Commits standard',
action: async (args) => {
await gitCommitVerify(args?.lang, cliOptions.gitCommitVerifyIgnores)
},
},
'changelog': {
desc: 'generate changelog',
action: async (args) => {
Expand Down
42 changes: 0 additions & 42 deletions packages/scripts/src/locales/index.ts

This file was deleted.

2 changes: 0 additions & 2 deletions packages/scripts/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,4 @@ export interface CliOption {
* @link https://github.com/soybeanjs/changelog
*/
changelogOptions: Partial<ChangelogOption>
/** The ignore pattern list of git commit verify */
gitCommitVerifyIgnores: RegExp[]
}

0 comments on commit 87c1056

Please sign in to comment.