From 481f4d769b895d7108b6f61d37d36ae4d2f4bb4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Gu=CC=88ner?= Date: Fri, 5 Jul 2024 16:26:51 +0300 Subject: [PATCH] feat: codegen command for bob cli --- .../react-native-builder-bob/src/index.ts | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/packages/react-native-builder-bob/src/index.ts b/packages/react-native-builder-bob/src/index.ts index e8ae2f96e..b04add1f2 100644 --- a/packages/react-native-builder-bob/src/index.ts +++ b/packages/react-native-builder-bob/src/index.ts @@ -11,6 +11,8 @@ import buildCommonJS from './targets/commonjs'; import buildModule from './targets/module'; import buildTypescript from './targets/typescript'; import type { Options } from './types'; +import { patchCodegen } from './utils/patchCodegen'; +import spawn from 'cross-spawn'; // eslint-disable-next-line import/no-commonjs, @typescript-eslint/no-var-requires const { name, version } = require('../package.json'); @@ -453,6 +455,33 @@ yargs } } }) + .command( + 'codegen', + 'generate codegen from typescript specs', + {}, + async () => { + const packageJsonPath = path.resolve(root, 'package.json'); + if (!(await fs.pathExists(packageJsonPath))) { + logger.exit( + `Couldn't find a 'package.json' file in '${root}'. Are you in a project folder?` + ); + } + + spawn.sync('npx', ['react-native', 'codegen'], { + stdio: 'inherit', + }); + + patchCodegen(root); + + console.log( + dedent` + ${kleur.green('Codegen patched successfully!')} + + ${kleur.yellow('Good luck!')} + ` + ); + } + ) .demandCommand() .recommendCommands() .strict().argv;