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
This commit is contained in:
Riccardo Cipolleschi
2024-02-29 07:17:02 -08:00
committed by Facebook GitHub Bot
parent 23c541046c
commit 9a27c08fb9
@@ -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,