Skip to content

Commit

Permalink
build: fail CI if native addon build fails
Browse files Browse the repository at this point in the history
Fixes: #63
PR-URL: #65
  • Loading branch information
aqrln authored and belochub committed Jan 22, 2018
1 parent eb533df commit 813fc1f
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions build-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ const fs = require('fs');
const childProcess = require('child_process');

const EXIT_SUCCESS = 0;
const EXIT_FAIL = 1;

const nodeGyp = childProcess.spawn('node-gyp', ['rebuild'], { shell: true });
const errorLines = [];

nodeGyp.on('error', showWarning);
nodeGyp.on('error', () => {
handleBuildError(EXIT_FAIL);
});

nodeGyp.stdout.pipe(process.stdout);

Expand All @@ -23,12 +26,16 @@ nodeGyp.on('exit', (code) => {
fs.writeFileSync('builderror.log', errorLines.join('\n'));
}
if (code !== EXIT_SUCCESS) {
showWarning();
handleBuildError(code);
}
process.exit();
});

function showWarning() {
console.warn('Could not build JSTP native extensions, ' +
'JavaScript implementation will be used instead.');
function handleBuildError(code) {
if (process.env.TRAVIS) {
process.exit(code);
} else {
console.warn('Could not build JSTP native extensions, ' +
'JavaScript implementation will be used instead.');
}
}

0 comments on commit 813fc1f

Please sign in to comment.