-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add script to generate native modules specs with react-native-codegen
Summary: Adds a script that uses `react-native-codegen` to generate FBReactNativeSpec. The generated output should not be considered ready for production use at this time. The goal of adding this script at this time is to demonstrate the current status of native modules specs code generation in open source. For example, the generated output may be used in RNTester, with some modifications due to some naming differences in react-native-codegen's output when compared to the FBReactNativeSpec files generated by the old codegen. Usage: ``` ./scripts/generate-native-modules-specs.sh ./codegen-out ``` Changelog: [Internal] Reviewed By: TheSavior Differential Revision: D21471004 fbshipit-source-id: 5ff3c57807d9ba2c91dc7fe32d227d218732b059
- Loading branch information
1 parent
164d47f
commit 91a49d8
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/bin/bash | ||
# 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. | ||
|
||
# This script collects the JavaScript spec definitions for native | ||
# modules, then uses react-native-codegen to generate native code. | ||
# The script will copy the generated code to the final location by | ||
# default. Optionally, call the script with a path to the desired | ||
# output location. | ||
# | ||
# Usage: | ||
# ./scripts/generate-native-modules-specs.sh [output-dir] | ||
# | ||
# Example: | ||
# ./scripts/generate-native-modules-specs.sh ./codegen-out | ||
|
||
# shellcheck disable=SC2038 | ||
|
||
set -e | ||
|
||
describe () { | ||
printf "\\n\\n>>>>> %s\\n\\n\\n" "$1" | ||
} | ||
|
||
THIS_DIR=$(cd -P "$(dirname "$(readlink "${BASH_SOURCE[0]}" || echo "${BASH_SOURCE[0]}")")" && pwd) | ||
RN_DIR=$(cd "$THIS_DIR/.." && pwd) | ||
|
||
TEMP_DIR=$(mktemp -d /tmp/react-native-codegen-XXXXXXXX) | ||
|
||
SRCS_DIR=$(cd "$RN_DIR/Libraries" && pwd) | ||
LIBRARY_NAME="FBReactNativeSpec" | ||
MODULE_SPEC_NAME="FBReactNativeSpec" | ||
|
||
SCHEMA_FILE="$RN_DIR/schema-native-modules.json" | ||
OUTPUT_DIR="$SRCS_DIR/$LIBRARY_NAME/$MODULE_SPEC_NAME" | ||
|
||
describe "Generating schema from flow types" | ||
grep --exclude NativeUIManager.js --include=Native\*.js -rnwl "$SRCS_DIR" -e 'export interface Spec extends TurboModule' -e "export default \(TurboModuleRegistry.get(Enforcing)?<Spec>\('.*\): Spec\);/" \ | ||
| xargs yarn flow-node packages/react-native-codegen/src/cli/combine/combine-js-to-schema-cli.js "$SCHEMA_FILE" | ||
|
||
describe "Generating native code from schema" | ||
yarn flow-node packages/react-native-codegen/buck_tests/generate-tests.js "$SCHEMA_FILE" "$LIBRARY_NAME" "$TEMP_DIR" "$MODULE_SPEC_NAME" | ||
|
||
if [ -n "$1" ]; then | ||
OUTPUT_DIR="$1" | ||
mkdir -p "$OUTPUT_DIR" | ||
fi | ||
|
||
describe "Copying $MODULE_SPEC_NAME output to $OUTPUT_DIR" | ||
cp "$TEMP_DIR"/$MODULE_SPEC_NAME* "$OUTPUT_DIR/." |