Skip to content

Commit d0e404c

Browse files
committed
build(npm): setup git hooks and linters
1 parent d56c10b commit d0e404c

File tree

4 files changed

+56
-2
lines changed

4 files changed

+56
-2
lines changed

Diff for: .prettierrc

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"trailingComma": "es5",
3+
"tabWidth": 2,
4+
"semi": true,
5+
"singleQuote": true,
6+
"parser": "typescript"
7+
}

Diff for: commitlint.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = { extends: ['@commitlint/config-conventional'] };

Diff for: hooks/update-dependencies.sh

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
# MIT © Sindre Sorhus - sindresorhus.com
3+
4+
# git hook to run a command after `git pull` if a specified file was changed
5+
# Run `chmod +x post-merge` to make it executable then put it into `.git/hooks/`.
6+
7+
changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)"
8+
9+
check_run() {
10+
echo "$changed_files" | grep --quiet "$1" && eval "$2"
11+
}
12+
13+
check_run package.json "echo \"Updated package.json found, updating node_modules\" && npm install && npm prune"

Diff for: package.json

+35-2
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,18 @@
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
77
"scripts": {
8-
"test": "echo \"Error: no test specified\" && exit 1",
8+
"test": "run-s build:noemit",
99
"build": "tsc",
10+
"build:noemit": "tsc --noEmit",
1011
"postbuild": "npm shrinkwrap",
1112
"docs": "typedoc --options typedoc.json",
1213
"postinstall": "node scripts/not-for-production-warning.js",
1314
"clean": "rimraf ./dist",
14-
"prepack": "run-s clean build"
15+
"prepack": "run-s clean build",
16+
"lint-staged": "lint-staged",
17+
"cm": "git-cz",
18+
"release": "HUSKY_SKIP_HOOKS=1 standard-version",
19+
"reset-dependencies": "bash ./hooks/update-dependencies"
1520
},
1621
"publishConfig": {
1722
"access": "public"
@@ -30,10 +35,18 @@
3035
"LICENSE"
3136
],
3237
"devDependencies": {
38+
"@commitlint/cli": "^8.0.0",
39+
"@commitlint/config-conventional": "^8.0.0",
3340
"@types/debug": "^4.1.3",
3441
"all-contributors-cli": "^6.7.0",
42+
"commitizen": "^3.1.1",
43+
"cz-conventional-changelog": "^2.1.0",
44+
"husky": "^3.0.0",
45+
"lint-staged": "^8.2.1",
3546
"npm-run-all": "^4.1.5",
47+
"prettier": "^1.18.2",
3648
"rimraf": "^2.6.3",
49+
"standard-version": "^6.0.1",
3750
"typedoc": "^0.14.2",
3851
"typedoc-plugin-external-module-name": "^2.0.0",
3952
"typescript": "^3.4.2"
@@ -49,5 +62,25 @@
4962
"mime-types": "^2.1.22",
5063
"recursive-readdir": "^2.2.2",
5164
"type-fest": "^0.3.0"
65+
},
66+
"husky": {
67+
"hooks": {
68+
"pre-commit": "run-s lint-staged test",
69+
"prepare-commit-msg": "exec < /dev/tty && git-cz --hook",
70+
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
71+
"post-checkout": "reset-dependencies",
72+
"post-merge": "reset-dependencies"
73+
}
74+
},
75+
"lint-staged": {
76+
"*.{js,jsx,ts,tsx}": [
77+
"prettier --write",
78+
"git add"
79+
]
80+
},
81+
"config": {
82+
"commitizen": {
83+
"path": "./node_modules/cz-conventional-changelog"
84+
}
5285
}
5386
}

0 commit comments

Comments
 (0)