-
-
Notifications
You must be signed in to change notification settings - Fork 96
Expand file tree
/
Copy pathnitro_pod_utils.rb
More file actions
27 lines (24 loc) · 1.21 KB
/
Copy pathnitro_pod_utils.rb
File metadata and controls
27 lines (24 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
require "json"
# Gets the path of the react-native/package.json file.
def get_react_native_package_path()
pod_root = Pod::Config.instance.installation_root.to_s
return `cd "#{pod_root}" && node --print "require.resolve('react-native/package.json')"`.strip!
end
# Finds out whether react-native is available, or not.
# This works by checking if the react-native node package can be resolved.
def has_react_native()
react_native_package_path = get_react_native_package_path()
return File.exist?(react_native_package_path)
end
# Gets the minor react-native version (e.g 76 for 0.76.4)
def get_react_native_version()
react_native_package_path = get_react_native_package_path()
if !File.exist?(react_native_package_path)
raise "[NitroModules] Couldn't find react-native path! File '#{react_native_package_path}' doesn't exist!"
end
react_native_package = JSON.parse(File.read(react_native_package_path))
react_native_version = react_native_package['version']
react_native_minor_version = react_native_version.split('.')[1].to_i
Pod::UI.puts "[NitroModules] Found react-native #{react_native_version} (#{react_native_minor_version}) in #{File.dirname(react_native_package_path)}!"
return react_native_minor_version
end