@@ -27,6 +27,10 @@ set -e
2727THIS_DIR=$( cd -P " $( dirname " $( readlink " ${BASH_SOURCE[0]} " || echo " ${BASH_SOURCE[0]} " ) " ) " && pwd)
2828TEMP_DIR=$( mktemp -d /tmp/react-native-codegen-XXXXXXXX)
2929RN_DIR=$( cd " $THIS_DIR /.." && pwd)
30+
31+ # find node path
32+ source " $RN_DIR /scripts/find-node.sh"
33+
3034NODE_BINARY=" ${NODE_BINARY:- $(command -v node || true)} "
3135USE_FABRIC=" ${USE_FABRIC:- 0} "
3236
@@ -53,33 +57,19 @@ main() {
5357 TEMP_OUTPUT_DIR=" $TEMP_DIR /out"
5458 SCHEMA_FILE=" $TEMP_DIR /schema.json"
5559
56- CODEGEN_REPO_PATH=" $RN_DIR /packages/react-native-codegen"
57- CODEGEN_NPM_PATH=" $RN_DIR /../react-native-codegen"
58-
59- if [ -z " $NODE_BINARY " ]; then
60+ if [ -z " $NODE_BINARY " ]; then
6061 echo " Error: Could not find node. Make sure it is in bash PATH or set the NODE_BINARY environment variable." 1>&2
6162 exit 1
6263 fi
6364
64- if [ -d " $CODEGEN_REPO_PATH " ]; then
65- CODEGEN_PATH=$( cd " $CODEGEN_REPO_PATH " && pwd)
66- elif [ -d " $CODEGEN_NPM_PATH " ]; then
67- CODEGEN_PATH=$( cd " $CODEGEN_NPM_PATH " && pwd)
68- else
69- echo " Error: Could not determine react-native-codegen location. Try running 'yarn install' or 'npm install' in your project root." 1>&2
70- exit 1
71- fi
65+ CODEGEN_PATH=$( " $NODE_BINARY " -e " console.log(require('path').dirname(require.resolve('react-native-codegen/package.json')))" )
7266
67+ # Special case for running CodeGen from source: build it
7368 if [ ! -d " $CODEGEN_PATH /lib" ]; then
7469 describe " Building react-native-codegen package"
7570 bash " $CODEGEN_PATH /scripts/oss/build.sh"
7671 fi
7772
78- if [ -z " $NODE_BINARY " ]; then
79- echo " Error: Could not find node. Make sure it is in bash PATH or set the NODE_BINARY environment variable." 1>&2
80- exit 1
81- fi
82-
8373 describe " Generating schema from flow types"
8474 " $NODE_BINARY " " $CODEGEN_PATH /lib/cli/combine/combine-js-to-schema-cli.js" " $SCHEMA_FILE " " $SRCS_DIR "
8575
0 commit comments