Skip to content

Commit 4e5da2e

Browse files
cipolleschirobhogan
authored andcommitted
Add extra parameter to define whether codegen is invoked by lib or app (facebook#48995)
Summary: Pull Request resolved: facebook#48995 This change adds an extra parameter to the codegen script that allow our users to trigger codegen for Apps or for Libraries. When running codegen for Apps, we have to generate some extra files that are not needed by the Libraries. This is causing issues to our library maintainers and this change will provide more flexibility in the DevX of libraries. The default value is App, so if the new parameter is not passed, nothing will change in the current behavior. [iOS][Added] - Add the `source` parameter to generate-codegen-artifacts to avoid generating files not needed by libraries. Reviewed By: cortinico Differential Revision: D68765478 fbshipit-source-id: 8030b4472ad4f5058e58b1c91089de5122a4f60a
1 parent 1f002f9 commit 4e5da2e

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

packages/react-native/react-native.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,18 @@ const codegenCommand = {
6868
name: '--outputPath <path>',
6969
description: 'Path where generated artifacts will be output to.',
7070
},
71+
{
72+
name: '--source <string>',
73+
description: 'Whether the script is invoked from an `app` or a `library`',
74+
default: 'app',
75+
},
7176
],
7277
func: (argv, config, args) =>
7378
require('./scripts/codegen/generate-artifacts-executor').execute(
7479
args.path,
7580
args.platform,
7681
args.outputPath,
82+
args.source,
7783
),
7884
};
7985

packages/react-native/scripts/codegen/generate-artifacts-executor.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -899,11 +899,12 @@ function generateFBReactNativeSpecIOS(projectRoot /*: string */) /*: void*/ {
899899
* @parameter projectRoot: the directory with the app source code, where the package.json lives.
900900
* @parameter baseOutputPath: the base output path for the CodeGen.
901901
* @parameter targetPlatform: the target platform. Supported values: 'android', 'ios', 'all'.
902+
* @parameter source: the source that is invoking codegen. Supported values: 'app', 'library'.
902903
* @throws If it can't find a config file for react-native.
903904
* @throws If it can't find a CodeGen configuration in the file.
904905
* @throws If it can't find a cli for the CodeGen.
905906
*/
906-
function execute(projectRoot, targetPlatform, baseOutputPath) {
907+
function execute(projectRoot, targetPlatform, baseOutputPath, source) {
907908
try {
908909
codegenLog(`Analyzing ${path.join(projectRoot, 'package.json')}`);
909910

@@ -951,9 +952,12 @@ function execute(projectRoot, targetPlatform, baseOutputPath) {
951952
platform,
952953
);
953954

954-
generateRCTThirdPartyComponents(libraries, outputPath);
955-
generateCustomURLHandlers(libraries, outputPath);
956-
generateAppDependencyProvider(outputPath);
955+
if (source === 'app') {
956+
// These components are only required by apps, not by libraries
957+
generateRCTThirdPartyComponents(libraries, outputPath);
958+
generateCustomURLHandlers(libraries, outputPath);
959+
generateAppDependencyProvider(outputPath);
960+
}
957961

958962
cleanupEmptyFilesAndFolders(outputPath);
959963
}

packages/react-native/scripts/generate-codegen-artifacts.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ const argv = yargs
2525
alias: 'outputPath',
2626
description: 'Path where generated artifacts will be output to.',
2727
})
28+
.option('s', {
29+
alias: 'source',
30+
description: 'Whether the script is invoked from an `app` or a `library`',
31+
default: 'app',
32+
})
2833
.usage('Usage: $0 -p [path to app] -t [target platform] -o [output path]')
2934
.demandOption(['p', 't']).argv;
3035

31-
executor.execute(argv.path, argv.targetPlatform, argv.outputPath);
36+
executor.execute(argv.path, argv.targetPlatform, argv.outputPath, argv.source);

0 commit comments

Comments
 (0)