Use pre-push hook instead of pre-commit

This commit is contained in:
Bartek Fabiszewski 2020-04-11 21:31:55 +02:00
parent 4a66630a00
commit 569303651e
2 changed files with 9 additions and 29 deletions

View File

@ -17,32 +17,15 @@
* along with this program; if not, see <http://www.gnu.org/licenses/>. * along with this program; if not, see <http://www.gnu.org/licenses/>.
*/ */
const fs = require('fs');
const crypto = require('crypto');
const exec = require('child_process').execSync; const exec = require('child_process').execSync;
const getBundleHash = () => { const sourcesModified = () => {
const distDir = 'js/dist/'; const lastBuildCommit = exec('git log -1 --pretty="format:%H" js/dist/*bundle*js*').toString();
const hash = crypto.createHash('sha1'); const output = exec(`git diff --name-only ${lastBuildCommit} HEAD js/src`).toString();
fs.readdirSync(distDir) return !!output && output.split('\n').length > 0;
.filter(path => path.endsWith('.js'))
.sort()
.forEach(path => {
hash.update(fs.readFileSync(distDir + path));
});
return hash.digest('hex');
}; };
const main = () => { if (sourcesModified()) {
const bundleHash = getBundleHash(); console.log('\nPlease update and commit distribution bundle first!\nYou may still push using --no-verify option.\n');
try { process.exitCode = 1;
exec('npm run build'); }
if (getBundleHash() !== bundleHash) {
exec('git add js/dist/*');
}
} catch (e) {
console.log('Warning: build failed!');
}
};
main();

View File

@ -88,10 +88,7 @@
], ],
"husky": { "husky": {
"hooks": { "hooks": {
"pre-commit": "lint-staged" "pre-push": "node .githooks/build-status.js"
} }
},
"lint-staged": {
"js/src/**/*.js": "node .githooks/build-staged.js"
} }
} }