From 33b135518ec35e26291c508d2ca1210f15efe600 Mon Sep 17 00:00:00 2001 From: Vinayak Kulkarni <19776877+vinayakkulkarni@users.noreply.github.com> Date: Tue, 20 Sep 2022 13:14:46 +0530 Subject: [PATCH] feat: add `husky` & `commitlint` Signed-off-by: Vinayak Kulkarni <19776877+vinayakkulkarni@users.noreply.github.com> --- .husky/commit-msg | 21 +++++++++++++++++++++ .husky/pre-push | 4 ++++ commitlint.config.cjs | 3 +++ lint-staged.config.cjs | 4 ++++ package.json | 10 +++++++--- 5 files changed, 39 insertions(+), 3 deletions(-) create mode 100755 .husky/commit-msg create mode 100755 .husky/pre-push create mode 100644 commitlint.config.cjs create mode 100644 lint-staged.config.cjs diff --git a/.husky/commit-msg b/.husky/commit-msg new file mode 100755 index 0000000..ff455dc --- /dev/null +++ b/.husky/commit-msg @@ -0,0 +1,21 @@ +#!/bin/sh +. "$(dirname "$0")/_/husky.sh" + +NAME=$(git config user.name) +EMAIL=$(git config user.email) + +if [ -z "$NAME" ]; then + echo "empty git config user.name" + exit 1 +fi + +if [ -z "$EMAIL" ]; then + echo "empty git config user.email" + exit 1 +fi + +git interpret-trailers --if-exists doNothing --trailer \ + "Signed-off-by: $NAME <$EMAIL>" \ + --in-place "$1" + +npm exec --no -- commitlint --edit $1 diff --git a/.husky/pre-push b/.husky/pre-push new file mode 100755 index 0000000..1aa95fe --- /dev/null +++ b/.husky/pre-push @@ -0,0 +1,4 @@ +#!/bin/sh +. "$(dirname "$0")/_/husky.sh" + +npm exec --no -- lint-staged --no-stash diff --git a/commitlint.config.cjs b/commitlint.config.cjs new file mode 100644 index 0000000..84dcb12 --- /dev/null +++ b/commitlint.config.cjs @@ -0,0 +1,3 @@ +module.exports = { + extends: ['@commitlint/config-conventional'], +}; diff --git a/lint-staged.config.cjs b/lint-staged.config.cjs new file mode 100644 index 0000000..0c8d50d --- /dev/null +++ b/lint-staged.config.cjs @@ -0,0 +1,4 @@ +module.exports = { + '*.{js,ts}': 'npm run lint:js', + '*.{yml}': 'npm run lint:yml', +}; diff --git a/package.json b/package.json index 1bc6f4a..a898016 100644 --- a/package.json +++ b/package.json @@ -8,11 +8,12 @@ "scripts": { "test": "mocha test/**.js --timeout 10000", "lint:yml": "yamllint --schema=CORE_SCHEMA *.{yml,yaml}", + "lint:js": "npm run lint:prettier", + "lint:js:fix": "npm run lint:prettier:fix", "lint:prettier": "prettier --check \"{,!(node_modules|dist|static)/**/}*.{js,ts,cjs,mjs,json}\" --ignore-path .gitignore", "lint:prettier:fix": "prettier --write \"{,!(node_modules|dist|static)/**/}*.{js,ts,cjs,mjs,json}\" --ignore-path .gitignore", - "lint": "npm run lint:prettier", - "lintfix": "npm run lint:prettier:fix", - "docker": "docker build -f Dockerfile . && docker run --rm -i -p 8080:80 $(docker build -q .)" + "docker": "docker build -f Dockerfile . && docker run --rm -i -p 8080:80 $(docker build -q .)", + "prepare": "husky install" }, "dependencies": { "@mapbox/glyph-pbf-composite": "0.0.3", @@ -40,7 +41,10 @@ "sanitize-filename": "1.6.3" }, "devDependencies": { + "@commitlint/cli": "^17.1.2", + "@commitlint/config-conventional": "^17.1.0", "chai": "4.3.6", + "husky": "^8.0.1", "mocha": "^10.0.0", "prettier": "^2.7.1", "should": "^13.2.3",