Skip to content

Commit

Permalink
Add publish script
Browse files Browse the repository at this point in the history
  • Loading branch information
janicduplessis committed Nov 22, 2023
1 parent 6f971b9 commit 247c030
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,5 @@ package-lock.json

# CircleCI
.circleci/generated_config.yml

react-native-*.tgz
19 changes: 12 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,18 @@ React Native is developed and supported by many companies and individual core co

## Contents

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


## 📋 Requirements
Expand Down
2 changes: 2 additions & 0 deletions packages/react-native/ReactAndroid/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ src/main/third-party/
# Exclude Android & JVM tests
src/test/
src/androidTest/
# Exclude prebuilt
src/main/jni/prebuilt/lib/
101 changes: 101 additions & 0 deletions scripts/generate-npm-tarball.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/**
* @format
*/

'use strict';

const {exec, echo, exit, sed, rm} = require('shelljs');
const os = require('os');
const path = require('path');
const yargs = require('yargs');

const argv = yargs
.option('base-version', {
type: 'string',
})
.option('fork-version', {
type: 'string',
})
.option('hermes-version', {
type: 'string',
})
.option('clean', {
type: 'boolean',
default: false,
})
.strict().argv;
const baseVersion = argv.baseVersion;
const forkVersion = argv.forkVersion;
const hermesVersion = argv.hermesVersion;
const clean = argv.clean;

const rnDir = path.join(__dirname, '../packages/react-native');

if (clean) {
rm('-rf', path.join(rnDir, 'android'));
rm('-rf', path.join(rnDir, 'sdks/download'));
rm('-rf', path.join(rnDir, 'sdks/hermes'));
rm('-rf', path.join(rnDir, 'sdks/hermesc'));
}

// Update the version number.
if (
exec(
`node scripts/set-rn-version.js --to-version ${forkVersion} --build-type release`,
).code
) {
echo(`Failed to set version number to ${forkVersion}`);
exit(1);
}

// Use the hermes prebuilt binaries from the base version.
sed(
'-i',
/^version = .*$/,
`version = '${baseVersion}'`,
path.join(rnDir, 'sdks/hermes-engine/hermes-engine.podspec'),
);

// Download hermesc from the base version.
const rnTmpDir = path.join(os.tmpdir(), 'hermesc');
const rnTgzOutput = path.join(rnTmpDir, `react-native-${baseVersion}.tgz`);
const hermescDest = path.join(rnDir, 'sdks');
exec(`mkdir -p ${rnTmpDir}`);
if (
exec(
`curl https://registry.npmjs.com/react-native/-/react-native-${baseVersion}.tgz --output ${rnTgzOutput}`,
).code
) {
echo('Failed to download base react-native package');
exit(1);
}
if (exec(`tar -xvf ${rnTgzOutput} -C ${rnTmpDir}`).code) {
echo('Failed to extract base react-native package');
exit(1);
}
exec(`mkdir -p ${hermescDest}`);
if (
exec(`cp -r ${path.join(rnTmpDir, 'package/sdks/hermesc')} ${hermescDest}`)
.code
) {
echo('Failed to copy hermesc from base react-native package');
exit(1);
}

if (hermesVersion) {
exec(`echo "${hermesVersion}" > ${hermescDest}/.hermesversion`);
}

// Build the android artifacts in the npm package.
if (exec('./gradlew publishAllInsideNpmPackage').code) {
echo('Could not generate artifacts');
exit(1);
}

// Generate tarball.
if (exec(`cd ${rnDir} && npm pack`).code) {
echo('Failed to generate tarball');
exit(1);
} else {
exit(0);
}

0 comments on commit 247c030

Please sign in to comment.