Skip to content

Commit

Permalink
Introduce "outputDir" property of "codegenConfig" (#41782)
Browse files Browse the repository at this point in the history
Summary:

This diff adds `outputDir` property to `codegenConfig`.
Now codegen output dir is resolved like this:
1. It is set to `outputDir` argument of `generate-codegen-artifacts.js` if it is present.
2. *[New]* It is set to `outputDir` property of `codegenConfig` if it is present.
3. It is set to the project root.

Changelog: [General][Added] - Introduce "outputDir" property of "codegenConfig"

Reviewed By: cipolleschi

Differential Revision: D51494009
  • Loading branch information
dmytrorykun authored and facebook-github-bot committed Dec 4, 2023
1 parent 5754b4a commit 9026e9b
Showing 1 changed file with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,8 @@ function buildCodegenIfNeeded() {
});
}

function computeIOSOutputDir(outputPath, projectRoot) {
return path.join(
outputPath ? outputPath : projectRoot,
'build/generated/ios',
);
function computeIOSOutputDir(outputPath) {
return path.join(outputPath, 'build', 'generated', 'ios');
}

function generateSchemaInfo(library) {
Expand Down Expand Up @@ -264,8 +261,7 @@ function createComponentProvider(schemas) {
console.log(`Generated provider in: ${outputDir}`);
}

function findCodegenEnabledLibraries(projectRoot) {
const pkgJson = readPkgJsonInDirectory(projectRoot);
function findCodegenEnabledLibraries(pkgJson, projectRoot) {
return [
...findExternalLibraries(pkgJson),
...findProjectRootLibraries(pkgJson, projectRoot),
Expand Down Expand Up @@ -321,17 +317,30 @@ function cleanupEmptyFilesAndFolders(filepath) {
* @throws If it can't find a cli for the CodeGen.
*/
function execute(projectRoot, outputPath) {
buildCodegenIfNeeded();

try {
const libraries = findCodegenEnabledLibraries(projectRoot);
const pkgJson = readPkgJsonInDirectory(projectRoot);
if (!(pkgJson.codegenConfig && typeof pkgJson.codegenConfig === 'object')) {
throw `[Codegen] Error: package.json in ${pkgJsonPath} must contain "codegenConfig" object.`;
}

buildCodegenIfNeeded();

const libraries = findCodegenEnabledLibraries(pkgJson, projectRoot);

if (libraries.length === 0) {
console.log('[Codegen] No codegen-enabled libraries found.');
return;
}

const iosOutputDir = computeIOSOutputDir(outputPath, projectRoot);
if (outputPath == null) {
const outputPathOverride = pkgJson.codegenConfig.outputDir;
if (outputPathOverride && typeof outputPathOverride === 'string') {
outputPath = outputPathOverride;
} else {
outputPath = projectRoot;
}
}
const iosOutputDir = computeIOSOutputDir(outputPath);

const schemaInfos = generateSchemaInfos(libraries);
generateNativeCode(iosOutputDir, schemaInfos);
Expand Down

0 comments on commit 9026e9b

Please sign in to comment.