Skip to content

Commit

Permalink
feat(tools): add husky hook
Browse files Browse the repository at this point in the history
* add husky hook to check prettier, esling and stylelint.
* it also check the terraform linting.
  • Loading branch information
antoine-amara committed Mar 6, 2022
1 parent 0f0107e commit a7a47e4
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

make style
13 changes: 10 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
DC = docker-compose
YN = yarn
WEBSITE = website
DEPLOY = docker run -it --env-file ${PWD}/deploy/gcp/configs.env -v ${PWD}/deploy/gcp/:/deploy/ -v ${PWD}/dist/:/dist/ -w /deploy/ --rm staticpack-gcp-terraform:332.0.0-alpine
DEPLOY = docker run -t --env-file ${PWD}/deploy/gcp/configs.env -v ${PWD}/deploy/gcp/:/deploy/ -v ${PWD}/dist/:/dist/ -w /deploy/ --rm staticpack-gcp-terraform:332.0.0-alpine

default: help;

Expand All @@ -11,6 +11,8 @@ init: ## build, install dependencies and run the development environment. The en
${DC} up -d
${DC} ps
cp ./deploy/gcp/configs.env.dist ./deploy/gcp/configs.env
${MAKE} build-gcp-image
${MAKE} gcp-init

run: ## build the production bundle and run it.
${DC} run -p 3000:3000 --rm ${WEBSITE} ${YN} serve
Expand All @@ -30,9 +32,14 @@ clean: ## clean builded assets

check: style test ## run the linter to check code formating and unit tests to check javascripts libs.

style: ## run the linter and prettier to enforce code formating.
style: ## run the linter to check code formating.
${DC} run --rm -T ${WEBSITE} ${YN} lint
${DC} run --rm -T ${WEBSITE} ${YN} format
${DEPLOY} terraform validate

stylefix: ## run the linter and prettier to enforce code formating.
${DC} run --rm ${WEBSITE} ${YN} format
${DC} run --rm ${WEBSITE} ${YN} lint
${DC} run --rm ${WEBSITE} ${YN} lint:fix
${DEPLOY} terraform fmt -write=true -recursive .
${DEPLOY} terraform validate

Expand Down
16 changes: 11 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@
"package": "rm -f website.zip && yarn build && cd dist/ && bestzip ../website.zip *",
"build": "webpack --config webpack.prod.js",
"lint": "yarn lint:js && yarn lint:css",
"lint:js": "eslint --fix ./src/js/*.js",
"lint:css": "stylelint --fix 'src/css/*.css'",
"format": "prettier --write src",
"lint:js": "eslint ./src/js/*.js",
"lint:css": "stylelint 'src/css/*.css'",
"lint:fix": "yarn lint:js:fix && yarn lint:css:fix",
"lint:js:fix": "eslint --fix ./src/js/*.js",
"lint:css:fix": "stylelint --fix 'src/css/*.css'",
"format": "prettier --check src",
"format:fix": "prettier --write src",
"test": "jest --config=./jest.config.js src/",
"analyze-bundle": "yarn --silent build --profile --json > stats.json && webpack-bundle-analyzer stats.json ./dist/ -O -h 0.0.0.0 -p 9042"
"analyze-bundle": "yarn --silent build --profile --json > stats.json && webpack-bundle-analyzer stats.json ./dist/ -O -h 0.0.0.0 -p 9042",
"prepare": "husky install"
},
"devDependencies": {
"@babel/core": "^7.17.2",
Expand Down Expand Up @@ -59,7 +64,8 @@
"webpack-bundle-analyzer": "^4.5.0",
"webpack-cli": "^4.9.2",
"webpack-dev-server": "^4.7.4",
"webpack-merge": "^5.8.0"
"webpack-merge": "^5.8.0",
"husky": "^7.0.0"
},
"resolutions": {
"follow-redirects": "^1.14.8",
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4701,6 +4701,11 @@ human-signals@^2.1.0:
resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-2.1.0.tgz#dc91fcba42e4d06e4abaed33b3e7a3c02f514ea0"
integrity sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==

husky@^7.0.0:
version "7.0.4"
resolved "https://registry.yarnpkg.com/husky/-/husky-7.0.4.tgz#242048245dc49c8fb1bf0cc7cfb98dd722531535"
integrity sha512-vbaCKN2QLtP/vD4yvs6iz6hBEo6wkSzs8HpRah1Z6aGmF2KW5PdYuAd7uX5a+OyBZHBhd+TFLqgjUgytQr4RvQ==

iconv-lite@0.4.24:
version "0.4.24"
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b"
Expand Down

0 comments on commit a7a47e4

Please sign in to comment.