Skip to content

Commit

Permalink
feat: add husky, commitlint, lint-staged (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
lamngockhuong authored Jun 7, 2024
1 parent 2852654 commit 7ec0125
Show file tree
Hide file tree
Showing 12 changed files with 780 additions and 49 deletions.
1 change: 1 addition & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pnpm dlx commitlint --edit $1
6 changes: 6 additions & 0 deletions .husky/install.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Skip Husky install in production and CI
if (process.env.NODE_ENV === 'production' || process.env.CI === 'true') {
process.exit(0)
}
const husky = (await import('husky')).default
console.log(husky())
16 changes: 16 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env sh

BRANCH=$(git rev-parse --abbrev-ref HEAD)
REGEX="^(feature|bugfix|hotfix|release|merge)\.([a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*)$"

RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'
echo "Branch name: ${GREEN}$BRANCH${NC}"
if ! echo "$BRANCH" | grep -qE "$REGEX"; then
echo "${RED}Your commit was rejected due to branching name"
echo "Please rename your branch with '(feature|bugfix|hotfix|release|merge)(.<ticket>?).<subject-example>' syntax${NC}"
exit 1
fi

pnpm lint-staged
12 changes: 12 additions & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env sh
GREEN='\033[0;32m'
BLUE='\033[0;34m'
NC='\033[0m'
changed_files=$(git diff --name-only HEAD HEAD~ -- '*.ts' '*.js')
if [ -n "$changed_files" ]; then
echo "${BLUE}Running tests due to changes in the following TS/JS files:${NC}"
echo "$changed_files"
pnpm test
else
echo "${GREEN}No TS/JS files have been changed. Skipping tests.${NC}"
fi
1 change: 1 addition & 0 deletions commitlint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default { extends: ['@commitlint/config-conventional'] };
6 changes: 6 additions & 0 deletions lint-staged.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
'*.ts': [
'pnpm lint',
'pnpm format'
],
};
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json",
"typeorm": ""
"typeorm": "",
"prepare": "husky"
},
"dependencies": {
"@nestjs/common": "10.3.9",
Expand All @@ -29,7 +30,9 @@
"rxjs": "7.8.1"
},
"devDependencies": {
"@eslint/js": "^9.4.0",
"@commitlint/cli": "19.3.0",
"@commitlint/config-conventional": "19.2.2",
"@eslint/js": "9.4.0",
"@nestjs/cli": "10.3.2",
"@nestjs/schematics": "10.1.1",
"@nestjs/testing": "10.3.9",
Expand All @@ -42,7 +45,9 @@
"eslint": "9.4.0",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-prettier": "5.1.3",
"husky": "9.0.11",
"jest": "29.7.0",
"lint-staged": "15.2.5",
"prettier": "3.3.1",
"source-map-support": "0.5.21",
"supertest": "7.0.0",
Expand Down
Loading

0 comments on commit 7ec0125

Please sign in to comment.