| 262 | } |
| 263 | |
| 264 | async function addHaulScript(progress: Ora, cwd: string): Promise<string> { |
| 265 | const packageJson = require(path.join(cwd, 'package.json')); |
| 266 | const scripts = packageJson.scripts || {}; |
| 267 | const haulScript = Object.keys(scripts).find( |
| 268 | name => scripts[name] === 'haul' |
| 269 | ); |
| 270 | |
| 271 | if (haulScript) { |
| 272 | progress.info('Haul already exists in your package.json.'); |
| 273 | return haulScript; |
| 274 | } |
| 275 | |
| 276 | let scriptName = 'start'; |
| 277 | if ( |
| 278 | scripts.start && |
| 279 | scripts.start !== 'node node_modules/react-native/local-cli/cli.js start' |
| 280 | ) { |
| 281 | const result = (await inquirer.prompt([ |
| 282 | { |
| 283 | type: 'input', |
| 284 | name: 'scriptName', |
| 285 | message: |
| 286 | 'Enter the name of the script to add to package.json, e.g. `haul` for `yarn run haul`', |
| 287 | default: 'haul', |
| 288 | }, |
| 289 | ])) as { scriptName: string }; |
| 290 | |
| 291 | scriptName = result.scriptName; |
| 292 | } |
| 293 | |
| 294 | packageJson.scripts = Object.assign({}, scripts, { |
| 295 | [scriptName]: 'haul start', |
| 296 | }); |
| 297 | |
| 298 | progress.start(`Adding \`${scriptName}\` script to your package.json`); |
| 299 | |
| 300 | await delay(1000); |
| 301 | |
| 302 | fs.writeFileSync( |
| 303 | path.join(cwd, 'package.json'), |
| 304 | JSON.stringify(packageJson, null, 2) |
| 305 | ); |
| 306 | |
| 307 | return scriptName; |
| 308 | } |
| 309 | |
| 310 | async function installDependencies( |
| 311 | progress: Ora, |