diff --git a/.circleci/config.yml b/.circleci/config.yml index fce49cf88a4..fa515b7ae76 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1577,6 +1577,7 @@ jobs: executor: reactnativeandroid steps: - checkout + - run_yarn - run: name: Set NPM auth token command: echo "//registry.npmjs.org/:_authToken=${CIRCLE_NPM_TOKEN}" > ~/.npmrc diff --git a/scripts/run-ci-e2e-tests.js b/scripts/run-ci-e2e-tests.js index f9a2f98fe54..a94e1be4468 100644 --- a/scripts/run-ci-e2e-tests.js +++ b/scripts/run-ci-e2e-tests.js @@ -23,6 +23,8 @@ const {cd, cp, echo, exec, exit, mv} = require('shelljs'); const spawn = require('child_process').spawn; const argv = require('yargs').argv; const path = require('path'); + +const forEachPackage = require('./monorepo/for-each-package'); const setupVerdaccio = require('./setup-verdaccio'); const SCRIPTS = __dirname; @@ -79,14 +81,18 @@ try { VERDACCIO_PID = setupVerdaccio(ROOT, VERDACCIO_CONFIG_PATH); describe('Publish packages'); - const packages = JSON.parse( - JSON.parse(exec('yarn --json workspaces info').stdout).data, + forEachPackage( + (packageAbsolutePath, packageRelativePathFromRoot, packageManifest) => { + if (packageManifest.private) { + return; + } + + exec( + 'npm publish --registry http://localhost:4873 --yes --access public', + {cwd: packageAbsolutePath}, + ); + }, ); - Object.keys(packages).forEach(packageName => { - exec( - `cd ${packages[packageName].location} && npm publish --registry http://localhost:4873 --yes --access public`, - ); - }); describe('Scaffold a basic React Native app from template'); exec(`rsync -a ${ROOT}/template ${REACT_NATIVE_TEMP_DIR}`); diff --git a/scripts/template/initialize.js b/scripts/template/initialize.js index b0cfaf9365a..eaba0e4e900 100644 --- a/scripts/template/initialize.js +++ b/scripts/template/initialize.js @@ -11,9 +11,8 @@ const yargs = require('yargs'); const {execSync, spawnSync} = require('child_process'); -const fs = require('fs'); -const path = require('path'); +const forEachPackage = require('../monorepo/for-each-package'); const setupVerdaccio = require('../setup-verdaccio'); const {argv} = yargs @@ -43,41 +42,32 @@ const {reactNativeRootPath, templateName, templateConfigPath, directory} = argv; const VERDACCIO_CONFIG_PATH = `${reactNativeRootPath}/.circleci/verdaccio.yml`; -function readPackageJSON(pathToPackage) { - return JSON.parse(fs.readFileSync(path.join(pathToPackage, 'package.json'))); -} - function install() { - const yarnWorkspacesStdout = execSync('yarn --json workspaces info', { - cwd: reactNativeRootPath, - encoding: 'utf8', - }); - const packages = JSON.parse(JSON.parse(yarnWorkspacesStdout).data); - const VERDACCIO_PID = setupVerdaccio( reactNativeRootPath, VERDACCIO_CONFIG_PATH, ); process.stdout.write('Bootstrapped Verdaccio \u2705\n'); - process.stdout.write('Starting to publish all the packages...\n'); - Object.entries(packages).forEach(([packageName, packageEntity]) => { - const packageRelativePath = packageEntity.location; - const packageAbsolutePath = `${reactNativeRootPath}/${packageRelativePath}`; + process.stdout.write('Starting to publish every package...\n'); + forEachPackage( + (packageAbsolutePath, packageRelativePathFromRoot, packageManifest) => { + if (packageManifest.private) { + return; + } - const packageManifest = readPackageJSON(packageAbsolutePath); - if (packageManifest.private) { - return; - } + execSync('npm publish --registry http://localhost:4873 --access public', { + cwd: packageAbsolutePath, + stdio: [process.stdin, process.stdout, process.stderr], + }); - execSync('npm publish --registry http://localhost:4873 --access public', { - cwd: `${reactNativeRootPath}/${packageEntity.location}`, - stdio: [process.stdin, process.stdout, process.stderr], - }); + process.stdout.write( + `Published ${packageManifest.name} to proxy \u2705\n`, + ); + }, + ); - process.stdout.write(`Published ${packageName} to proxy \u2705\n`); - }); - process.stdout.write('Published all packages \u2705\n'); + process.stdout.write('Published every package \u2705\n'); execSync( `node cli.js init ${templateName} --directory ${directory} --template ${templateConfigPath} --verbose --skip-install`,