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
29 changes: 29 additions & 0 deletions cli/commands/bundleCommand/bundleCodePush.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fs from "fs";
import path from "path";
import { prepareToBundleJS } from "../../functions/prepareToBundleJS.js";
import { runReactNativeBundleCommand } from "../../functions/runReactNativeBundleCommand.js";
import { runExpoBundleCommand } from "../../functions/runExpoBundleCommand.js";
Expand All @@ -17,6 +18,7 @@ export async function bundleCodePush(
entryFile: string = ENTRY_FILE,
jsBundleName: string, // JS bundle file name (not CodePush bundle file)
bundleDirectory: string, // CodePush bundle output directory
outputMetroDir?: string,
): Promise<string> {
if (fs.existsSync(outputRootPath)) {
fs.rmSync(outputRootPath, { recursive: true });
Expand Down Expand Up @@ -49,6 +51,8 @@ export async function bundleCodePush(

console.log('log: JS bundling complete');

copyMetroOutputsIfNeeded(outputRootPath, outputMetroDir, OUTPUT_CONTENT_PATH, _jsBundleName, SOURCEMAP_OUTPUT);

await runHermesEmitBinaryCommand(
_jsBundleName,
OUTPUT_CONTENT_PATH,
Expand All @@ -61,3 +65,28 @@ export async function bundleCodePush(

return codePushBundleFileName;
}

function copyMetroOutputsIfNeeded(
outputRootPath: string,
outputMetroDir: string | undefined,
outputContentPath: string,
jsBundleName: string,
sourceMapOutputPath: string,
) {
if (!outputMetroDir) {
return;
}

const resolvedOutputMetroDir = path.join(outputRootPath, outputMetroDir);

fs.mkdirSync(resolvedOutputMetroDir, { recursive: true });
fs.copyFileSync(
path.join(outputContentPath, jsBundleName),
path.join(resolvedOutputMetroDir, jsBundleName),
);
fs.copyFileSync(
sourceMapOutputPath,
path.join(resolvedOutputMetroDir, path.basename(sourceMapOutputPath)),
);
console.log(`log: Metro outputs copied to: ${resolvedOutputMetroDir}`);
}
3 changes: 3 additions & 0 deletions cli/commands/bundleCommand/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type Options = {
entryFile: string;
bundleName: string;
outputBundleDir: string;
outputMetroDir?: string;
}

program.command('bundle')
Expand All @@ -18,6 +19,7 @@ program.command('bundle')
.option('-o, --output-path <string>', 'path to output root directory', ROOT_OUTPUT_DIR)
.option('-e, --entry-file <string>', 'path to JS/TS entry file', ENTRY_FILE)
.option('-b, --bundle-name <string>', 'bundle file name (default-ios: "main.jsbundle" / default-android: "index.android.bundle")')
.option('--output-metro-dir <string>', 'name of directory to copy the Metro JS bundle and sourcemap before Hermes compilation')
.option('--output-bundle-dir <string>', 'name of directory containing the bundle file created by the "bundle" command', OUTPUT_BUNDLE_DIR)
.action((options: Options) => {
bundleCodePush(
Expand All @@ -27,5 +29,6 @@ program.command('bundle')
options.entryFile,
options.bundleName,
`${options.outputPath}/${options.outputBundleDir}`,
options.outputMetroDir,
)
});
3 changes: 3 additions & 0 deletions cli/commands/releaseCommand/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type Options = {
skipBundle: boolean;
skipCleanup: boolean;
outputBundleDir: string;
outputMetroDir?: string;
hashCalc?: boolean;
}

Expand All @@ -39,6 +40,7 @@ program.command('release')
.option('--skip-bundle <bool>', 'skip bundle process', parseBoolean, false)
.option('--hash-calc <bool>', 'calculates the bundle file hash used for packageHash in the release history (Requires setting --skip-bundle to true)', parseBoolean)
.option('--skip-cleanup <bool>', 'skip cleanup process', parseBoolean, false)
.option('--output-metro-dir <string>', 'name of directory to copy the Metro JS bundle and sourcemap before Hermes compilation')
.option('--output-bundle-dir <string>', 'name of directory containing the bundle file created by the "bundle" command', OUTPUT_BUNDLE_DIR)
.action(async (options: Options) => {
const config = findAndReadConfigFile(process.cwd(), options.config);
Expand Down Expand Up @@ -71,6 +73,7 @@ program.command('release')
options.skipBundle,
options.skipCleanup,
`${options.outputPath}/${options.outputBundleDir}`,
options.outputMetroDir,
options.hashCalc,
)

Expand Down
3 changes: 2 additions & 1 deletion cli/commands/releaseCommand/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ export async function release(
skipBundle: boolean,
skipCleanup: boolean,
bundleDirectory: string,
outputMetroDir?: string,
hashCalc?: boolean,
): Promise<void> {
const bundleFileName = skipBundle
? readBundleFileNameFrom(bundleDirectory)
: await bundleCodePush(framework, platform, outputPath, entryFile, jsBundleName, bundleDirectory);
: await bundleCodePush(framework, platform, outputPath, entryFile, jsBundleName, bundleDirectory, outputMetroDir);
const bundleFilePath = `${bundleDirectory}/${bundleFileName}`;

const packageHash = await (() => {
Expand Down
Loading