Browse Source

add pre-commit hook

Evan You 9 years ago
parent
commit
ea61d9878f
3 changed files with 17 additions and 1 deletions
  1. 8 0
      .github/CONTRIBUTING.md
  2. 7 0
      build/git-hooks/pre-commit
  3. 2 1
      package.json

+ 8 - 0
.github/CONTRIBUTING.md

@@ -59,6 +59,14 @@ After cloning the repo, run:
 $ npm install
 ```
 
+If you are on a Unix-like system, optionally install the Git pre-commit hook with:
+
+``` bash
+$ npm run install:hooks
+```
+
+This will run Flow and ESLint on changed files before each commit.
+
 ### Commonly used NPM scripts
 
 ``` bash

+ 7 - 0
build/git-hooks/pre-commit

@@ -0,0 +1,7 @@
+#!/usr/bin/env bash
+
+files_to_lint=$(git diff --cached --name-only --diff-filter=ACM | grep '\.js$')
+
+if [ -n "$files_to_lint" ]; then
+  flow && NODE_ENV=production eslint $files_to_lint
+fi

+ 2 - 1
package.json

@@ -42,7 +42,8 @@
     "sauce": "SAUCE=true karma start build/karma.sauce.config.js",
     "bench:ssr": "npm run build:ssr && NODE_ENV=production node benchmarks/ssr/renderToString.js && NODE_ENV=production VUE_ENV=server node benchmarks/ssr/renderToStream.js",
     "release": "bash build/release.sh",
-    "release:weex": "bash build/release-weex.sh"
+    "release:weex": "bash build/release-weex.sh",
+    "install:hooks": "ln -fs ../../build/git-hooks/pre-commit .git/hooks/pre-commit"
   },
   "repository": {
     "type": "git",