Skip to content

Commit 4bedff2

Browse files
hoxyqOlimpiaZurek
authored andcommitted
refactor(circleci/template): publish all packages to Verdaccio before template initialization (facebook#35459)
Summary: Pull Request resolved: facebook#35459 Changelog: [Internal] [Changed] - now bootstrapping Verdaccio before template app initialization, this is required because react-native migh depend on some package which version is not yet published to npm Reviewed By: cipolleschi Differential Revision: D41521496 fbshipit-source-id: 6183ab02c697d9d08e9dca5b323bd7a11a749c3a
1 parent ec398e0 commit 4bedff2

File tree

5 files changed

+107
-128
lines changed

5 files changed

+107
-128
lines changed

.circleci/config.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -764,8 +764,7 @@ jobs:
764764
command: |
765765
REPO_ROOT=$(pwd)
766766
node ./scripts/set-rn-template-version.js "file:$REPO_ROOT/build/$(cat build/react-native-package-version)"
767-
node cli.js init $PROJECT_NAME --directory "/tmp/$PROJECT_NAME" --template $REPO_ROOT --verbose --skip-install
768-
node ./scripts/template/install-dependencies.js --reactNativeRootPath $REPO_ROOT --templatePath "/tmp/$PROJECT_NAME"
767+
node ./scripts/template/initialize.js --reactNativeRootPath $REPO_ROOT --templateName $PROJECT_NAME --templateConfigPath $REPO_ROOT --directory "/tmp/$PROJECT_NAME"
769768
- run:
770769
name: Build the template application for << parameters.flavor >> with Architecture set to << parameters.architecture >>, and using the << parameters.jsengine>> JS engine.
771770
command: |
@@ -849,8 +848,7 @@ jobs:
849848
PACKAGE=$(cat build/react-native-package-version)
850849
PATH_TO_PACKAGE="$REPO_ROOT/build/$PACKAGE"
851850
node ./scripts/set-rn-template-version.js "file:$PATH_TO_PACKAGE"
852-
node cli.js init $PROJECT_NAME --directory "/tmp/$PROJECT_NAME" --template $REPO_ROOT --verbose --skip-install
853-
node ./scripts/template/install-dependencies.js --reactNativeRootPath $REPO_ROOT --templatePath "/tmp/$PROJECT_NAME"
851+
node ./scripts/template/initialize.js --reactNativeRootPath $REPO_ROOT --templateName $PROJECT_NAME --templateConfigPath $REPO_ROOT --directory "/tmp/$PROJECT_NAME"
854852
- run:
855853
name: Install iOS dependencies - Configuration << parameters.flavor >>; New Architecture << parameters.architecture >>; JS Engine << parameters.jsengine>>; Flipper << parameters.flipper >>
856854
command: |

scripts/template/README.md

Lines changed: 0 additions & 30 deletions
This file was deleted.

scripts/template/initialize.js

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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();

scripts/template/install-dependencies.js

Lines changed: 0 additions & 67 deletions
This file was deleted.

scripts/template/verdaccio.yml

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)