Skip to content

Instantly share code, notes, and snippets.

@IchrakMansour
Created May 26, 2020 07:33
Show Gist options
  • Save IchrakMansour/6664b6e6dd871616dc3eae024f5e209f to your computer and use it in GitHub Desktop.
Save IchrakMansour/6664b6e6dd871616dc3eae024f5e209f to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
'use strict';
// Makes the script crash on unhandled rejections instead of silently
// ignoring them. In the future, promise rejections that are not handled will
// terminate the Node.js process with a non-zero exit code.
process.on('unhandledRejection', err => {
throw err;
});
const spawn = require('react-dev-utils/crossSpawn');
const args = process.argv.slice(2);
const scriptIndex = args.findIndex(x => x === 'build' || x === 'start');
const script = scriptIndex === -1 ? args[0] : args[scriptIndex];
const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : [];
switch (script) {
case 'build':
case 'start': {
const result = spawn.sync(
'node',
nodeArgs
.concat(require.resolve(`./scripts/${script}-locale`))
.concat(args.slice(scriptIndex + 1)),
{ stdio: 'inherit' }
);
if (result.signal) {
if (result.signal === 'SIGKILL') {
console.log(
'The build failed because the process exited too early. ' +
'This probably means the system ran out of memory or someone called ' +
'`kill -9` on the process.'
);
} else if (result.signal === 'SIGTERM') {
console.log(
'The build failed because the process exited too early. ' +
'Someone might have called `kill` or `killall`, or the system could ' +
'be shutting down.'
);
}
process.exit(1);
}
process.exit(result.status);
break;
}
default:
console.log('Unknown script "' + script + '".');
break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment