forked from software-mansion/react-native-reanimated
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworklets_utils.rb
More file actions
94 lines (79 loc) · 3.9 KB
/
Copy pathworklets_utils.rb
File metadata and controls
94 lines (79 loc) · 3.9 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
module WorkletsUtils
module_function
def try_to_parse_react_native_package_json(react_native_dir)
react_native_package_json_path = File.join(react_native_dir, 'package.json')
if !File.exist?(react_native_package_json_path)
return nil
end
return JSON.parse(File.read(react_native_package_json_path))
end
def find_config()
result = {
:feature_flags_flag => nil,
:fetch_preview_flag => nil,
:is_reanimated_example_app => nil,
:react_native_version => nil,
:react_native_dir => nil,
:react_native_common_dir => nil,
}
react_native_dir = File.dirname(`cd "#{Pod::Config.instance.installation_root.to_s}" && node --print "require.resolve('react-native/package.json')"`)
react_native_json = try_to_parse_react_native_package_json(react_native_dir)
if react_native_json == nil
# user configuration, just in case
node_modules_dir = ENV["REACT_NATIVE_NODE_MODULES_DIR"]
react_native_json = try_to_parse_react_native_package_json(File.join(node_modules_dir, 'react-native'))
end
if react_native_json == nil
raise '[Worklets] 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`.'
end
result[:is_reanimated_example_app] = ENV["IS_REANIMATED_EXAMPLE_APP"] != nil
result[:react_native_version] = react_native_json['version']
result[:react_native_dir] = File.expand_path(react_native_dir)
pods_root = Pod::Config.instance.project_pods_root
react_native_common_dir_absolute = File.join(react_native_dir, 'ReactCommon')
react_native_common_dir_relative = Pathname.new(react_native_common_dir_absolute).relative_path_from(pods_root).to_s
result[:react_native_common_dir] = react_native_common_dir_relative
feature_flags = get_static_feature_flags()
result[:feature_flags_flag] = get_static_feature_flags_flag(feature_flags)
result[:fetch_preview_flag] = get_flag_from_feature_flags(feature_flags, 'FETCH_PREVIEW_ENABLED')
return result
end
def assert_minimal_react_native_version(config)
validate_react_native_version_script = File.expand_path(File.join(__dir__, 'validate-react-native-version.js'))
unless system("node \"#{validate_react_native_version_script}\" #{config[:react_native_version]}")
raise "[Worklets] Your installed version of React Native is not compatible with installed version of Worklets. See the documentation for the list of supported versions: https://docs.swmansion.com/react-native-worklets/docs/guides/compatibility/"
end
end
def get_flag_from_feature_flags(feature_flags, flag_name)
if feature_flags[flag_name] == 'true'
return "-DWORKLETS_#{flag_name}"
else
return ''
end
end
def get_static_feature_flags()
feature_flags = {}
static_feature_flags_path = File.path('./src/featureFlags/staticFlags.json')
if !File.exist?(static_feature_flags_path)
raise "[Worklets] Feature flags file not found at #{static_feature_flags_path}."
end
static_feature_flags_json = JSON.parse(File.read(static_feature_flags_path))
static_feature_flags_json.each do |key, value|
feature_flags[key] = value.to_s
end
package_json_path = File.join(Pod::Config.instance.installation_root.to_s, '..', 'package.json')
if File.exist?(package_json_path)
package_json = JSON.parse(File.read(package_json_path))
if package_json['worklets'] && package_json['worklets']['staticFeatureFlags']
feature_flags_json = package_json['worklets']['staticFeatureFlags']
feature_flags_json.each do |key, value|
feature_flags[key] = value.to_s
end
end
end
return feature_flags
end
def get_static_feature_flags_flag(feature_flags)
return "-DWORKLETS_FEATURE_FLAGS=\"#{feature_flags.map { |key, value| "[#{key}:#{value}]" }.join('')}\""
end
end