import { program, Option } from "commander"; import { bundleCodePush } from "./bundleCodePush.js"; import { resolveBinaryBundlePathOption } from "../../functions/makeBinaryPatchBundle.js"; import { OUTPUT_BUNDLE_DIR, ROOT_OUTPUT_DIR, ENTRY_FILE } from "../../constant.js"; type Options = { framework: 'expo' | undefined; platform: 'ios' | 'android'; outputPath: string; entryFile: string; // Commander derives this from the "-b, --bundle-name" flag. bundleName?: string; outputBundleDir: string; outputMetroDir?: string; binaryBundlePath?: string; } program.command('bundle') .description('Creates a CodePush bundle file (assumes Hermes is enabled).') .addOption(new Option('-f, --framework ', 'framework type (expo)').choices(['expo'])) .addOption(new Option('-p, --platform ', 'platform').choices(['ios', 'android']).default('ios')) .option('-o, --output-path ', 'path to output root directory', ROOT_OUTPUT_DIR) .option('-e, --entry-file ', 'path to JS/TS entry file', ENTRY_FILE) .option('-b, --bundle-name ', 'bundle file name (default-ios: "main.jsbundle" / default-android: "index.android.bundle")') .option('--output-metro-dir ', 'name of directory to copy the Metro JS bundle and sourcemap before Hermes compilation') .option('--output-bundle-dir ', 'name of directory containing the bundle file created by the "bundle" command', OUTPUT_BUNDLE_DIR) .option('--binary-bundle-path ', 'path to the JS bundle of the target binary. Aligns the Hermes compilation with it and records it as the binary patch base.') .action((options: Options) => { // Resolved before bundling so a wrong path fails now rather than after a build. const baseBundlePath = resolveBinaryBundlePathOption(options.binaryBundlePath); bundleCodePush( options.framework, options.platform, options.outputPath, options.entryFile, options.bundleName, `${options.outputPath}/${options.outputBundleDir}`, options.outputMetroDir, baseBundlePath, ) });