@@ -100,11 +100,13 @@ done
100100cd " $NODE_MODULES_DIR /react-native"
101101
102102RN_DIR=" ./"
103+ SCRIPTS_PATH=" ./scripts/"
103104CODEGEN_REPO_PATH=" ../packages/react-native-codegen"
104105CODEGEN_NPM_PATH=" ../react-native-codegen"
105106SRCS_DIR=${SRCS_DIR:- $(cd " ./Libraries" && pwd)}
107+ RN_VERSION=$( cat ./package.json | grep -m 1 version | sed ' s/[^0-9.]//g' )
106108
107- RN_PODSPECS=$( find * -type f -name " *.podspec" -not -path " third-party-podspecs/*" -not -path " *Fabric*" -print)
109+ RN_PODSPECS=$( find * -type f -name " *.podspec" -not -name " React-rncore.podspec " -not - path " third-party-podspecs/*" -not -path " *Fabric*" -print)
108110TMP_DEST=$( mktemp -d)
109111
110112for podspec in $RN_PODSPECS
159161 bash " $CODEGEN_PATH /scripts/oss/build.sh"
160162 fi
161163
164+ # Generate React-Codegen
165+ # A copy of react_native_pods is done to modify the content within get_react_codegen_spec
166+ # this enables getting the schema for React-Codegen in runtime by printing the content.
167+ echo " Generating React-Codegen"
168+ REACT_NATIVE_PODS_PATH=" $SCRIPTS_PATH /react_native_pods.rb"
169+ REACT_NATIVE_PODS_MODIFIED_PATH=" $SCRIPTS_PATH /react_native_pods_modified.rb"
170+ # Making a temp copy of react_native_pods.rb
171+ cp $REACT_NATIVE_PODS_PATH $REACT_NATIVE_PODS_MODIFIED_PATH
172+ # Modify the get_react_codegen_spec method to return the result using print and JSON.pretty
173+ sed -i ' ' -e " s/:git => ''/:git => 'https:\/\/github.com\/facebook\/react-native.git', :tag => 'v$RN_VERSION '/" " $REACT_NATIVE_PODS_MODIFIED_PATH "
174+ sed -i ' ' -e ' s/return spec/print JSON.pretty_generate(spec)/' " $REACT_NATIVE_PODS_MODIFIED_PATH "
175+ # Run get_react_codegen_spec and generate React-Codegen.podspec.json
176+ ruby -r " ./scripts/react_native_pods_modified.rb" -e " get_react_codegen_spec" > " $DEST /React-Codegen.podspec.json"
177+ TMP_ReactCodeGenSpec=$( mktemp)
178+ jq ' .source_files = "third-party-podspecs/FBReactNativeSpec/**/*.{c,h,m,mm,cpp}"' " $DEST /React-Codegen.podspec.json" > " $TMP_ReactCodeGenSpec "
179+ mv " $TMP_ReactCodeGenSpec " " $DEST /React-Codegen.podspec.json"
180+ # Remove temp copy of react_native_pods.rb
181+ rm $REACT_NATIVE_PODS_MODIFIED_PATH
182+
162183 echo " Generating schema from Flow types"
163184 " $NODE_BINARY " " $CODEGEN_PATH /lib/cli/combine/combine-js-to-schema-cli.js" " $SCHEMA_FILE " " $SRCS_DIR "
164185
165186 echo " Generating native code from schema (iOS)"
166187 " $NODE_BINARY " " ./scripts/generate-specs-cli.js" -p " ios" -s " $SCHEMA_FILE " -o " $DEST /FBReactNativeSpec"
167188
189+ # Removing unneeded files
190+ find " $DEST /FBReactNativeSpec" -type f -not -name " FBReactNativeSpec.podspec.json" -not -name " FBReactNativeSpec-generated.mm" -not -name " FBReactNativeSpec.h" -not -name " FBReactNativeSpec.h" -delete
191+
168192 # Removing 'script_phases' that shouldn't be needed anymore.
169193 # Removing 'prepare_command' that includes additional steps to create intermediate folders to keep generated files which won't be needed.
170194 # Removing 'source.tag' as we'll use a commit hash from gutenberg-mobile instead.
0 commit comments