-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathmendix_utils.rb
More file actions
178 lines (141 loc) · 5.04 KB
/
Copy pathmendix_utils.rb
File metadata and controls
178 lines (141 loc) · 5.04 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
require "json"
def generate_pod_dependencies
resolved_pods = {}
capabilities_setup_config = get_capabilities_setup_config
get_project_capabilities.select { |_, value| value == true }.each do |name, _|
capability = capabilities_setup_config[name.to_s]
if capability.nil?
unless get_excluded_capabilities.include?(name.to_s)
Pod::UI.warn "Capability for '#{name.to_s}' is not valid. This file should not be manipulated without guidance."
end
next
end
next unless config = capability["ios"]
if !config["pods"].nil?
resolved_pods.merge! config["pods"]
end
if !config["buildPhases"].nil?
include_script_phases(config["buildPhases"])
end
end
modules = get_react_native_config["dependencies"]
get_unlinked_dependency_config.each do |name, options|
next unless options["ios"] && modules.include?(name) && pods = options["ios"]["pods"]
resolved_pods.merge! pods
end
include_pods(resolved_pods.compact)
end
def generate_mendix_delegate
imports = []
hooks = {
didFinishLaunchingWithOptions: [],
openURL: [],
getJSBundleFile: [],
}
returnHooks = {
boolean_openURLWithOptions: [],
}
capabilities_setup_config = get_capabilities_setup_config
get_project_capabilities.select { |_, value| value == true }.each do |name, _|
capability = capabilities_setup_config[name.to_s]
if capability.nil?
unless get_excluded_capabilities.include?(name.to_s)
Pod::UI.warn "Capability for '#{name.to_s}' is not valid. This file should not be manipulated without guidance."
end
next
end
next if capability["ios"].nil?
Pod::UI.notice "Capability for '#{name.to_s}' was enabled for this project."
next unless capability = capability["ios"]["AppDelegate"]
imports << capability["imports"] if !capability["imports"].nil?
hooks.each do |name, hook|
hook << capability[name.to_s].map { |line| " #{line}" } if !capability[name.to_s].nil?
end
returnHooks.each do |name, hook|
hook << capability[name.to_s].map { |line| " #{line}" } if !capability[name.to_s].nil?
end
end
File.open("MendixAppDelegate.m", "w") do |file|
mendix_app_delegate = mendix_app_delegate_template.sub("{{ imports }}", stringify(imports))
hooks.each { |name, hook| mendix_app_delegate.sub!("{{ #{name.to_s} }}", stringify(hook)) }
returnHooks.each { |name, hook| mendix_app_delegate.sub!("{{ #{name.to_s} }}", stringify(hook).length > 0 ? stringify(hook) : " return YES;") }
file << mendix_app_delegate
end
end
def mendix_app_delegate_template
%(// DO NOT EDIT BY HAND. THIS FILE IS AUTO-GENERATED
#import <Foundation/Foundation.h>
#import <MendixNative.h>
#import "MendixAppDelegate.h"
{{ imports }}
@implementation MendixAppDelegate
+ (void) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
{{ didFinishLaunchingWithOptions }}
}
+ (BOOL) application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
{{ boolean_openURLWithOptions }}
}
+ (void) application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
{{ openURL }}
}
+ (NSURL *) getJSBundleFile {
{{ getJSBundleFile }}
return [ReactNative.instance getJSBundleFile];
}
@end\n)
end
def stringify(array)
array.flatten.uniq.join("\n")
end
def read_json_file_gracefully(path)
file_path = File.join(__dir__, "..", path)
JSON.parse(File.read(file_path)) if File.exist?(file_path)
end
def get_unlinked_dependency_config
read_json_file_gracefully("unlinked-dependency-config.json") || {}
end
def get_capabilities_setup_config
read_json_file_gracefully("capabilities-setup-config.json") || {}
end
def get_project_capabilities
read_json_file_gracefully("capabilities.ios.json") || {}
end
# Source @react-native-community/cli-platform-ios/native_modules
def get_react_native_config
cli_command = "try {console.log(require('@react-native-community/cli').bin);} catch (e) {console.log(require('react-native/cli').bin);}"
cli_result = Pod::Executable.execute_command("node", ["-e", cli_command], true).strip
json = []
IO.popen(["node", cli_result, "config"]) do |data|
while line = data.gets
json << line
end
end
JSON.parse(json.join("\n"))
end
def include_pods(pods = {})
pods.each do |name, pod|
if pod["path"] != nil && !pod["path"].empty?
pod name, :path => "../node_modules/#{pod["path"]}"
elsif pod["version"] != nil && !pod["version"].empty?
pod name, pod["version"]
else
pod name
end
end
end
def include_script_phases(phases)
phases.each do |phase|
if phase["path"]
phase["script"] = File.read(File.expand_path(phase["path"], ".."))
phase.delete("path")
end
if phase["execution_position"]
phase["execution_position"] = phase["execution_position"].to_sym
end
phase = Hash[phase.map { |k, v| [k.to_sym, v] }]
script_phase phase
end
end
def get_excluded_capabilities
["nativeOTA"]
end