const spawn = require('cross-spawn');
const script = process.argv[2];
const args = process.argv.slice(3);

switch (script) {
  case 'build':
  case 'start':
  case 'test': {
    const { status } = spawn.sync(
      'node',
      [require.resolve(`../scripts/${script}`)].concat(args),
      { stdio: 'inherit' }
    );
    process.exit(status);
    break;
  }
  case 'eject': {
    const { status } = spawn.sync(
      'node',
      [require.resolve(`./${script}`)].concat(args),
      { stdio: 'inherit' }
    );
    process.exit(status);
    break;
  }
  default:
    console.log(`Unknown script "${script}".`);
    break;
}

const spawn = require('cross-spawn');
const script = process.argv[2];
const args = process.argv.slice(3);

const run = script => {
  const { status } = spawn.sync(
    'node',
    [require.resolve(script)].concat(args),
    { stdio: 'inherit' }
  );
  process.exit(status);
};

switch (script) {
  case 'build':
  case 'start':
  case 'test': {
    run(`../scripts/${script}`);
    break;
  }
  case 'eject': {
    run(`./${script}`);
    break;
  }
  default:
    console.log(`Unknown script "${script}".`);
    break;
}

Use run method to remove duplicate codes
Use run method to remove duplicate codes
