Files
react-native/packages/react-native/react-native.config.js
T
Riccardo Cipolleschi 4e5da2ea1d Add extra parameter to define whether codegen is invoked by lib or app (#48995)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/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
2025-03-18 15:30:31 +00:00

110 lines
2.6 KiB
JavaScript

/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
'use strict';
// React Native shouldn't be exporting itself like this, the Community Template should be be directly
// depending on and injecting:
// - @react-native-community/cli-platform-android
// - @react-native-community/cli-platform-ios
// - @react-native/community-cli-plugin (via the @react-native/core-cli-utils package)
// - codegen command should be inhoused into @react-native-community/cli
//
// This is a temporary workaround.
const verbose = process.env.DEBUG && process.env.DEBUG.includes('react-native');
let android;
try {
android = require('@react-native-community/cli-platform-android');
} catch {
if (verbose) {
console.warn(
'@react-native-community/cli-platform-android not found, the react-native.config.js may be unusable.',
);
}
}
let ios;
try {
ios = require('@react-native-community/cli-platform-ios');
} catch {
if (verbose) {
console.warn(
'@react-native-community/cli-platform-ios not found, the react-native.config.js may be unusable.',
);
}
}
const commands = [];
const {
bundleCommand,
startCommand,
} = require('@react-native/community-cli-plugin');
commands.push(bundleCommand, startCommand);
const codegenCommand = {
name: 'codegen',
options: [
{
name: '--path <path>',
description: 'Path to the React Native project root.',
default: process.cwd(),
},
{
name: '--platform <string>',
description:
'Target platform. Supported values: "android", "ios", "all".',
default: 'all',
},
{
name: '--outputPath <path>',
description: 'Path where generated artifacts will be output to.',
},
{
name: '--source <string>',
description: 'Whether the script is invoked from an `app` or a `library`',
default: 'app',
},
],
func: (argv, config, args) =>
require('./scripts/codegen/generate-artifacts-executor').execute(
args.path,
args.platform,
args.outputPath,
args.source,
),
};
commands.push(codegenCommand);
const config = {
commands,
platforms: {},
};
if (ios != null) {
config.commands.push(...ios.commands);
config.platforms.ios = {
projectConfig: ios.projectConfig,
dependencyConfig: ios.dependencyConfig,
};
}
if (android != null) {
config.commands.push(...android.commands);
config.platforms.android = {
projectConfig: android.projectConfig,
dependencyConfig: android.dependencyConfig,
};
}
module.exports = config;