Skip to content

Commit

Permalink
feat: use node to call rnccli codegen
Browse files Browse the repository at this point in the history
  • Loading branch information
atlj committed Nov 15, 2024
1 parent a007633 commit 774fd98
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
8 changes: 3 additions & 5 deletions packages/react-native-builder-bob/src/targets/codegen.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import kleur from 'kleur';
import type { Input } from '../types';
import { patchCodegen } from '../utils/patchCodegen';
import { spawn } from '../utils/spawn';
import fs from 'fs-extra';
import path from 'path';
import del from 'del';
import { runRNCCli } from '../utils/runRNCCli';

type Options = Input;

Expand Down Expand Up @@ -33,11 +33,9 @@ export default async function build({ root, report }: Options) {
}

try {
await spawn('npx', ['@react-native-community/cli', 'codegen'], {
stdio: 'ignore',
});
await runRNCCli(['codegen']);

patchCodegen(root, packageJson, report);
await patchCodegen(root, packageJson, report);

report.success('Generated native code with codegen');
} catch (e: unknown) {
Expand Down
27 changes: 27 additions & 0 deletions packages/react-native-builder-bob/src/utils/runRNCCli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { type SpawnOptions } from 'node:child_process';
import { spawn } from './spawn';
import path from 'node:path';

const RNC_CLI_BINARY_PATH = path.resolve(
process.cwd(), // We are always expected to run in the library
'node_modules',
'.bin',
'rnc-cli'
);

// This is a special case for calling bob from the XCode scripts
// XCode scripts don't have the node binary properly set
// We expose an env value for node instead.
const NODE_BINARY = process.env['NODE_BINARY'] || 'node';

/**
* Runs the React Native Community CLI with the specified arguments
*/
export async function runRNCCli(
args: string[],
options: SpawnOptions = {
stdio: 'ignore',
}
) {
return await spawn(NODE_BINARY, [RNC_CLI_BINARY_PATH, ...args], options);
}

0 comments on commit 774fd98

Please sign in to comment.