Files
self/packages/mobile-sdk-demo/scripts/bundle-analyze-ci.cjs
Justin Hernandez 20fa5c5adc [SELF-700] feat: add mock document generator demo (#995)
* feat: add mock document generator demo

* feat: add mock document generator

* fixes

* chore: refresh workflow cache

* update lock

* build

* updates

* more fixes

* code rabbit feedback

* compiles

* save wip

* updates

* merge with dev and fixes

* fix: align hoisting and demo Jest resolver (#1003)

* chore(app): map common src paths and declare svg flag module

* ci fix

* update lock

* save wip

* chore: address yarn lock issues (#1004)

* address yarn lock issues

* fix postinstall

* fix ci

* use metro js proxy

* android build working for /app

* save wip

* fix merge

* pipeline fixes

* format

* fix pipelines

* bump limit and split

* fix pipeline issues

* chore: decouple demo app build (#1013)

* chore: decouple demo app build

* chore: move demo app to workspace

* chore: unpublish demo workspace

* fix mobile sdk tests

* updates

* remove polyfills

* update merge

* update resolutions

* update resolutions

* fix merge

* fix paths

* save wip

* save wip fixes rd2

* working android

* update lock

* save wip ios building

* fix merge

* readd public key

* fixes

* ci fixes

* fixes

* fix web building

* fix ci

* fix tests

* update lock

* fix ci rd2

* formatting and fix ci

* fix

* finalize ci fixes

* fix tests and metro config paths for building

* save wip

* install missing package for pipeline

* fix wip app building

* wip react config

* save working emulator compile

* first round of pr fixes and feedback

* clean up demo app artifacts from sdk

* Add Gradle wrapper files for mobile-sdk-demo Android build

- Added gradlew, gradlew.bat, and gradle/wrapper/ directory
- Updated .gitignore to allow committing Gradle wrapper files
- Fixes Android build error: spawn ./gradlew ENOENT

* codex feedback and fixes

* fix tests

* file renames

* revert back to dev

* add types

* coderabbit fixes

* fix tests

* fix tests

* fix test

* fixes

* fix wip coderabbit issues

* coderabbit suggestions rd 2

* fix ci pipelines and addresss warnings

* cr fixes

* convert kebab to camelCase

* save wip fixes

* update reinstall and lock files

* fixes

* remove file

* fix lint

* fix polyfill fallback issues

* ensure that mock document is not on ofac list

* prettier
2025-09-27 13:59:47 -07:00

99 lines
3.2 KiB
JavaScript

#!/usr/bin/env node
// SPDX-FileCopyrightText: 2025 Social Connect Labs, Inc.
// SPDX-License-Identifier: BUSL-1.1
// NOTE: Converts to Apache-2.0 on 2029-06-11 per LICENSE.
const { execSync } = require('child_process');
const { existsSync, statSync, unlinkSync } = require('fs');
const os = require('os');
const { join } = require('path');
const platform = process.argv[2];
if (!platform || !['android', 'ios'].includes(platform)) {
console.error('Usage: bundle-analyze-ci.cjs <android|ios>');
process.exit(1);
}
// Bundle size thresholds in MB - adjusted for demo app
const BUNDLE_THRESHOLDS_MB = {
ios: 10, // Smaller threshold for demo app
android: 10, // Smaller threshold for demo app
};
function formatBytes(bytes) {
const sizes = ['Bytes', 'KB', 'MB', 'GB'];
if (bytes === 0) return '0 Bytes';
const i = Math.floor(Math.log(bytes) / Math.log(1024));
return Math.round((bytes / Math.pow(1024, i)) * 100) / 100 + ' ' + sizes[i];
}
function checkBundleSize(bundleSize, targetPlatform) {
const thresholdMB = BUNDLE_THRESHOLDS_MB[targetPlatform];
const thresholdBytes = thresholdMB * 1024 * 1024;
console.log(`\n📦 Demo App Bundle size: ${formatBytes(bundleSize)}`);
console.log(`🎯 Threshold: ${thresholdMB}MB (${formatBytes(thresholdBytes)})`);
if (bundleSize > thresholdBytes) {
const overage = bundleSize - thresholdBytes;
console.error(`\n❌ Bundle size exceeds threshold by ${formatBytes(overage)}!`);
console.error(` Current: ${formatBytes(bundleSize)}`);
console.error(` Threshold: ${thresholdMB}MB`);
console.error(` Please reduce bundle size to continue.`);
console.error(`\n💡 To increase the threshold, edit BUNDLE_THRESHOLDS_MB in this script.`);
return false;
} else {
const remaining = thresholdBytes - bundleSize;
console.log(`✅ Demo app bundle size is within threshold (${formatBytes(remaining)} remaining)`);
return true;
}
}
// Use Metro's built-in bundle command
const tmpDir = os.tmpdir();
const bundleFile = join(tmpDir, `demo-app-${platform}.bundle`);
const sourcemapFile = join(tmpDir, `demo-app-${platform}.bundle.map`);
console.log(`🔨 Generating demo app ${platform} bundle using Metro...`);
try {
execSync(
`npx react-native bundle ` +
`--platform ${platform} ` +
`--dev false ` +
`--entry-file index.js ` +
`--bundle-output ${bundleFile} ` +
`--sourcemap-output ${sourcemapFile} ` +
`--minify false ` +
`--config metro.config.cjs ` +
`--reset-cache`,
{
stdio: 'inherit',
},
);
} catch (error) {
console.error(`❌ Failed to generate demo app bundle: ${error.message}`);
process.exit(1);
}
// Check bundle size against threshold
if (existsSync(bundleFile)) {
const bundleSize = statSync(bundleFile).size;
console.log(`📁 Demo app bundle generated at: ${bundleFile}`);
if (!checkBundleSize(bundleSize, platform)) {
process.exit(1);
}
// Clean up temporary files
try {
unlinkSync(bundleFile);
unlinkSync(sourcemapFile);
console.log('🧹 Cleaned up temporary bundle files');
} catch (cleanupError) {
console.warn('⚠️ Could not clean up temporary files:', cleanupError.message);
}
} else {
console.error(`❌ Bundle file not found at ${bundleFile}`);
process.exit(1);
}