|
| 1 | +#!/usr/bin/env; |
| 2 | +const spawn = require('react-dev-utils/crossSpawn'); |
| 3 | +const chalk = require('react-dev-utils/chalk'); |
| 4 | +const args = process.argv.slice(2); |
| 5 | + |
| 6 | +const scriptIndex = args.findIndex( |
| 7 | + (x) => x === 'build' || x === 'start' || x === 'test' || x === 'eject' |
| 8 | +); |
| 9 | +const script = scriptIndex === -1 ? args[0] : args[scriptIndex]; |
| 10 | +const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : []; |
| 11 | + |
| 12 | +switch (script) { |
| 13 | + case 'build': |
| 14 | + case 'start': { |
| 15 | + const result = spawn.sync( |
| 16 | + 'node', |
| 17 | + nodeArgs |
| 18 | + .concat(require.resolve(`../scripts/${script}`)) |
| 19 | + .concat(args.slice(scriptIndex + 1)), |
| 20 | + { stdio: 'inherit' } |
| 21 | + ); |
| 22 | + |
| 23 | + if (result.signal) { |
| 24 | + if (result.signal === 'SIGKILL') { |
| 25 | + console.log('The build failed because the process exited too early.'); |
| 26 | + console.log( |
| 27 | + 'This probably means the system ran out of memory or someone called kill -9` on the process.' |
| 28 | + ); |
| 29 | + } |
| 30 | + if (result.signal === 'SIGTERM') { |
| 31 | + console.log('The build failed because the process exited too early.'); |
| 32 | + console.log( |
| 33 | + 'Someone might have called `kill` or `killall`, or the system could be shutting down.' |
| 34 | + ); |
| 35 | + } |
| 36 | + process.exit(1); |
| 37 | + } |
| 38 | + |
| 39 | + process.exit(result.status); |
| 40 | + break; |
| 41 | + } |
| 42 | + case 'test': { |
| 43 | + console.log('This is not supported by us, you should just use:'); |
| 44 | + console.log('react-scripts test, in your npm package.json'); |
| 45 | + break; |
| 46 | + } |
| 47 | + case 'eject': { |
| 48 | + console.log('This is not supported by us, you should just use:'); |
| 49 | + console.log('react-scripts eject, in your npm package.json'); |
| 50 | + break; |
| 51 | + } |
| 52 | + default: { |
| 53 | + console.log(`Unknown script ${chalk.green(script)}.`); |
| 54 | + console.log('Kindly ensure you have the latest react-scripts installed'); |
| 55 | + console.log(`${chalk.green('Go to this link:')}`); |
| 56 | + console.log('https://create-react-app.dev/docs/updating-to-new-releases'); |
| 57 | + } |
| 58 | +} |
0 commit comments