From f5b5299aa2e48437298cbe57dd552508adb0e806 Mon Sep 17 00:00:00 2001 From: Marcy Sutton Date: Tue, 12 Sep 2017 11:42:14 -0700 Subject: [PATCH] fix(postinstall): use node, more conditionals (#520) * fix(postinstall): use node, more conditionals Closes https://github.com/dequelabs/axe-core/issues/516 * chore: move fs-extra to devDependencies --- bin/postinstall.sh | 8 -------- build/utils/postinstall.js | 15 +++++++++++++++ package.json | 3 ++- 3 files changed, 17 insertions(+), 9 deletions(-) delete mode 100755 bin/postinstall.sh create mode 100644 build/utils/postinstall.js diff --git a/bin/postinstall.sh b/bin/postinstall.sh deleted file mode 100755 index 72db42e15a..0000000000 --- a/bin/postinstall.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh - -if [ -d ".git/hooks" ]; then - if [ ! -f ".git/hooks/commit-msg" ]; then - echo "Installing pre-commit hook" - cd .git/hooks/ && cp ../../node_modules/angular-precommit/index.js commit-msg && cd ../../ - fi -fi \ No newline at end of file diff --git a/build/utils/postinstall.js b/build/utils/postinstall.js new file mode 100644 index 0000000000..6beaea9bb5 --- /dev/null +++ b/build/utils/postinstall.js @@ -0,0 +1,15 @@ +var fs = require('fs') + +if (fs.existsSync(".git/hooks")) { + let commitMsg = '.git/hooks/commit-msg' + if (!fs.existsSync(commitMsg)) { + let angularPrecommit = "./node_modules/angular-precommit/index.js" + if (fs.existsSync(angularPrecommit)) { + var fsExtra = require('fs-extra') + fsExtra.copy(angularPrecommit, commitMsg, (err) => { + if (err) throw err + console.log("Installing git pre-commit hook") + }) + } + } +} \ No newline at end of file diff --git a/package.json b/package.json index 1258744367..ccd6306b9a 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "test-fast": "grunt test-fast", "version": "node build/sri-update", "prepublishOnly": "grunt build && node build/sri-update --validate", - "postinstall": "./bin/postinstall.sh", + "postinstall": "node build/utils/postinstall.js", "release": "standard-version" }, "devDependencies": { @@ -65,6 +65,7 @@ "chai": "~3.5.0", "clone": "~1.0.2", "dot": "~1.0.3", + "fs-extra": "^4.0.1", "grunt": "^1.0.1", "grunt-babel": "^6.0.0", "grunt-contrib-clean": "^1.0.0",