Skip to content

Commit a023cc1

Browse files
Add publish script
1 parent de67d7c commit a023cc1

4 files changed

Lines changed: 128 additions & 7 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,5 @@ vendor/
158158

159159
# CircleCI
160160
.circleci/generated_config.yml
161+
162+
react-native-*.tgz

README.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,18 @@ React Native is developed and supported by many companies and individual core co
5656

5757
## Contents
5858

59-
- [Requirements](#-requirements)
60-
- [Building your first React Native app](#-building-your-first-react-native-app)
61-
- [Documentation](#-documentation)
62-
- [Upgrading](#-upgrading)
63-
- [How to Contribute](#-how-to-contribute)
64-
- [Code of Conduct](#code-of-conduct)
65-
- [License](#-license)
59+
- [Contents](#contents)
60+
- [📋 Requirements](#-requirements)
61+
- [🎉 Building your first React Native app](#-building-your-first-react-native-app)
62+
- [📖 Documentation](#-documentation)
63+
- [🚀 Upgrading](#-upgrading)
64+
- [👏 How to Contribute](#-how-to-contribute)
65+
- [Code of Conduct](#code-of-conduct)
66+
- [Contributing Guide](#contributing-guide)
67+
- [Open Source Roadmap](#open-source-roadmap)
68+
- [Good First Issues](#good-first-issues)
69+
- [Discussions](#discussions)
70+
- [📄 License](#-license)
6671

6772

6873
## 📋 Requirements

packages/react-native/ReactAndroid/.npmignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@
77
src/main/third-party/
88
# Exclude Android & JVM tests
99
src/test/
10+
# Exclude prebuilt
11+
src/main/jni/prebuilt/lib/

scripts/generate-npm-tarball.js

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/**
2+
* @format
3+
*/
4+
5+
'use strict';
6+
7+
const {exec, echo, exit, sed, rm} = require('shelljs');
8+
const os = require('os');
9+
const path = require('path');
10+
const yargs = require('yargs');
11+
12+
const argv = yargs
13+
.option('base-version', {
14+
type: 'string',
15+
})
16+
.option('fork-version', {
17+
type: 'string',
18+
})
19+
.option('hermes-version', {
20+
type: 'string',
21+
})
22+
.option('clean', {
23+
type: 'boolean',
24+
default: false,
25+
})
26+
.strict().argv;
27+
const baseVersion = argv.baseVersion;
28+
const forkVersion = argv.forkVersion;
29+
const hermesVersion = argv.hermesVersion;
30+
const clean = argv.clean;
31+
32+
const rnDir = path.join(__dirname, '../packages/react-native');
33+
34+
if (clean) {
35+
if (exec('./gradlew clean').code) {
36+
echo('Failed to run gradle clean');
37+
exit(1);
38+
}
39+
rm('-rf', path.join(rnDir, 'android'));
40+
rm('-rf', path.join(rnDir, 'sdks/download'));
41+
rm('-rf', path.join(rnDir, 'sdks/hermes'));
42+
rm('-rf', path.join(rnDir, 'sdks/hermesc'));
43+
}
44+
45+
// Update the version number.
46+
if (
47+
exec(
48+
`node scripts/releases/set-rn-artifacts-version.js --to-version ${forkVersion} --build-type release`,
49+
).code
50+
) {
51+
echo(`Failed to set version number to ${forkVersion}`);
52+
exit(1);
53+
}
54+
55+
// Use the hermes prebuilt binaries from the base version.
56+
sed(
57+
'-i',
58+
/^version = .*$/,
59+
`version = '${baseVersion}'`,
60+
path.join(rnDir, 'sdks/hermes-engine/hermes-engine.podspec'),
61+
);
62+
63+
// Download hermesc from the base version.
64+
const rnTmpDir = path.join(os.tmpdir(), 'hermesc');
65+
const rnTgzOutput = path.join(rnTmpDir, `react-native-${baseVersion}.tgz`);
66+
const hermescDest = path.join(rnDir, 'sdks');
67+
exec(`mkdir -p ${rnTmpDir}`);
68+
if (
69+
exec(
70+
`curl https://registry.npmjs.com/react-native/-/react-native-${baseVersion}.tgz --output ${rnTgzOutput}`,
71+
).code
72+
) {
73+
echo('Failed to download base react-native package');
74+
exit(1);
75+
}
76+
if (exec(`tar -xvf ${rnTgzOutput} -C ${rnTmpDir}`).code) {
77+
echo('Failed to extract base react-native package');
78+
exit(1);
79+
}
80+
exec(`mkdir -p ${hermescDest}`);
81+
if (
82+
exec(`cp -r ${path.join(rnTmpDir, 'package/sdks/hermesc')} ${hermescDest}`)
83+
.code
84+
) {
85+
echo('Failed to copy hermesc from base react-native package');
86+
exit(1);
87+
}
88+
89+
if (hermesVersion) {
90+
exec(`echo "${hermesVersion}" > ${hermescDest}/.hermesversion`);
91+
}
92+
93+
rm('-rf', '/tmp/maven-local');
94+
95+
// Build the android artifacts in the npm package.
96+
if (exec('./gradlew publishAllToMavenTempLocal').code) {
97+
echo('Could not generate artifacts');
98+
exit(1);
99+
}
100+
101+
if (exec(`cp -r /tmp/maven-local/ ${path.join(rnDir, 'android')}`).code) {
102+
echo('Could not copy artifacts');
103+
exit(1);
104+
}
105+
106+
// Generate tarball.
107+
if (exec(`cd ${rnDir} && npm pack`).code) {
108+
echo('Failed to generate tarball');
109+
exit(1);
110+
} else {
111+
exit(0);
112+
}

0 commit comments

Comments
 (0)