|
| 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 fs = require('fs'); |
| 15 | +const path = require('path'); |
| 16 | + |
| 17 | +const setupVerdaccio = require('../setup-verdaccio'); |
| 18 | + |
| 19 | +const {argv} = yargs |
| 20 | + .option('r', { |
| 21 | + alias: 'reactNativeRootPath', |
| 22 | + describe: 'Path to root folder of react-native', |
| 23 | + required: true, |
| 24 | + }) |
| 25 | + .option('n', { |
| 26 | + alias: 'templateName', |
| 27 | + describe: 'Template App name', |
| 28 | + required: true, |
| 29 | + }) |
| 30 | + .option('tcp', { |
| 31 | + alias: 'templateConfigPath', |
| 32 | + describe: 'Path to folder containing template config', |
| 33 | + required: true, |
| 34 | + }) |
| 35 | + .option('d', { |
| 36 | + alias: 'directory', |
| 37 | + describe: 'Path to template application folder', |
| 38 | + required: true, |
| 39 | + }) |
| 40 | + .strict(); |
| 41 | + |
| 42 | +const {reactNativeRootPath, templateName, templateConfigPath, directory} = argv; |
| 43 | + |
| 44 | +const VERDACCIO_CONFIG_PATH = `${reactNativeRootPath}/.circleci/verdaccio.yml`; |
| 45 | + |
| 46 | +function readPackageJSON(pathToPackage) { |
| 47 | + return JSON.parse(fs.readFileSync(path.join(pathToPackage, 'package.json'))); |
| 48 | +} |
| 49 | + |
| 50 | +function install() { |
| 51 | + const yarnWorkspacesStdout = execSync('yarn --json workspaces info', { |
| 52 | + cwd: reactNativeRootPath, |
| 53 | + encoding: 'utf8', |
| 54 | + }); |
| 55 | + const packages = JSON.parse(JSON.parse(yarnWorkspacesStdout).data); |
| 56 | + |
| 57 | + const VERDACCIO_PID = setupVerdaccio( |
| 58 | + reactNativeRootPath, |
| 59 | + VERDACCIO_CONFIG_PATH, |
| 60 | + ); |
| 61 | + process.stdout.write('Bootstrapped Verdaccio \u2705\n'); |
| 62 | + |
| 63 | + process.stdout.write('Starting to publish all the packages...\n'); |
| 64 | + Object.entries(packages).forEach(([packageName, packageEntity]) => { |
| 65 | + const packageManifest = readPackageJSON(packageAbsolutePath); |
| 66 | + if (packageManifest.private) { |
| 67 | + return; |
| 68 | + } |
| 69 | + |
| 70 | + const packageRelativePath = packageEntity.location; |
| 71 | + const packageAbsolutePath = `${reactNativeRootPath}/${packageRelativePath}`; |
| 72 | + |
| 73 | + execSync('npm publish --registry http://localhost:4873 --access public', { |
| 74 | + cwd: `${reactNativeRootPath}/${packageEntity.location}`, |
| 75 | + stdio: [process.stdin, process.stdout, process.stderr], |
| 76 | + }); |
| 77 | + |
| 78 | + process.stdout.write(`Published ${packageName} to proxy \u2705\n`); |
| 79 | + }); |
| 80 | + process.stdout.write('Published all packages \u2705\n'); |
| 81 | + |
| 82 | + execSync( |
| 83 | + `node cli.js init ${templateName} --directory ${directory} --template ${templateConfigPath} --verbose --skip-install`, |
| 84 | + { |
| 85 | + cwd: reactNativeRootPath, |
| 86 | + stdio: [process.stdin, process.stdout, process.stderr], |
| 87 | + }, |
| 88 | + ); |
| 89 | + process.stdout.write('Completed initialization of template app \u2705\n'); |
| 90 | + |
| 91 | + process.stdout.write('Installing dependencies in template app folder...\n'); |
| 92 | + spawnSync('yarn', ['install'], { |
| 93 | + cwd: directory, |
| 94 | + stdio: [process.stdin, process.stdout, process.stderr], |
| 95 | + }); |
| 96 | + process.stdout.write('Installed dependencies via Yarn \u2705\n'); |
| 97 | + |
| 98 | + process.stdout.write(`Killing verdaccio. PID — ${VERDACCIO_PID}...\n`); |
| 99 | + execSync(`kill -9 ${VERDACCIO_PID}`); |
| 100 | + process.stdout.write('Killed Verdaccio process \u2705\n'); |
| 101 | + |
| 102 | + process.exit(); |
| 103 | +} |
| 104 | + |
| 105 | +install(); |
0 commit comments