From b5f08f3bed95e6cac47b20d3fa4148d00ffa8c55 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 17 Jun 2017 19:21:00 +0800 Subject: [PATCH] build: use cross-platform hook installation with shelljs --- .github/CONTRIBUTING.md | 5 ++++- build/install-hooks.js | 8 ++++++++ build/install-hooks.sh | 6 ------ package.json | 3 ++- yarn.lock | 8 ++++++++ 5 files changed, 22 insertions(+), 8 deletions(-) create mode 100644 build/install-hooks.js delete mode 100644 build/install-hooks.sh diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index f96c3241..555a41fb 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -43,7 +43,10 @@ After cloning the repo, run: $ npm install ``` -This would also run the `postinstall` script which will link git commit hooks if you are on a Unix-like system. +This will also run the `postinstall` script which links two git hooks: + +- `pre-commit`: runs ESLint on staged files. +- `commit-msg`: validates commit message format (see below). ### Commiting Changes diff --git a/build/install-hooks.js b/build/install-hooks.js new file mode 100644 index 00000000..e5f8ad84 --- /dev/null +++ b/build/install-hooks.js @@ -0,0 +1,8 @@ +const { test, ln, chmod } = require('shelljs') + +if (test('-e', '.git/hooks')) { + ln('-sf', '../../build/git-hooks/pre-commit', '.git/hooks/pre-commit') + chmod('+x', '.git/hooks/pre-commit') + ln('-sf', '../../build/git-hooks/commit-msg', '.git/hooks/commit-msg') + chmod('+x', '.git/hooks/commit-msg') +} diff --git a/build/install-hooks.sh b/build/install-hooks.sh deleted file mode 100644 index 2e6fc6d6..00000000 --- a/build/install-hooks.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash - -if test -e .git/hooks; then - ln -sf ../../build/git-hooks/pre-commit .git/hooks/pre-commit && chmod +x .git/hooks/pre-commit - ln -sf ../../build/git-hooks/commit-msg .git/hooks/commit-msg && chmod +x .git/hooks/commit-msg -fi diff --git a/package.json b/package.json index 926978e5..9abe3327 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "release": "bash build/release.sh", "release:weex": "bash build/release-weex.sh", "release:note": "node build/gen-release-note.js", - "postinstall": "bash build/install-hooks.sh", + "postinstall": "node build/install-hooks.js", "commit": "git-cz" }, "repository": { @@ -117,6 +117,7 @@ "rollup-watch": "^4.0.0", "selenium-server": "^2.53.1", "serialize-javascript": "^1.3.0", + "shelljs": "^0.7.8", "typescript": "^2.3.4", "uglify-js": "^3.0.15", "webpack": "^2.6.1", diff --git a/yarn.lock b/yarn.lock index 69acfff5..aadf345a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4824,6 +4824,14 @@ shelljs@0.7.6, shelljs@^0.7.5: interpret "^1.0.0" rechoir "^0.6.2" +shelljs@^0.7.8: + version "0.7.8" + resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.7.8.tgz#decbcf874b0d1e5fb72e14b164a9683048e9acb3" + dependencies: + glob "^7.0.0" + interpret "^1.0.0" + rechoir "^0.6.2" + signal-exit@^3.0.0: version "3.0.2" resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"