Skip to content

Commit b5f08f3

Browse files
committed
build: use cross-platform hook installation with shelljs
1 parent 610d1aa commit b5f08f3

File tree

5 files changed

+22
-8
lines changed

5 files changed

+22
-8
lines changed

.github/CONTRIBUTING.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ After cloning the repo, run:
4343
$ npm install
4444
```
4545

46-
This would also run the `postinstall` script which will link git commit hooks if you are on a Unix-like system.
46+
This will also run the `postinstall` script which links two git hooks:
47+
48+
- `pre-commit`: runs ESLint on staged files.
49+
- `commit-msg`: validates commit message format (see below).
4750

4851
### Commiting Changes
4952

build/install-hooks.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const { test, ln, chmod } = require('shelljs')
2+
3+
if (test('-e', '.git/hooks')) {
4+
ln('-sf', '../../build/git-hooks/pre-commit', '.git/hooks/pre-commit')
5+
chmod('+x', '.git/hooks/pre-commit')
6+
ln('-sf', '../../build/git-hooks/commit-msg', '.git/hooks/commit-msg')
7+
chmod('+x', '.git/hooks/commit-msg')
8+
}

build/install-hooks.sh

-6
This file was deleted.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"release": "bash build/release.sh",
3939
"release:weex": "bash build/release-weex.sh",
4040
"release:note": "node build/gen-release-note.js",
41-
"postinstall": "bash build/install-hooks.sh",
41+
"postinstall": "node build/install-hooks.js",
4242
"commit": "git-cz"
4343
},
4444
"repository": {
@@ -117,6 +117,7 @@
117117
"rollup-watch": "^4.0.0",
118118
"selenium-server": "^2.53.1",
119119
"serialize-javascript": "^1.3.0",
120+
"shelljs": "^0.7.8",
120121
"typescript": "^2.3.4",
121122
"uglify-js": "^3.0.15",
122123
"webpack": "^2.6.1",

yarn.lock

+8
Original file line numberDiff line numberDiff line change
@@ -4824,6 +4824,14 @@ [email protected], shelljs@^0.7.5:
48244824
interpret "^1.0.0"
48254825
rechoir "^0.6.2"
48264826

4827+
shelljs@^0.7.8:
4828+
version "0.7.8"
4829+
resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.7.8.tgz#decbcf874b0d1e5fb72e14b164a9683048e9acb3"
4830+
dependencies:
4831+
glob "^7.0.0"
4832+
interpret "^1.0.0"
4833+
rechoir "^0.6.2"
4834+
48274835
signal-exit@^3.0.0:
48284836
version "3.0.2"
48294837
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"

0 commit comments

Comments
 (0)