Skip to content

Commit e0410e5

Browse files
committed
chore: simple-git-hooks
1 parent bd5e4fd commit e0410e5

File tree

3 files changed

+41
-125
lines changed

3 files changed

+41
-125
lines changed

package.json

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@
5757
"test:unit": "vitest --coverage",
5858
"firebase:emulators": "firebase emulators:start",
5959
"test:dev": "vitest",
60-
"test": "pnpm run lint && pnpm run test:types && pnpm run build && pnpm run -C packages/nuxt build && pnpm run test:unit run"
60+
"test": "pnpm run lint && pnpm run test:types && pnpm run build && pnpm run -C packages/nuxt build && pnpm run test:unit run",
61+
"postinstall": "simple-git-hooks"
6162
},
6263
"keywords": [
6364
"vue",
@@ -107,22 +108,25 @@
107108
"p-series": "^3.0.0",
108109
"prettier": "^2.8.8",
109110
"semver": "^7.5.4",
111+
"simple-git-hooks": "^2.9.0",
110112
"typedoc": "^0.25.4",
111113
"typedoc-plugin-markdown": "^3.17.1",
112114
"typescript": "~5.3.3",
113115
"unbuild": "^2.0.0",
114116
"vitepress": "1.0.0-rc.31",
115117
"vitest": "^1.0.4",
116-
"vue": "^3.3.11",
117-
"yorkie": "^2.0.0"
118+
"vue": "^3.3.11"
118119
},
119-
"gitHooks": {
120-
"pre-commit": "lint-staged",
120+
"simple-git-hooks": {
121+
"pre-commit": "pnpm lint-staged",
121122
"commit-msg": "node scripts/verifyCommit.mjs"
122123
},
123124
"lint-staged": {
124-
"*.(j|t)s": [
125+
"*.{js,mjs,json,cjs}": [
125126
"prettier --write"
127+
],
128+
"*.ts?(x)": [
129+
"prettier --parser=typescript --write"
126130
]
127131
},
128132
"repository": {

pnpm-lock.yaml

Lines changed: 9 additions & 90 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/verifyCommit.mjs

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,27 @@
1-
// Invoked on the commit-msg git hook by yorkie.
1+
// @ts-check
2+
import { readFileSync } from 'node:fs'
3+
import path from 'node:path'
24

3-
import chalk from 'chalk'
4-
const msgPath = process.env.GIT_PARAMS
5-
import { readFile } from 'fs/promises'
5+
// Define raw escape codes for colors
6+
const reset = '\x1b[0m'
7+
const red = '\x1b[31m'
8+
const green = '\x1b[32m'
9+
const bgRedWhite = '\x1b[41m\x1b[37m'
610

7-
async function main() {
8-
const msg = (await readFile(msgPath, 'utf-8')).trim()
11+
const msgPath = path.resolve('.git/COMMIT_EDITMSG')
12+
const msg = readFileSync(msgPath, 'utf-8').trim()
913

10-
const commitRE =
11-
/^(revert: )?(feat|fix|docs|dx|style|refactor|perf|test|workflow|build|ci|chore|types|wip|release)(\(.+\))?: .{1,50}/
14+
const commitRE =
15+
/^(revert: )?(feat|fix|docs|dx|style|refactor|perf|test|workflow|build|ci|chore|types|wip|release)(\(.+\))?: .{1,50}/
1216

13-
if (!commitRE.test(msg)) {
14-
console.log()
15-
console.error(
16-
` ${chalk.bgRed.white(' ERROR ')} ${chalk.red(
17-
`invalid commit message format.`
18-
)}\n\n` +
19-
chalk.red(
20-
` Proper commit message format is required for automated changelog generation. Examples:\n\n`
21-
) +
22-
` ${chalk.green(
23-
`fix(view): handle keep-alive with aborted navigations`
24-
)}\n` +
25-
` ${chalk.green(
26-
`fix(view): handle keep-alive with aborted navigations (close #28)`
27-
)}\n\n` +
28-
chalk.red(` See .github/commit-convention.md for more details.\n`)
29-
)
30-
process.exit(1)
31-
}
17+
if (!commitRE.test(msg)) {
18+
console.log()
19+
console.error(
20+
` ${bgRedWhite} ERROR ${reset} ${red}invalid commit message format.${reset}\n\n` +
21+
`${red} Proper commit message format is required for automated changelog generation. Examples:\n\n` +
22+
` ${green}feat: add disableRoot option${reset}\n` +
23+
` ${green}fix(view): handle keep-alive with aborted navigations (close #28)${reset}\n\n` +
24+
`${red} See .github/commit-convention.md for more details.${reset}\n`
25+
)
26+
process.exit(1)
3227
}
33-
34-
main()

0 commit comments

Comments
 (0)