|
10 | 10 | 'use strict';
|
11 | 11 |
|
12 | 12 | const yargs = require('yargs');
|
13 |
| -const {execSync, spawnSync} = require('child_process'); |
| 13 | +const {execSync} = require('child_process'); |
14 | 14 |
|
15 | 15 | const forEachPackage = require('../monorepo/for-each-package');
|
16 | 16 | const setupVerdaccio = require('../setup-verdaccio');
|
| 17 | +const {retry} = require('../circleci/retry'); |
17 | 18 |
|
18 | 19 | const {argv} = yargs
|
19 | 20 | .option('r', {
|
@@ -42,54 +43,69 @@ const {reactNativeRootPath, templateName, templateConfigPath, directory} = argv;
|
42 | 43 |
|
43 | 44 | const VERDACCIO_CONFIG_PATH = `${reactNativeRootPath}/.circleci/verdaccio.yml`;
|
44 | 45 |
|
45 |
| -function install() { |
| 46 | +async function install() { |
46 | 47 | const VERDACCIO_PID = setupVerdaccio(
|
47 | 48 | reactNativeRootPath,
|
48 | 49 | VERDACCIO_CONFIG_PATH,
|
49 | 50 | );
|
50 |
| - process.stdout.write('Bootstrapped Verdaccio \u2705\n'); |
51 |
| - |
52 |
| - process.stdout.write('Starting to publish every package...\n'); |
53 |
| - forEachPackage( |
54 |
| - (packageAbsolutePath, packageRelativePathFromRoot, packageManifest) => { |
55 |
| - if (packageManifest.private) { |
56 |
| - return; |
57 |
| - } |
58 |
| - |
59 |
| - execSync('npm publish --registry http://localhost:4873 --access public', { |
60 |
| - cwd: packageAbsolutePath, |
| 51 | + try { |
| 52 | + process.stdout.write('Bootstrapped Verdaccio \u2705\n'); |
| 53 | + |
| 54 | + process.stdout.write('Starting to publish every package...\n'); |
| 55 | + forEachPackage( |
| 56 | + (packageAbsolutePath, packageRelativePathFromRoot, packageManifest) => { |
| 57 | + if (packageManifest.private) { |
| 58 | + return; |
| 59 | + } |
| 60 | + |
| 61 | + execSync( |
| 62 | + 'npm publish --registry http://localhost:4873 --access public', |
| 63 | + { |
| 64 | + cwd: packageAbsolutePath, |
| 65 | + stdio: [process.stdin, process.stdout, process.stderr], |
| 66 | + }, |
| 67 | + ); |
| 68 | + |
| 69 | + process.stdout.write( |
| 70 | + `Published ${packageManifest.name} to proxy \u2705\n`, |
| 71 | + ); |
| 72 | + }, |
| 73 | + ); |
| 74 | + |
| 75 | + process.stdout.write('Published every package \u2705\n'); |
| 76 | + |
| 77 | + execSync( |
| 78 | + `node cli.js init ${templateName} --directory ${directory} --template ${templateConfigPath} --verbose --skip-install`, |
| 79 | + { |
| 80 | + cwd: `${reactNativeRootPath}/packages/react-native`, |
61 | 81 | stdio: [process.stdin, process.stdout, process.stderr],
|
62 |
| - }); |
63 |
| - |
64 |
| - process.stdout.write( |
65 |
| - `Published ${packageManifest.name} to proxy \u2705\n`, |
66 |
| - ); |
67 |
| - }, |
68 |
| - ); |
69 |
| - |
70 |
| - process.stdout.write('Published every package \u2705\n'); |
| 82 | + }, |
| 83 | + ); |
| 84 | + process.stdout.write('Completed initialization of template app \u2705\n'); |
71 | 85 |
|
72 |
| - execSync( |
73 |
| - `node cli.js init ${templateName} --directory ${directory} --template ${templateConfigPath} --verbose --skip-install`, |
74 |
| - { |
75 |
| - cwd: `${reactNativeRootPath}/packages/react-native`, |
| 86 | + process.stdout.write('Installing dependencies in template app folder...\n'); |
| 87 | + const options = { |
| 88 | + cwd: directory, |
76 | 89 | stdio: [process.stdin, process.stdout, process.stderr],
|
77 |
| - }, |
78 |
| - ); |
79 |
| - process.stdout.write('Completed initialization of template app \u2705\n'); |
80 |
| - |
81 |
| - process.stdout.write('Installing dependencies in template app folder...\n'); |
82 |
| - spawnSync('yarn', ['install'], { |
83 |
| - cwd: directory, |
84 |
| - stdio: [process.stdin, process.stdout, process.stderr], |
85 |
| - }); |
86 |
| - process.stdout.write('Installed dependencies via Yarn \u2705\n'); |
| 90 | + }; |
| 91 | + const success = await retry('yarn', options, 3, 500, ['install']); |
87 | 92 |
|
88 |
| - process.stdout.write(`Killing verdaccio. PID — ${VERDACCIO_PID}...\n`); |
89 |
| - execSync(`kill -9 ${VERDACCIO_PID}`); |
90 |
| - process.stdout.write('Killed Verdaccio process \u2705\n'); |
91 |
| - |
92 |
| - process.exit(); |
| 93 | + if (!success) { |
| 94 | + process.stdout.write( |
| 95 | + 'Failed to install dependencies in template app folder.', |
| 96 | + ); |
| 97 | + throw new Error('Failed to install dependencies in template app folder.'); |
| 98 | + } |
| 99 | + |
| 100 | + process.stdout.write('Installed dependencies via Yarn \u2705\n'); |
| 101 | + } finally { |
| 102 | + process.stdout.write(`Killing verdaccio. PID — ${VERDACCIO_PID}...\n`); |
| 103 | + execSync(`kill -9 ${VERDACCIO_PID}`); |
| 104 | + process.stdout.write('Killed Verdaccio process \u2705\n'); |
| 105 | + } |
93 | 106 | }
|
94 | 107 |
|
95 |
| -install(); |
| 108 | +install().then(() => { |
| 109 | + console.log('Done with preparing the project.'); |
| 110 | + process.exit(); |
| 111 | +}); |
0 commit comments