Skip to content

Commit 47a2ac9

Browse files
committed
Add custom publishing script
1 parent 2893ba8 commit 47a2ac9

File tree

5 files changed

+114
-2
lines changed

5 files changed

+114
-2
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,5 @@ package-lock.json
134134

135135
# Temporary files created by Metro to check the health of the file watcher
136136
.metro-health-check*
137+
138+
react-native-*.tgz

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
# Expensify Release
2+
3+
To publish a new version run the following script, where `<base-version>` is the react-native version that the fork is based on, and `<fork-version>` is the version you want to publish. This will generate a tarball (`react-native-<fork-version>.tgz`) which can then be uploaded to a github release and consumed via npm.
4+
5+
```bash
6+
node ./scripts/publish-npm-expensify.js --base-version <base-version> --fork-version <fork-version>
7+
```
8+
9+
For example if the fork is based on [email protected] and our fork version is 0.71.3.
10+
11+
```bash
12+
node ./scripts/publish-npm-expensify.js --base-version 0.71.0 --fork-version 0.71.3
13+
```
14+
15+
If you encounter build issues you can add the `--clean` flag to delete some folder that might cause some cache issues.
16+
117
<h1 align="center">
218
<a href="https://reactnative.dev/">
319
React Native
@@ -56,6 +72,7 @@ React Native is developed and supported by many companies and individual core co
5672

5773
## Contents
5874

75+
- [Expensify Release](#expensify-release)
5976
- [Requirements](#-requirements)
6077
- [Building your first React Native app](#-building-your-first-react-native-app)
6178
- [Documentation](#-documentation)

ReactAndroid/.npmignore

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

scripts/publish-npm-expensify.js

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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('clean', {
20+
type: 'boolean',
21+
default: false,
22+
})
23+
.strict().argv;
24+
const baseVersion = argv.baseVersion;
25+
const forkVersion = argv.forkVersion;
26+
const clean = argv.clean;
27+
28+
if (clean) {
29+
rm('-rf', path.join(__dirname, '../android'));
30+
rm('-rf', path.join(__dirname, '../sdks/download'));
31+
rm('-rf', path.join(__dirname, '../sdks/hermes'));
32+
rm('-rf', path.join(__dirname, '../sdks/hermesc'));
33+
}
34+
35+
// Update the version number.
36+
if (
37+
exec(
38+
`node scripts/set-rn-version.js --to-version ${forkVersion} --build-type release`,
39+
).code
40+
) {
41+
echo(`Failed to set version number to ${forkVersion}`);
42+
exit(1);
43+
}
44+
45+
// Use the hermes prebuilt binaries from the base version.
46+
sed(
47+
'-i',
48+
/^version = .*$/,
49+
`version = '${baseVersion}'`,
50+
path.join(__dirname, '../sdks/hermes-engine/hermes-engine.podspec'),
51+
);
52+
53+
// Download hermesc from the base version.
54+
const rnTmpDir = path.join(os.tmpdir(), 'hermesc');
55+
const rnTgzOutput = path.join(rnTmpDir, `react-native-${baseVersion}.tgz`);
56+
const hermescDest = path.join(__dirname, '../sdks');
57+
exec(`mkdir -p ${rnTmpDir}`);
58+
if (
59+
exec(
60+
`curl https://registry.npmjs.com/react-native/-/react-native-${baseVersion}.tgz --output ${rnTgzOutput}`,
61+
).code
62+
) {
63+
echo('Failed to download base react-native package');
64+
exit(1);
65+
}
66+
if (exec(`tar -xvf ${rnTgzOutput} -C ${rnTmpDir}`).code) {
67+
echo('Failed to extract base react-native package');
68+
exit(1);
69+
}
70+
exec(`mkdir -p ${hermescDest}`);
71+
if (
72+
exec(`cp -r ${path.join(rnTmpDir, 'package/sdks/hermesc')} ${hermescDest}`)
73+
.code
74+
) {
75+
echo('Failed to copy hermesc from base react-native package');
76+
exit(1);
77+
}
78+
79+
// Build the android artifacts in the npm package.
80+
if (exec('./gradlew publishAllInsideNpmPackage').code) {
81+
echo('Could not generate artifacts');
82+
exit(1);
83+
}
84+
85+
// Generate tarball.
86+
if (exec('npm pack').code) {
87+
echo('Failed to generate tarball');
88+
exit(1);
89+
} else {
90+
exit(0);
91+
}

sdks/hermes-engine/hermes-engine.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ require_relative "./hermes-utils.rb"
88

99
react_native_path = File.join(__dir__, "..", "..")
1010

11-
# Whether Hermes is built for Release or Debug is determined by the PRODUCTION envvar.
12-
build_type = ENV['PRODUCTION'] == "1" ? :release : :debug
11+
# Always use release build of hermes.
12+
build_type = :release
1313

1414
# package.json
1515
package = JSON.parse(File.read(File.join(react_native_path, "package.json")))

0 commit comments

Comments
 (0)