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
19 changes: 10 additions & 9 deletions src/bundle/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ import { info, rmRf, execCommand, buildBundleConfig, mkdir } from './utils'
import type { BundleArgs, BundlerConfig, Hashes } from './types'
import { checkout, gitRestore } from './git'
import { hashes, removeUnchangedAssets } from './diff'
import { metroBundle } from './metroBundle'

const {
runHermesEmitBinaryCommand,
runReactNativeBundleCommand,
} = require('appcenter-cli/dist/commands/codepush/lib/react-native-utils')
const { runHermesEmitBinaryCommand } = require('appcenter-cli/dist/commands/codepush/lib/react-native-utils')

export async function bundle(args: BundleArgs) {
const { base } = args
Expand Down Expand Up @@ -40,6 +38,7 @@ export async function bundle(args: BundleArgs) {

const bundleReactNative = async (config: BundlerConfig, shouldBuildSourceMaps?: boolean) => {
const {
bundleCommand,
bundleName,
entryFile,
os,
Expand All @@ -57,15 +56,17 @@ const bundleReactNative = async (config: BundlerConfig, shouldBuildSourceMaps?:
info(`Using '${config.reinstallNodeModulesCommand}' to install node modules`)
await execCommand(config.reinstallNodeModulesCommand)

await runReactNativeBundleCommand(
metroBundle({
bundleCommand,
bundleName,
false, // development
development: false,
entryFile,
outputDir,
os, // platform
platform: os,
sourcemapOutput,
['--reset-cache', ...extraBundlerOptions]
)
extraBundlerOptions,
})

if (shouldBuildSourceMaps && useHermes) {
await runHermesEmitBinaryCommand(bundleName, outputDir, sourcemapOutput, extraHermesFlags)
}
Expand Down
50 changes: 50 additions & 0 deletions src/bundle/metroBundle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const path = require('path')
const { spawnSync } = require('child_process')

interface MetroBundleOptions {
platform: string
entryFile: string
outputDir?: string
development?: boolean
resetCache?: boolean
bundleName?: string
bundleOutput?: string
assetsDest?: string
sourcemapOutputDir?: string
sourcemapOutput?: string
bundleCommand?: string
extraBundlerOptions?: string[]
}

export const metroBundle = ({
platform,
entryFile,
outputDir = '',
development = false,
resetCache = true,
bundleCommand = 'bundle',
bundleName,
bundleOutput = path.join(outputDir, bundleName),
assetsDest = outputDir,
sourcemapOutputDir = '',
sourcemapOutput = sourcemapOutputDir ? path.join(sourcemapOutputDir, `${bundleName}.map`) : null,
extraBundlerOptions = [],
}: MetroBundleOptions) => {
const args = [
bundleCommand,
`--platform=${platform}`,
`--entry-file=${entryFile}`,
`--dev=${development}`,
`--bundle-output=${bundleOutput}`,
sourcemapOutput && `--sourcemap-output=${sourcemapOutput}`,
assetsDest && `--assets-dest=${assetsDest}`,
resetCache && '--reset-cache',
...extraBundlerOptions,
].filter(Boolean)

spawnSync(getCliPath(), args, { stdio: 'inherit' })
}

function getCliPath() {
return path.join('node_modules', '.bin', 'react-native')
}
1 change: 1 addition & 0 deletions src/bundle/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface BundlerConfig {
sourcemapOutputDir: string
useHermes?: boolean
extraHermesFlags?: string[]
bundleCommand?: string
}

type Config = Partial<BundlerConfig> & VersionSearchParams
Expand Down
1 change: 1 addition & 0 deletions src/cli/bundleArgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export const bundleArgs = <T = {}>(yargs: Argv<T>) =>
.option('base', { type: 'string', demandOption: true })
.option('reinstallNodeModulesCommand', { type: 'string', alias: ['npm'] })
.option('rest', { type: 'string', default: '' })
.option('bundle-command', { type: 'string' })