Skip to content

Commit

Permalink
build: fail CI if native addon build fails
Browse files Browse the repository at this point in the history
  • Loading branch information
aqrln committed Feb 10, 2017
1 parent 521b00d commit 1c5dd37
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 1c5dd37

Please sign in to comment.