Skip to content

Commit

Permalink
build: simple git hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Dec 30, 2023
1 parent ef737f8 commit 5dcde0b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 145 deletions.
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"test:vitest": "vitest --coverage",
"test:types": "tsc --build ./tsconfig.json",
"test:dts": "pnpm run -r test:dts",
"docs:api": "pnpm run --filter ./packages/docs -r docs:api"
"docs:api": "pnpm run --filter ./packages/docs -r docs:api",
"postinstall": "simple-git-hooks"
},
"devDependencies": {
"@rollup/plugin-alias": "^5.1.0",
Expand Down Expand Up @@ -47,19 +48,19 @@
"rollup": "^4.2.0",
"rollup-plugin-typescript2": "^0.36.0",
"semver": "^7.5.4",
"simple-git-hooks": "^2.9.0",
"typedoc": "^0.25.3",
"typedoc-plugin-markdown": "^3.17.0",
"typescript": "^5.2.2",
"vitest": "^0.34.6",
"vue": "^3.3.11",
"yorkie": "^2.0.0"
"vue": "^3.3.11"
},
"gitHooks": {
"pre-commit": "lint-staged",
"simple-git-hooks": {
"pre-commit": "pnpm lint-staged",
"commit-msg": "node scripts/verifyCommit.mjs"
},
"lint-staged": {
"*.js": [
"*.{js,mjs,json,cjs}": [
"prettier --write"
],
"*.ts?(x)": [
Expand Down
131 changes: 9 additions & 122 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 15 additions & 17 deletions scripts/verifyCommit.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
// Invoked on the commit-msg git hook by yorkie.

import chalk from 'chalk'
// @ts-check
import { readFileSync } from 'node:fs'
const msgPath = process.env.GIT_PARAMS
import path from 'node:path'

// Define raw escape codes for colors
const reset = '\x1b[0m'
const red = '\x1b[31m'
const green = '\x1b[32m'
const bgRedWhite = '\x1b[41m\x1b[37m'

const msgPath = path.resolve('.git/COMMIT_EDITMSG')
const msg = readFileSync(msgPath, 'utf-8').trim()

const commitRE =
Expand All @@ -11,19 +17,11 @@ const commitRE =
if (!commitRE.test(msg)) {
console.log()
console.error(
` ${chalk.bgRed.white(' ERROR ')} ${chalk.red(
`invalid commit message format.`
)}\n\n` +
chalk.red(
` Proper commit message format is required for automated changelog generation. Examples:\n\n`
) +
` ${chalk.green(
`fix(view): handle keep-alive with aborted navigations`
)}\n` +
` ${chalk.green(
`fix(view): handle keep-alive with aborted navigations (close #28)`
)}\n\n` +
chalk.red(` See .github/commit-convention.md for more details.\n`)
` ${bgRedWhite} ERROR ${reset} ${red}invalid commit message format.${reset}\n\n` +
`${red} Proper commit message format is required for automated changelog generation. Examples:\n\n` +
` ${green}feat: add disableRoot option${reset}\n` +
` ${green}fix(view): handle keep-alive with aborted navigations (close #28)${reset}\n\n` +
`${red} See .github/commit-convention.md for more details.${reset}\n`
)
process.exit(1)
}

0 comments on commit 5dcde0b

Please sign in to comment.