diff --git a/.githooks/build-staged.js b/.githooks/build-status.js similarity index 56% rename from .githooks/build-staged.js rename to .githooks/build-status.js index cbfefcf..1c8a3b5 100644 --- a/.githooks/build-staged.js +++ b/.githooks/build-status.js @@ -17,32 +17,15 @@ * along with this program; if not, see . */ -const fs = require('fs'); -const crypto = require('crypto'); const exec = require('child_process').execSync; -const getBundleHash = () => { - const distDir = 'js/dist/'; - const hash = crypto.createHash('sha1'); - fs.readdirSync(distDir) - .filter(path => path.endsWith('.js')) - .sort() - .forEach(path => { - hash.update(fs.readFileSync(distDir + path)); - }); - return hash.digest('hex'); +const sourcesModified = () => { + const lastBuildCommit = exec('git log -1 --pretty="format:%H" js/dist/*bundle*js*').toString(); + const output = exec(`git diff --name-only ${lastBuildCommit} HEAD js/src`).toString(); + return !!output && output.split('\n').length > 0; }; -const main = () => { - const bundleHash = getBundleHash(); - try { - exec('npm run build'); - if (getBundleHash() !== bundleHash) { - exec('git add js/dist/*'); - } - } catch (e) { - console.log('Warning: build failed!'); - } -}; - -main(); +if (sourcesModified()) { + console.log('\nPlease update and commit distribution bundle first!\nYou may still push using --no-verify option.\n'); + process.exitCode = 1; +} diff --git a/package.json b/package.json index cd8980d..1d5ffd9 100644 --- a/package.json +++ b/package.json @@ -88,10 +88,7 @@ ], "husky": { "hooks": { - "pre-commit": "lint-staged" + "pre-push": "node .githooks/build-status.js" } - }, - "lint-staged": { - "js/src/**/*.js": "node .githooks/build-staged.js" } }