|
1 | | -def rngh_try_to_parse_react_native_package_json(react_native_dir) |
2 | | - react_native_package_json_path = File.join(react_native_dir, 'package.json') |
| 1 | +module GestureHandlerUtils |
| 2 | + module_function |
3 | 3 |
|
4 | | - if !File.exist?(react_native_package_json_path) |
5 | | - return nil |
| 4 | + def try_to_parse_react_native_package_json(react_native_dir) |
| 5 | + react_native_package_json_path = File.join(react_native_dir, 'package.json') |
| 6 | + |
| 7 | + if !File.exist?(react_native_package_json_path) |
| 8 | + return nil |
| 9 | + end |
| 10 | + |
| 11 | + return JSON.parse(File.read(react_native_package_json_path)) |
6 | 12 | end |
7 | 13 |
|
8 | | - return JSON.parse(File.read(react_native_package_json_path)) |
9 | | -end |
| 14 | + def get_react_native_minor_version() |
| 15 | + react_native_dir = File.dirname(`cd "#{Pod::Config.instance.installation_root.to_s}" && node --print "require.resolve('react-native/package.json')"`) |
| 16 | + react_native_json = try_to_parse_react_native_package_json(react_native_dir) |
10 | 17 |
|
11 | | -def rngh_get_react_native_minor_version() |
12 | | - react_native_dir = File.dirname(`cd "#{Pod::Config.instance.installation_root.to_s}" && node --print "require.resolve('react-native/package.json')"`) |
13 | | - react_native_json = rngh_try_to_parse_react_native_package_json(react_native_dir) |
| 18 | + if react_native_json == nil |
| 19 | + node_modules_dir = ENV["REACT_NATIVE_NODE_MODULES_DIR"] |
| 20 | + if node_modules_dir != nil |
| 21 | + react_native_json = try_to_parse_react_native_package_json(File.join(node_modules_dir, 'react-native')) |
| 22 | + end |
| 23 | + end |
14 | 24 |
|
15 | | - if react_native_json == nil |
16 | | - node_modules_dir = ENV["REACT_NATIVE_NODE_MODULES_DIR"] |
17 | | - react_native_json = rngh_try_to_parse_react_native_package_json(File.join(node_modules_dir, 'react-native')) |
18 | | - end |
| 25 | + if react_native_json == nil |
| 26 | + raise '[react-native-gesture-handler] Unable to recognize your `react-native` version. Please set environmental variable with `react-native` location: `export REACT_NATIVE_NODE_MODULES_DIR="<path to react-native>" && pod install`.' |
| 27 | + end |
19 | 28 |
|
20 | | - if react_native_json == nil |
21 | | - raise '[react-native-gesture-handler] Unable to recognize your `react-native` version. Please set environmental variable with `react-native` location: `export REACT_NATIVE_NODE_MODULES_DIR="<path to react-native>" && pod install`.' |
| 29 | + return react_native_json['version'].split('.')[1].to_i |
22 | 30 | end |
23 | | - |
24 | | - return react_native_json['version'].split('.')[1].to_i |
25 | 31 | end |
0 commit comments