Skip to content

Commit

Permalink
Support monorepo/custom configuration where node_modules may not be l…
Browse files Browse the repository at this point in the history
…ocated under app_root

Summary:
This diff supports monorepo/custom configuration where node_modules may not be located under app_root.

The default (RN_root, '..') should support most cases, but I also added an option to provide a custom location for users to set.

Changelog: [internal]

Reviewed By: ShikaSD

Differential Revision: D32469957

fbshipit-source-id: 6b8a6c775c21bde72ef542e34973701d698f678f
  • Loading branch information
sota000 authored and facebook-github-bot committed Nov 18, 2021
1 parent 9822464 commit 5e93cf6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
19 changes: 13 additions & 6 deletions scripts/generate-artifacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,18 @@ const argv = yargs
description: 'A flag to control whether to generate fabric components.',
boolean: 'e',
})
.option('c', {
alias: 'configFileDir',
default: '',
description:
'Path where codegen config files are located (e.g. node_modules dir).',
})
.usage('Usage: $0 -p [path to app]')
.demandOption(['p']).argv;

const RN_ROOT = path.join(__dirname, '..');
const CODEGEN_CONFIG_FILENAME = argv.f;
const CODEGEN_CONFIG_FILE_DIR = argv.c;
const CODEGEN_CONFIG_KEY = argv.k;
const CODEGEN_FABRIC_ENABLED = argv.e;
const CODEGEN_REPO_PATH = `${RN_ROOT}/packages/react-native-codegen`;
Expand Down Expand Up @@ -80,18 +87,15 @@ function main(appRootDir, outputPath) {
const dependencies = {...pkgJson.dependencies, ...pkgJson.devDependencies};

// 3. Determine which of these are codegen-enabled libraries
const confifDir = CODEGEN_CONFIG_FILE_DIR || path.join(RN_ROOT, '..');
console.log(
`\n\n[Codegen] >>>>> Searching for codegen-enabled libraries in ${appRootDir}`,
`\n\n[Codegen] >>>>> Searching for codegen-enabled libraries in ${confifDir}`,
);
const libraries = [];

// Handle react-native and third-party libraries
Object.keys(dependencies).forEach(dependency => {
const codegenConfigFileDir = path.join(
appRootDir,
'node_modules',
dependency,
);
const codegenConfigFileDir = path.join(confifDir, dependency);
const configFilePath = path.join(
codegenConfigFileDir,
CODEGEN_CONFIG_FILENAME,
Expand Down Expand Up @@ -165,6 +169,9 @@ function main(appRootDir, outputPath) {
// 5. For each codegen-enabled library, generate the native code spec files
libraries.forEach(library => {
if (!CODEGEN_FABRIC_ENABLED && library.config.type === 'components') {
console.log(
`[Codegen] ${library.config.name} skipped because fabric is not enabled.`,
);
return;
}
const tmpDir = fs.mkdtempSync(
Expand Down
12 changes: 11 additions & 1 deletion scripts/react_native_pods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,18 @@ def use_react_native_codegen_discovery!(options={})
react_native_path = options[:react_native_path] ||= "../node_modules/react-native"
app_path = options[:app_path]
fabric_enabled = options[:fabric_enabled] ||= false
config_file_dir = options[:config_file_dir] ||= ''
if app_path
Pod::Executable.execute_command('node', ["#{react_native_path}/scripts/generate-artifacts.js", "-p", "#{app_path}", "-o", Pod::Config.instance.installation_root, "-e", "#{fabric_enabled}"])
out = Pod::Executable.execute_command(
'node',
[
"#{react_native_path}/scripts/generate-artifacts.js",
"-p", "#{app_path}",
"-o", Pod::Config.instance.installation_root,
"-e", "#{fabric_enabled}",
"-c", "#{config_file_dir}",
])
Pod::UI.puts out;
else
Pod::UI.warn '[Codegen] error: no app_path was provided'
exit 1
Expand Down

0 comments on commit 5e93cf6

Please sign in to comment.