mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
3af21381df
Summary: This commit: * Generate Fabric component Java files along side Java NativeModule specs, when `USE_FABRIC=1` is set * Adjust the component codegen to place output files in a subdir based on package name * Adjust existing Buck targets to filter the right nativemodule vs component java files (this avoids duplicated symbols) * Compiles the Java output during build time on RNTester/ReactAndroid (Gradle) Not in this commit: * Fabric C++ files * Removing checked-in generated component files. Changelog: [Internal] Reviewed By: mdvacca Differential Revision: D25416614 fbshipit-source-id: fd670ead2198c9b5a65812c692b7aed9f3d7cd58
92 lines
1.9 KiB
JavaScript
92 lines
1.9 KiB
JavaScript
/**
|
|
* Copyright (c) Facebook, Inc. and its 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';
|
|
|
|
let RNCodegen;
|
|
try {
|
|
RNCodegen = require('react-native-codegen/lib/generators/RNCodegen.js');
|
|
} catch (e) {
|
|
RNCodegen = require('../packages/react-native-codegen/lib/generators/RNCodegen.js');
|
|
if (!RNCodegen) {
|
|
throw 'RNCodegen not found.';
|
|
}
|
|
}
|
|
|
|
const fs = require('fs');
|
|
const mkdirp = require('mkdirp');
|
|
const path = require('path');
|
|
|
|
const USE_FABRIC = process.env.USE_FABRIC != null && !!process.env.USE_FABRIC;
|
|
|
|
const GENERATORS = {
|
|
android: USE_FABRIC
|
|
? ['componentsAndroid', 'modulesAndroid']
|
|
: ['modulesAndroid'],
|
|
ios: ['modulesIOS'],
|
|
};
|
|
|
|
function generateSpec(
|
|
platform,
|
|
schemaPath,
|
|
outputDirectory,
|
|
libraryName,
|
|
packageName,
|
|
) {
|
|
const moduleSpecName = libraryName;
|
|
const schemaText = fs.readFileSync(schemaPath, 'utf-8');
|
|
|
|
if (schemaText == null) {
|
|
throw new Error(`Can't find schema at ${schemaPath}`);
|
|
}
|
|
|
|
if (!outputDirectory) {
|
|
outputDirectory = path.resolve(
|
|
__dirname,
|
|
'..',
|
|
'Libraries',
|
|
libraryName,
|
|
moduleSpecName,
|
|
);
|
|
}
|
|
mkdirp.sync(outputDirectory);
|
|
|
|
let schema;
|
|
try {
|
|
schema = JSON.parse(schemaText);
|
|
} catch (err) {
|
|
throw new Error(`Can't parse schema to JSON. ${schemaPath}`);
|
|
}
|
|
|
|
RNCodegen.generate(
|
|
{
|
|
libraryName,
|
|
schema,
|
|
outputDirectory,
|
|
moduleSpecName,
|
|
packageName,
|
|
},
|
|
{
|
|
generators: GENERATORS[platform],
|
|
},
|
|
);
|
|
}
|
|
|
|
function main() {
|
|
const args = process.argv.slice(2);
|
|
const platform = args[0];
|
|
const schemaPath = args[1];
|
|
const outputDir = args[2];
|
|
const libraryName = args[3] || 'FBReactNativeSpec';
|
|
const javaPackageName = args[4] || 'com.facebook.fbreact.specs';
|
|
generateSpec(platform, schemaPath, outputDir, libraryName, javaPackageName);
|
|
}
|
|
|
|
main();
|