Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"env": {
"es6": true
"es6": true,
"node": true
},
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 2018,
"sourceType": "module"
},
"plugins": ["prettier"]
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,4 @@ rust_modules/
# React Native Codegen
ios/generated
android/generated
binaries.tar.gz
13 changes: 10 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
"ios",
"cpp",
"*.podspec",
"build",
"react-native.config.js",
"swift",
"scripts",
"!ios/build",
"!android/build",
"!android/gradle",
Expand Down Expand Up @@ -59,7 +59,7 @@
"clean": "del-cli -v android/build example/android/build example/android/app/build example/ios/build lib **/.cxx",
"prepare": "bob build",
"release": "release-it",
"postinstall": "patch-package"
"postinstall": "patch-package && node scripts/download-binaries.js"
},
"keywords": [
"react-native",
Expand Down Expand Up @@ -100,6 +100,7 @@
"react-native": "0.76.9",
"react-native-builder-bob": "^0.31.0",
"release-it": "^15.0.0",
"tar": "^7.4.3",
"turbo": "^1.10.7",
"typescript": "^5.2.2",
"uniffi-bindgen-react-native": "0.29.3-1"
Expand Down Expand Up @@ -136,7 +137,13 @@
"publish": true
},
"github": {
"release": true
"release": true,
"assets": [
"binaries.tar.gz"
]
},
"hooks": {
"before:release": "node scripts/package-binaries.js"
},
"plugins": {
"@release-it/conventional-changelog": {
Expand Down
85 changes: 85 additions & 0 deletions scripts/download-binaries.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/usr/bin/env node

const fs = require('fs');
const path = require('path');
const https = require('https');
const { execSync } = require('child_process');
const tar = require('tar');

const PACKAGE_JSON = require('../package.json');
const VERSION = PACKAGE_JSON.version;
const REPO = 'unomed-dev/react-native-matrix-sdk';

async function downloadFile(url, dest) {
return new Promise((resolve, reject) => {
const file = fs.createWriteStream(dest);
https.get(url, (response) => {
if (response.statusCode === 302 || response.statusCode === 301) {
// Follow redirect
https.get(response.headers.location, (redirectResponse) => {
redirectResponse.pipe(file);
file.on('finish', () => {
file.close(resolve);
});
}).on('error', reject);
} else if (response.statusCode === 200) {
response.pipe(file);
file.on('finish', () => {
file.close(resolve);
});
} else {
reject(new Error(`HTTP ${response.statusCode}`));
}
}).on('error', reject);
});
}

async function downloadBinaries() {
const buildDir = path.join(__dirname, '..', 'build');

// Check if binaries already exist
if (fs.existsSync(path.join(buildDir, 'RnMatrixRustSdk.xcframework'))) {
console.log('Binaries already exist, skipping download.');
return;
}

console.log(`Downloading binaries for v${VERSION}...`);

// Create build directory
if (!fs.existsSync(buildDir)) {
fs.mkdirSync(buildDir, { recursive: true });
}

const releaseUrl = `https://github.com/${REPO}/releases/download/v${VERSION}/binaries.tar.gz`;
const tempFile = path.join(buildDir, 'binaries.tar.gz');

try {
// Download the binary archive
console.log(`Downloading from ${releaseUrl}...`);
await downloadFile(releaseUrl, tempFile);

// Extract the archive
console.log('Extracting binaries...');
await tar.x({
file: tempFile,
cwd: buildDir,
});

// Clean up
fs.unlinkSync(tempFile);

console.log('Binaries downloaded successfully!');
} catch (error) {
console.error('Failed to download binaries:', error.message);
console.error('You may need to build the binaries locally using:');
console.error(' yarn generate:release');
// Exit gracefully if binaries do not exist
process.exit(0);
}
}

if (require.main === module) {
downloadBinaries().catch(console.error);
}

module.exports = { downloadBinaries };
34 changes: 34 additions & 0 deletions scripts/package-binaries.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env node

const fs = require('fs');
const path = require('path');
const tar = require('tar');

async function packageBinaries() {
const buildDir = path.join(__dirname, '..', 'build');
const outputFile = path.join(__dirname, '..', 'binaries.tar.gz');

if (!fs.existsSync(path.join(buildDir, 'RnMatrixRustSdk.xcframework'))) {
console.error('No binaries found in build directory. Run yarn generate:release first.');
process.exit(1);
}

console.log('Packaging binaries...');

await tar.c({
gzip: true,
file: outputFile,
cwd: buildDir,
}, ['.']);

const stats = fs.statSync(outputFile);
const sizeMB = (stats.size / 1024 / 1024).toFixed(2);

console.log(`Binaries packaged successfully: ${outputFile} (${sizeMB} MB)`);
}

if (require.main === module) {
packageBinaries().catch(console.error);
}

module.exports = { packageBinaries };
58 changes: 57 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3030,6 +3030,15 @@ __metadata:
languageName: node
linkType: hard

"@isaacs/fs-minipass@npm:^4.0.0":
version: 4.0.1
resolution: "@isaacs/fs-minipass@npm:4.0.1"
dependencies:
minipass: ^7.0.4
checksum: 5d36d289960e886484362d9eb6a51d1ea28baed5f5d0140bbe62b99bac52eaf06cc01c2bc0d3575977962f84f6b2c4387b043ee632216643d4787b0999465bf2
languageName: node
linkType: hard

"@isaacs/ttlcache@npm:^1.4.1":
version: 1.4.1
resolution: "@isaacs/ttlcache@npm:1.4.1"
Expand Down Expand Up @@ -4564,6 +4573,7 @@ __metadata:
react-native: 0.76.9
react-native-builder-bob: ^0.31.0
release-it: ^15.0.0
tar: ^7.4.3
turbo: ^1.10.7
typescript: ^5.2.2
uniffi-bindgen-react-native: 0.29.3-1
Expand Down Expand Up @@ -5599,6 +5609,13 @@ __metadata:
languageName: node
linkType: hard

"chownr@npm:^3.0.0":
version: 3.0.0
resolution: "chownr@npm:3.0.0"
checksum: fd73a4bab48b79e66903fe1cafbdc208956f41ea4f856df883d0c7277b7ab29fd33ee65f93b2ec9192fc0169238f2f8307b7735d27c155821d886b84aa97aa8d
languageName: node
linkType: hard

"chrome-launcher@npm:^0.15.2":
version: 0.15.2
resolution: "chrome-launcher@npm:0.15.2"
Expand Down Expand Up @@ -11223,7 +11240,7 @@ __metadata:
languageName: node
linkType: hard

"minipass@npm:^5.0.0 || ^6.0.2 || ^7.0.0, minipass@npm:^7.0.2, minipass@npm:^7.0.3, minipass@npm:^7.1.2":
"minipass@npm:^5.0.0 || ^6.0.2 || ^7.0.0, minipass@npm:^7.0.2, minipass@npm:^7.0.3, minipass@npm:^7.0.4, minipass@npm:^7.1.2":
version: 7.1.2
resolution: "minipass@npm:7.1.2"
checksum: 2bfd325b95c555f2b4d2814d49325691c7bee937d753814861b0b49d5edcda55cbbf22b6b6a60bb91eddac8668771f03c5ff647dcd9d0f798e9548b9cdc46ee3
Expand All @@ -11240,6 +11257,15 @@ __metadata:
languageName: node
linkType: hard

"minizlib@npm:^3.0.1":
version: 3.0.2
resolution: "minizlib@npm:3.0.2"
dependencies:
minipass: ^7.1.2
checksum: 493bed14dcb6118da7f8af356a8947cf1473289c09658e5aabd69a737800a8c3b1736fb7d7931b722268a9c9bc038a6d53c049b6a6af24b34a121823bb709996
languageName: node
linkType: hard

"mkdirp@npm:^0.5.1":
version: 0.5.6
resolution: "mkdirp@npm:0.5.6"
Expand All @@ -11260,6 +11286,15 @@ __metadata:
languageName: node
linkType: hard

"mkdirp@npm:^3.0.1":
version: 3.0.1
resolution: "mkdirp@npm:3.0.1"
bin:
mkdirp: dist/cjs/src/bin.js
checksum: 972deb188e8fb55547f1e58d66bd6b4a3623bf0c7137802582602d73e6480c1c2268dcbafbfb1be466e00cc7e56ac514d7fd9334b7cf33e3e2ab547c16f83a8d
languageName: node
linkType: hard

"modify-values@npm:^1.0.0":
version: 1.0.1
resolution: "modify-values@npm:1.0.1"
Expand Down Expand Up @@ -13861,6 +13896,20 @@ __metadata:
languageName: node
linkType: hard

"tar@npm:^7.4.3":
version: 7.4.3
resolution: "tar@npm:7.4.3"
dependencies:
"@isaacs/fs-minipass": ^4.0.0
chownr: ^3.0.0
minipass: ^7.1.2
minizlib: ^3.0.1
mkdirp: ^3.0.1
yallist: ^5.0.0
checksum: 8485350c0688331c94493031f417df069b778aadb25598abdad51862e007c39d1dd5310702c7be4a6784731a174799d8885d2fde0484269aea205b724d7b2ffa
languageName: node
linkType: hard

"temp@npm:^0.8.4":
version: 0.8.4
resolution: "temp@npm:0.8.4"
Expand Down Expand Up @@ -14893,6 +14942,13 @@ __metadata:
languageName: node
linkType: hard

"yallist@npm:^5.0.0":
version: 5.0.0
resolution: "yallist@npm:5.0.0"
checksum: eba51182400b9f35b017daa7f419f434424410691bbc5de4f4240cc830fdef906b504424992700dc047f16b4d99100a6f8b8b11175c193f38008e9c96322b6a5
languageName: node
linkType: hard

"yaml@npm:^2.2.1":
version: 2.6.0
resolution: "yaml@npm:2.6.0"
Expand Down
Loading