From 9a27c08fb9c80eb4b65a8dc7bd96db09e301bf72 Mon Sep 17 00:00:00 2001 From: Riccardo Cipolleschi Date: Thu, 29 Feb 2024 07:17:02 -0800 Subject: [PATCH] Add script to generate RNCore components only Summary: This change extracts the function to create RNCore components in a separate reusable unit. RNCore is now generate in the `node_modules` folder when the app runs pod install, which is a problem because there are use cases where it's not possible to modify the `node_modules` folder or the generated files might be lost. The goal is to: - extract this function - execute this function before packing react-native during the release. (see D54308411) In this way, we are going to generate the RNCore files in the react-native path that will be packaged and then released. Users of react-native will have the generated code directly in the node_modules with no need to generate it. ## Changelog: [General][Added] - Add function to only generate RNCore components Reviewed By: huntie Differential Revision: D54308713 fbshipit-source-id: 0fa9ab4ba7b66c577663f0c736742c4d5583f617 --- .../codegen/generate-artifacts-executor.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/react-native/scripts/codegen/generate-artifacts-executor.js b/packages/react-native/scripts/codegen/generate-artifacts-executor.js index 3c84671a876..ca6ac08689d 100644 --- a/packages/react-native/scripts/codegen/generate-artifacts-executor.js +++ b/packages/react-native/scripts/codegen/generate-artifacts-executor.js @@ -593,6 +593,22 @@ function cleanupEmptyFilesAndFolders(filepath) { } } +function generateRNCoreComponentsIOS(projectRoot /*: string */) /*: void*/ { + const ios = 'ios'; + buildCodegenIfNeeded(); + const pkgJson = readPkgJsonInDirectory(projectRoot); + const rncoreLib = findProjectRootLibraries(pkgJson, projectRoot).filter( + library => library.config.name === 'rncore', + )[0]; + if (!rncoreLib) { + throw new Error( + "[Codegen] Can't find rncore library. Failed to generate rncore artifacts", + ); + } + const rncoreSchemaInfo = generateSchemaInfo(rncoreLib, ios); + generateCode('', rncoreSchemaInfo, false, ios); +} + // Execute /** @@ -686,7 +702,8 @@ function execute(projectRoot, targetPlatform, baseOutputPath) { } module.exports = { - execute: execute, + execute, + generateRNCoreComponentsIOS, // exported for testing purposes only: _extractLibrariesFromJSON: extractLibrariesFromJSON, _cleanupEmptyFilesAndFolders: cleanupEmptyFilesAndFolders,