|
| 1 | +/** |
| 2 | + * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | + * |
| 4 | + * This source code is licensed under the MIT license found in the |
| 5 | + * LICENSE file in the root directory of this source tree. |
| 6 | + * |
| 7 | + * @format |
| 8 | + */ |
| 9 | + |
| 10 | +'use strict'; |
| 11 | + |
| 12 | +const yargs = require('yargs'); |
| 13 | +const {execSync, spawnSync} = require('child_process'); |
| 14 | +const setupVerdaccio = require('../setup-verdaccio'); |
| 15 | + |
| 16 | +const {argv} = yargs |
| 17 | + .option('r', { |
| 18 | + alias: 'reactNativeRootPath', |
| 19 | + describe: 'Path to root folder of react-native', |
| 20 | + required: true, |
| 21 | + }) |
| 22 | + .option('c', { |
| 23 | + alias: 'templatePath', |
| 24 | + describe: 'Path to template application folder', |
| 25 | + required: true, |
| 26 | + }) |
| 27 | + .strict(); |
| 28 | + |
| 29 | +const {reactNativeRootPath, templatePath} = argv; |
| 30 | + |
| 31 | +const VERDACCIO_CONFIG_PATH = `${reactNativeRootPath}/scripts/template/verdaccio.yml`; |
| 32 | +const VERDACCIO_STORAGE_PATH = `${templatePath}/node_modules`; |
| 33 | + |
| 34 | +const PACKAGES_TO_PUBLISH_PATHS = []; |
| 35 | + |
| 36 | +function install() { |
| 37 | + const VERDACCIO_PID = setupVerdaccio( |
| 38 | + reactNativeRootPath, |
| 39 | + VERDACCIO_CONFIG_PATH, |
| 40 | + VERDACCIO_STORAGE_PATH, |
| 41 | + ); |
| 42 | + process.stdout.write('Bootstrapped Verdaccio \u2705\n'); |
| 43 | + |
| 44 | + // Publish all necessary packages... |
| 45 | + for (const packagePath of PACKAGES_TO_PUBLISH_PATHS) { |
| 46 | + execSync('npm publish --registry http://localhost:4873 --access public', { |
| 47 | + cwd: `${reactNativeRootPath}/${packagePath}`, |
| 48 | + stdio: [process.stdin, process.stdout, process.stderr], |
| 49 | + }); |
| 50 | + |
| 51 | + process.stdout.write(`Published /${packagePath} to proxy \u2705\n`); |
| 52 | + } |
| 53 | + |
| 54 | + spawnSync('yarn', ['install'], { |
| 55 | + cwd: templatePath, |
| 56 | + stdio: [process.stdin, process.stdout, process.stderr], |
| 57 | + }); |
| 58 | + process.stdout.write('Installed dependencies via Yarn \u2705\n'); |
| 59 | + |
| 60 | + process.stdout.write(`Killing verdaccio. PID — ${VERDACCIO_PID}...\n`); |
| 61 | + execSync(`kill -9 ${VERDACCIO_PID}`); |
| 62 | + process.stdout.write('Killed Verdaccio process \u2705\n'); |
| 63 | + |
| 64 | + process.exit(); |
| 65 | +} |
| 66 | + |
| 67 | +install(); |
0 commit comments