MCPcopy
hub / github.com/callstack/haul / addHaulScript

Function addHaulScript

packages/haul-cli/src/commands/init.ts:264–308  ·  view source on GitHub ↗
(progress: Ora, cwd: string)

Source from the content-addressed store, hash-verified

262}
263
264async 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
310async function installDependencies(
311 progress: Ora,

Callers 1

handlerFunction · 0.85

Calls 3

delayFunction · 0.85
stringifyMethod · 0.80
startMethod · 0.65

Tested by

no test coverage detected