apollo_commons_ruby_cli 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.DS_Store +0 -0
- data/.gitignore +9 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +19 -0
- data/README.md +40 -0
- data/Rakefile +2 -0
- data/apollo_commons_ruby.gemspec +26 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/apollo_commons_ruby/AtroposSubscription.rb +88 -0
- data/lib/apollo_commons_ruby/BackfillSampleData.rb +41 -0
- data/lib/apollo_commons_ruby/DomainEvent.rb +181 -0
- data/lib/apollo_commons_ruby/ExecuteCommand.rb +20 -0
- data/lib/apollo_commons_ruby/FileUtils.rb +136 -0
- data/lib/apollo_commons_ruby/MarioConfigsStability.rb +181 -0
- data/lib/apollo_commons_ruby/MarioEvent.rb +45 -0
- data/lib/apollo_commons_ruby/NetworkUtils.rb +188 -0
- data/lib/apollo_commons_ruby/Operation.rb +5 -0
- data/lib/apollo_commons_ruby/Permission.rb +51 -0
- data/lib/apollo_commons_ruby/RequestDataUtils.rb +28 -0
- data/lib/apollo_commons_ruby/ResolveTemplate.rb +40 -0
- data/lib/apollo_commons_ruby/SecretConfig.rb +65 -0
- data/lib/apollo_commons_ruby/ShopHook.rb +79 -0
- data/lib/apollo_commons_ruby/TemplateDebug.rb +207 -0
- data/lib/apollo_commons_ruby/TemplatePusher.rb +159 -0
- data/lib/apollo_commons_ruby/TemplatesHelper.rb +808 -0
- data/lib/apollo_commons_ruby/TemplatesRakefile.rb +864 -0
- data/lib/apollo_commons_ruby/TenantInfo.rb +26 -0
- data/lib/apollo_commons_ruby/TenantTokenCreator.rb +16 -0
- data/lib/apollo_commons_ruby/VerifyMarioConfig.rb +220 -0
- data/lib/apollo_commons_ruby/ViewGroup.rb +64 -0
- data/lib/apollo_commons_ruby/ViewGroupComponent.rb +73 -0
- data/lib/apollo_commons_ruby/ViewGroupDefinition.rb +68 -0
- data/lib/apollo_commons_ruby/WebhookReporting.rb +13 -0
- data/lib/apollo_commons_ruby/Zebugger.rb +125 -0
- data/lib/apollo_commons_ruby.rb +60 -0
- data/lib/jar/v1_atroposDevTools.jar +0 -0
- data/lib/tasks/add_translations.rake +9 -0
- data/lib/tasks/backfill_sample_data.rake +7 -0
- data/lib/tasks/checkValidJson.rake +17 -0
- data/lib/tasks/delete_domain_event.rake +7 -0
- data/lib/tasks/delete_view_group.rake +7 -0
- data/lib/tasks/delete_view_group_component.rake +21 -0
- data/lib/tasks/delete_view_group_definition.rake +26 -0
- data/lib/tasks/deploy_all_templates.rake +7 -0
- data/lib/tasks/deploy_permissions.rake +6 -0
- data/lib/tasks/deploy_shophooks.rake +6 -0
- data/lib/tasks/display_on_zebugger.rake +19 -0
- data/lib/tasks/get_tenant_token.rake +6 -0
- data/lib/tasks/runTests.rake +27 -0
- data/lib/tasks/template_debug.rake +32 -0
- data/lib/tasks/update_all.rake +36 -0
- data/lib/tasks/update_all_domain_events.rake +24 -0
- data/lib/tasks/update_all_view_group_components.rake +18 -0
- data/lib/tasks/update_domain_event.rake +12 -0
- data/lib/tasks/update_one_template.rake +42 -0
- data/lib/tasks/update_translations.rake +24 -0
- data/lib/tasks/update_view_group_component.rake +9 -0
- data/lib/tasks/update_view_group_definition.rake +7 -0
- data/lib/tasks/update_view_group_for_user_0.rake +36 -0
- data/lib/tasks/validate_mario_configs.rake +10 -0
- data/lib/tasks/verify_mario_config.rake +15 -0
- data/lib/version.rb +3 -0
- metadata +109 -0
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require_relative 'TemplatesHelper'
|
3
|
+
|
4
|
+
class ResolveTemplate
|
5
|
+
|
6
|
+
def resolveEnv(data_template, configuration, tenant_id, project_id)
|
7
|
+
envFilePath = configuration.env_file_path(tenant_id, project_id)
|
8
|
+
if(file_exists?(envFilePath))
|
9
|
+
envData = read_data_from_file_path(envFilePath)
|
10
|
+
envData = JSON.parse(envData)
|
11
|
+
data_template = data_template.force_encoding("UTF-8")
|
12
|
+
envData.each do |key, value|
|
13
|
+
substring_key = "{{" + key + "}}"
|
14
|
+
if data_template.include? substring_key
|
15
|
+
puts "Replacing " + substring_key
|
16
|
+
data_template.gsub! substring_key, value
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
return data_template
|
21
|
+
end
|
22
|
+
|
23
|
+
def resolveLang(data_template, configuration, language)
|
24
|
+
langFilePath = configuration.language_file_path_for_template(language)
|
25
|
+
if(file_exists?(langFilePath))
|
26
|
+
langData = read_res_data_from_file_path(langFilePath)
|
27
|
+
langData = JSON.parse(langData)
|
28
|
+
data_template = data_template.force_encoding("UTF-8")
|
29
|
+
langData.each do |key, value|
|
30
|
+
substring_key = "<<" + key + ">>"
|
31
|
+
if data_template.include? substring_key
|
32
|
+
puts "Replacing " + substring_key
|
33
|
+
data_template.gsub! substring_key, value
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
return data_template
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
class SecretConfig
|
2
|
+
|
3
|
+
attr_reader :authToken
|
4
|
+
attr_reader :userId
|
5
|
+
attr_reader :domainId
|
6
|
+
attr_reader :heraAuthToken
|
7
|
+
attr_reader :templateDirectory
|
8
|
+
|
9
|
+
def initialize(environment)
|
10
|
+
if file_exists?("./.apollo/#{environment}.json")
|
11
|
+
conf_file = File.read(File.expand_path("./.apollo/#{environment}.json"))
|
12
|
+
conf = JSON.parse conf_file
|
13
|
+
|
14
|
+
if (conf["tenantAuthToken"] == nil)
|
15
|
+
puts "Auth configurations are missing"
|
16
|
+
return nil
|
17
|
+
end
|
18
|
+
@authToken = conf["tenantAuthToken"]
|
19
|
+
|
20
|
+
elsif (File.exist? ("/var/jenkins_home/template_config/config.json"))
|
21
|
+
conf_file = File.read(File.expand_path("/var/jenkins_home/template_config/config.json"));
|
22
|
+
conf = JSON.parse conf_file
|
23
|
+
conf = conf[environment.downcase]
|
24
|
+
if (conf["authToken"] == nil || conf["heraAuthToken"] == nil)
|
25
|
+
puts "Security configurations are missing"
|
26
|
+
return nil
|
27
|
+
end
|
28
|
+
@authToken = conf["authToken"]
|
29
|
+
@userId = conf["userId"]
|
30
|
+
@domainId = conf["domainId"]
|
31
|
+
@heraAuthToken = conf["heraAuthToken"]
|
32
|
+
@templateDirectory = conf["templateDirectory"]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class DebugSecretConfig
|
38
|
+
|
39
|
+
attr_reader :authToken
|
40
|
+
attr_reader :userId
|
41
|
+
attr_reader :domainId
|
42
|
+
attr_reader :templateDirectory
|
43
|
+
|
44
|
+
def initialize(environment)
|
45
|
+
if(File.exist? ("./environments/#{environment}/userInfo.json"))
|
46
|
+
conf_file = File.read("./environments/#{environment}/userInfo.json");
|
47
|
+
conf = JSON.parse conf_file
|
48
|
+
@authToken = conf["authToken"]
|
49
|
+
@userId = conf["userId"]
|
50
|
+
@domainId = conf["domainId"]
|
51
|
+
else
|
52
|
+
puts "Please Provide userInfo path in /environments=>#{environment}=>userInfo.json file".red
|
53
|
+
return nil
|
54
|
+
end
|
55
|
+
|
56
|
+
if(File.exist? ("./environments/config.json"))
|
57
|
+
templateDirectory_json = File.read("./environments/config.json")
|
58
|
+
templateDirectory_json = JSON.parse templateDirectory_json
|
59
|
+
@templateDirectory = templateDirectory_json["templateDirectory"]
|
60
|
+
else
|
61
|
+
puts "Please Provide templateDirectory path in environments => config.json file".red
|
62
|
+
return nil
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'json'
|
3
|
+
require 'pp'
|
4
|
+
require_relative './NetworkUtils'
|
5
|
+
require_relative './FileUtils'
|
6
|
+
require_relative './SecretConfig'
|
7
|
+
|
8
|
+
$environmentProperties = nil
|
9
|
+
$secretConfig = nil
|
10
|
+
|
11
|
+
def deploy_shophooks(env)
|
12
|
+
environment = env["environment"]
|
13
|
+
tenantId = env["tenantId"]
|
14
|
+
projectId = env["projectId"]
|
15
|
+
shophookName = env["shophookName"]
|
16
|
+
|
17
|
+
raise_exception_if_string_empty(environment, "environment")
|
18
|
+
raise_exception_if_string_empty(tenantId, "tenantId")
|
19
|
+
raise_exception_if_string_empty(projectId, "projectId")
|
20
|
+
|
21
|
+
load_environment_properties(environment, tenantId, projectId)
|
22
|
+
|
23
|
+
if file_exists?("./.apollo/#{environment}.json")
|
24
|
+
apolloEnvFile = File.read("./.apollo/#{environment}.json")
|
25
|
+
apolloEnv = JSON.parse apolloEnvFile
|
26
|
+
tenantAuthToken = apolloEnv["tenantAuthToken"]
|
27
|
+
|
28
|
+
else
|
29
|
+
heraAuthToken = env["heraAuthToken"]
|
30
|
+
raise_exception_if_string_empty(heraAuthToken, "heraAuthToken")
|
31
|
+
|
32
|
+
puts "getting tenant auth token from apollo app"
|
33
|
+
|
34
|
+
apolloAppUrl = $environmentProperties["apolloAppBaseUrl"] + "/apollo-app/1.0/tenants/#{tenantId}/access-token"
|
35
|
+
|
36
|
+
code, response = make_GET_request(apolloAppUrl, heraAuthToken)
|
37
|
+
|
38
|
+
jsonResponse = JSON.parse(response)
|
39
|
+
tenantAuthToken = jsonResponse["access_token"]
|
40
|
+
end
|
41
|
+
|
42
|
+
if (tenantAuthToken == nil)
|
43
|
+
raise "Failed to get tenantAuthToken from apollo-app"
|
44
|
+
return
|
45
|
+
end
|
46
|
+
|
47
|
+
if shophookName == nil || shophookName.empty?
|
48
|
+
files = Dir["./shophooks/*.json"]
|
49
|
+
files.each do |path|
|
50
|
+
shophookName = File.basename(path, ".json")
|
51
|
+
puts "Deploying shophook " + shophookName
|
52
|
+
deploy_one_shophook(tenantId, projectId, shophookName, tenantAuthToken)
|
53
|
+
end
|
54
|
+
else
|
55
|
+
puts "Deploying shophook " + shophookName
|
56
|
+
deploy_one_shophook(tenantId, projectId, shophookName, tenantAuthToken)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def deploy_one_shophook(tenantId, projectId, shophookName, tenantAuthToken)
|
61
|
+
shophookConfig = read_data_from_file_path("./shophooks/" + shophookName + ".json")
|
62
|
+
raise_exception_if_string_empty(shophookConfig["shopHookId"], "shopHookId")
|
63
|
+
|
64
|
+
shophookConfig = shophookConfig.gsub("\n", ' ').squeeze(' ')
|
65
|
+
|
66
|
+
request_payload = {
|
67
|
+
:config => shophookConfig
|
68
|
+
}
|
69
|
+
|
70
|
+
url = $environmentProperties["apolloConfigBaseUrl"] + "/1.0/tenant/#{tenantId}/scopes/#{projectId}/shophooks/#{shophookName}"
|
71
|
+
|
72
|
+
code, response = make_GET_request(url, tenantAuthToken)
|
73
|
+
|
74
|
+
if (code == "200" || code == "201")
|
75
|
+
return
|
76
|
+
end
|
77
|
+
|
78
|
+
make_POST_request(url, request_payload.to_json, tenantAuthToken)
|
79
|
+
end
|
@@ -0,0 +1,207 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'rubygems'
|
3
|
+
require_relative 'TemplatesHelper'
|
4
|
+
require_relative 'TemplatesRakefile'
|
5
|
+
|
6
|
+
class TemplateGroupDetails
|
7
|
+
attr_reader :body
|
8
|
+
attr_reader :templateGroup
|
9
|
+
attr_reader :scopeId
|
10
|
+
attr_reader :transformer
|
11
|
+
attr_reader :templates
|
12
|
+
|
13
|
+
def initialize(scopeId, templateGroup, transformer)
|
14
|
+
@templateGroup = templateGroup
|
15
|
+
@scopeId = scopeId
|
16
|
+
@transformer = transformer
|
17
|
+
@templates = []
|
18
|
+
@body = JSON.parse "{}"
|
19
|
+
@body["templateGroup"] = templateGroup
|
20
|
+
@body["scopeId"] = scopeId
|
21
|
+
@body["transformer"] = transformer
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class Templates
|
26
|
+
attr_reader :templateGroup
|
27
|
+
attr_reader :scopeId
|
28
|
+
attr_reader :language
|
29
|
+
attr_reader :view
|
30
|
+
attr_reader :templateName
|
31
|
+
attr_reader :presentation
|
32
|
+
attr_reader :dataTemplate
|
33
|
+
attr_reader :attrs
|
34
|
+
attr_reader :body
|
35
|
+
|
36
|
+
def initialize(scopeId, templateGroup, language, view, templateName, presentation, dataTemplate, attrs)
|
37
|
+
@templateGroup = templateGroup
|
38
|
+
@scopeId = scopeId
|
39
|
+
@language = language
|
40
|
+
@view = view
|
41
|
+
@templateName = templateName
|
42
|
+
@presentation = presentation
|
43
|
+
@dataTemplate = dataTemplate
|
44
|
+
@attrs = attrs
|
45
|
+
@body = JSON.parse "{}"
|
46
|
+
@body["templateGroup"] = templateGroup
|
47
|
+
@body["scopeId"] = scopeId
|
48
|
+
@body["language"] = language
|
49
|
+
@body["view"] = view
|
50
|
+
@body["templateName"] = templateName
|
51
|
+
@body["presentation"] = presentation
|
52
|
+
@body["dataTemplate"] = dataTemplate
|
53
|
+
@body["attrs"] = attrs
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def get_template_group_details(task)
|
58
|
+
#Get path
|
59
|
+
template_group_directory = task.template_directory + "/Templates/#{task.template_group}"
|
60
|
+
|
61
|
+
#Form the template group
|
62
|
+
template_group_transformer = read_data_from_file_path(template_group_directory + "/transformer.js")
|
63
|
+
templateGroupDetails = TemplateGroupDetails.new(task.scope_id, task.template_group, template_group_transformer.newline.tabs)
|
64
|
+
|
65
|
+
#Find all the languages
|
66
|
+
languages = directory_list(template_group_directory)
|
67
|
+
resolved_language = "common"
|
68
|
+
languages.each do |language|
|
69
|
+
if (language == task.language)
|
70
|
+
resolved_language = language
|
71
|
+
end
|
72
|
+
end
|
73
|
+
template = create_template_from_files(task.template_directory, task.template_group, task.language, task.view_type, task.template_name,
|
74
|
+
template_group_directory + "/#{resolved_language}/#{task.view_type}/#{task.template_name}", task.tenant_id, task.project_id, task.environment)
|
75
|
+
templateGroupDetails.templates.push(template.body)
|
76
|
+
templateGroupDetails.body["templates"] = templateGroupDetails.templates
|
77
|
+
return templateGroupDetails.body
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
def create_template_from_files(template_directory, template_group, language, view, template_name, template_path, tenant_id, project_id, environment)
|
82
|
+
begin
|
83
|
+
presentation = get_presentation_after_conversion_if_neeeded($environmentProperties["apolloConfigBaseUrl"], environment, template_path)
|
84
|
+
presentation = JSON.parse(presentation).to_json
|
85
|
+
presentation = resolveLang(presentation.to_json, template_directory,language)
|
86
|
+
presentation = JSON.parse(presentation, :quirks_mode => true)
|
87
|
+
#Parsing data template
|
88
|
+
data_template_file_path = file_of_name_in_dir_path(template_path,"dataTemplate")
|
89
|
+
puts "data_template_file_path #{data_template_file_path}"
|
90
|
+
#many templates will not support dataTemplate, hence initializing a default value
|
91
|
+
data_template = "{}"
|
92
|
+
if !(data_template_file_path == nil)
|
93
|
+
#data template file is present
|
94
|
+
begin
|
95
|
+
data_template = read_data_from_file_path(data_template_file_path)
|
96
|
+
rescue Exception => e
|
97
|
+
#Mostly this should not happen, but a sanity check
|
98
|
+
puts "ERROR: data template file not found #{e}"
|
99
|
+
end
|
100
|
+
if data_template_file_path.end_with? ".json" and !data_template.newline.empty?
|
101
|
+
#if data template file is json, then enforce proper json
|
102
|
+
if !JSON.is_valid_json?(data_template)
|
103
|
+
raise "ERROR: data template is not a valid JSON"
|
104
|
+
end
|
105
|
+
data_template = "#{data_template}"
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
client_transformer = ""
|
110
|
+
isClientTransformerFound = true
|
111
|
+
|
112
|
+
begin
|
113
|
+
#Parsing local transformer specific to individual template
|
114
|
+
specific_local_transformer_file_path = file_of_name_in_dir_path(template_path,"localTransformer")
|
115
|
+
puts "specific_local_transformer_file_path #{specific_local_transformer_file_path}"
|
116
|
+
specific_local_transformer = "{}";
|
117
|
+
if !(specific_local_transformer_file_path == nil)
|
118
|
+
begin
|
119
|
+
specific_local_transformer = get_client_transformer_without_require(specific_local_transformer_file_path)
|
120
|
+
rescue Exception => e
|
121
|
+
puts "ERROR: specific local transformer file not found #{e}"
|
122
|
+
end
|
123
|
+
puts "specific_local_transformer #{specific_local_transformer}"
|
124
|
+
client_transformer = specific_local_transformer
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
#Parsing attrs json
|
129
|
+
attrs_json_file_path = file_of_name_in_dir_path(template_path, "attrs")
|
130
|
+
puts "attrs_json_file_path #{attrs_json_file_path}"
|
131
|
+
#many templates will not have attrs json, hence initializing a default value
|
132
|
+
attrs_json = "{}"
|
133
|
+
if !(attrs_json_file_path == nil)
|
134
|
+
#attrs file is present
|
135
|
+
begin
|
136
|
+
attrs_json = read_data_from_file_path(attrs_json_file_path)
|
137
|
+
rescue Exception => e
|
138
|
+
#Mostly this should not happen, but a sanity check
|
139
|
+
puts "ERROR: attrs file not found #{e}"
|
140
|
+
end
|
141
|
+
if attrs_json_file_path.end_with? ".json" and !attrs_json.newline.empty?
|
142
|
+
#if attrs file is json, then enforce proper json
|
143
|
+
if !JSON.is_valid_json?(attrs_json)
|
144
|
+
raise "ERROR: attrs is not a valid JSON"
|
145
|
+
end
|
146
|
+
attrs_json = "#{attrs_json}"
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
if isClientTransformerFound
|
151
|
+
client_transformer = client_transformer.newline.tabs
|
152
|
+
if client_transformer.scan(/^\s*<%.*%>\s*$/).length == 0
|
153
|
+
client_transformer = "<% #{client_transformer} %>"
|
154
|
+
end
|
155
|
+
if JSON.is_valid_json?(data_template)
|
156
|
+
data_template_hash_new = Hash.new
|
157
|
+
data_template_hash_new["__transformer"] = client_transformer
|
158
|
+
data_template_hash = JSON.parse(data_template)
|
159
|
+
data_template_hash_new.merge!(data_template_hash)
|
160
|
+
data_template = data_template_hash_new.to_json
|
161
|
+
else
|
162
|
+
data_template = "#{client_transformer}#{data_template}"
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
data_template = resolveEnv(data_template, template_directory, environment, tenant_id, project_id)
|
167
|
+
data_template = resolveLang(data_template, template_directory, language)
|
168
|
+
data_template = modify_data_template_if_its_mario_template(data_template)
|
169
|
+
attrs_json = modify_data_template_if_its_mario_template(attrs_json)
|
170
|
+
return Templates.new(project_id, template_group, language, view, template_name, presentation, data_template, attrs_json)
|
171
|
+
rescue Exception => e
|
172
|
+
puts "ERROR: Template loading from #{template_group} failed with error: #{e}"
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
def resolveEnv(data_template, template_directory, environment, tenantId, project_id)
|
177
|
+
if environment == 'PreProd'
|
178
|
+
environment = 'Preprod'
|
179
|
+
end
|
180
|
+
envFilePath = template_directory + "/environments/#{environment}/env_#{tenantId}_#{project_id}.json"
|
181
|
+
envData = read_data_from_file_path(envFilePath)
|
182
|
+
envData = JSON.parse(envData)
|
183
|
+
data_template = data_template.force_encoding("UTF-8")
|
184
|
+
envData.each do |key, value|
|
185
|
+
substring_key = "{{" + key + "}}"
|
186
|
+
if data_template.include? substring_key
|
187
|
+
puts "Replacing " + substring_key
|
188
|
+
data_template.gsub! substring_key, value
|
189
|
+
end
|
190
|
+
end
|
191
|
+
return data_template
|
192
|
+
end
|
193
|
+
|
194
|
+
def resolveLang(data_template, template_directory, language)
|
195
|
+
langFilePath = template_directory + "/Resources/#{language}.json"
|
196
|
+
langData = read_res_data_from_file_path(langFilePath)
|
197
|
+
langData = JSON.parse(langData)
|
198
|
+
data_template = data_template.force_encoding("UTF-8")
|
199
|
+
langData.each do |key, value|
|
200
|
+
substring_key = "<<" + key + ">>"
|
201
|
+
if data_template.include? substring_key
|
202
|
+
puts "Replacing " + substring_key
|
203
|
+
data_template.gsub! substring_key, value
|
204
|
+
end
|
205
|
+
end
|
206
|
+
return data_template
|
207
|
+
end
|
@@ -0,0 +1,159 @@
|
|
1
|
+
require 'set'
|
2
|
+
require 'open3'
|
3
|
+
require_relative 'TemplatesHelper'
|
4
|
+
|
5
|
+
$zebugger_ios_bundle_id = "in.zeta.zebugger-ios"
|
6
|
+
$old_zebugger_ios_bundle_id = "in.zeta.apollo.zebugger-ios"
|
7
|
+
|
8
|
+
def push_templates_to_device(configuration, environment, template_group, template_path, dependent_template_ids, language, view_type, platform)
|
9
|
+
templates_set_including_root = Set.new
|
10
|
+
templates_set_including_root.add(template_group)
|
11
|
+
templates_set_including_root.merge dependent_template_ids
|
12
|
+
print_separator_line()
|
13
|
+
puts "Found " + templates_set_including_root.size().to_s + " file(s) in total to be pushed to device"
|
14
|
+
print_separator_line()
|
15
|
+
|
16
|
+
is_real_device_connected, is_simulator_connected = check_for_device_connection(platform)
|
17
|
+
|
18
|
+
adb_push_presentation(configuration, environment, template_group, template_path, true, language, view_type, platform, is_real_device_connected, is_simulator_connected)
|
19
|
+
|
20
|
+
dependent_template_ids.each do |item|
|
21
|
+
item = item.tr('"','')
|
22
|
+
dependent_template_path = parse_template_id(configuration, item, language, view_type)
|
23
|
+
if dependent_template_path == nil
|
24
|
+
puts "invalid template id #{item}"
|
25
|
+
next
|
26
|
+
end
|
27
|
+
dependent_template_group = item.split('_')[0]
|
28
|
+
adb_push_presentation(configuration, environment, dependent_template_group, dependent_template_path, false, language, view_type, platform, is_real_device_connected, is_simulator_connected)
|
29
|
+
end
|
30
|
+
|
31
|
+
adb_push_template_data(template_group, language, view_type, platform, is_real_device_connected, is_simulator_connected)
|
32
|
+
end
|
33
|
+
|
34
|
+
#Push only presentation
|
35
|
+
def adb_push_presentation(configuration, environment, template_group, template_path, is_root, language, view_type, platform, is_real_device_connected, is_simulator_connected)
|
36
|
+
# create_zebuggerX_folder()
|
37
|
+
presentation = get_presentation_after_conversion_if_neeeded(configuration.apollo_config_base_url, environment, template_path)
|
38
|
+
presentation = JSON.parse(presentation, :quirks_mode => true)
|
39
|
+
presentation_file_path_to_push = template_path + '/' + 'presentation_file.json'
|
40
|
+
write_data_to_file(presentation_file_path_to_push, presentation)
|
41
|
+
if(platform == "iOS")
|
42
|
+
source_file_path = presentation_file_path_to_push
|
43
|
+
destination_file_path = "/Documents/presentation_#{template_group}_#{language}_#{view_type}.json"
|
44
|
+
adb_push_to_ios(source_file_path, destination_file_path, is_real_device_connected, is_simulator_connected)
|
45
|
+
else
|
46
|
+
adb_push_to_android(presentation_file_path_to_push, '/storage/emulated/0/Android/media/in.zeta.android.apollo.zebugger/files/zebuggerX/' + (is_root ? 'root_presentation' : ('presentation+' + template_group)) + '.json')
|
47
|
+
|
48
|
+
adb_push_to_android(presentation_file_path_to_push, '/storage/emulated/0/Download/zebuggerX/' + (is_root ? 'root_presentation' : ('presentation+' + template_group)) + '.json')
|
49
|
+
end
|
50
|
+
File.delete(presentation_file_path_to_push) if File.exist?(presentation_file_path_to_push)
|
51
|
+
end
|
52
|
+
|
53
|
+
def adb_push_template_data(template_group, language, view_type, platform, is_real_device_connected, is_simulator_connected)
|
54
|
+
# create_zebuggerX_folder()
|
55
|
+
template_data_file_path = Dir.pwd + '/scripts/commonData/' + 'generatedTemplatedData.json'
|
56
|
+
template_data_file_path = '"' + template_data_file_path + '"'
|
57
|
+
|
58
|
+
if(platform == "iOS")
|
59
|
+
source_file_path = template_data_file_path
|
60
|
+
destination_file_path = "/Documents/dataTemplate_#{template_group}_#{language}_#{view_type}.json"
|
61
|
+
adb_push_to_ios(source_file_path, destination_file_path, is_real_device_connected, is_simulator_connected)
|
62
|
+
else
|
63
|
+
adb_push_to_android(template_data_file_path, '/storage/emulated/0/Android/media/in.zeta.android.apollo.zebugger/files/zebuggerX/data.json')
|
64
|
+
adb_push_to_android(template_data_file_path, '/storage/emulated/0/Download/zebuggerX/data.json')
|
65
|
+
system("adb shell am force-stop in.zeta.android.apollo.youtube")
|
66
|
+
system("adb shell am start -n in.zeta.android.apollo.youtube/zebuggerx.zetlet.MainActivity")
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def adb_push_to_android(source_file_path, destination_file_path)
|
71
|
+
cmd = 'adb push "' + source_file_path + '" "' + destination_file_path + '"'
|
72
|
+
puts "Pushing file #{source_file_path} to Android device"
|
73
|
+
system(cmd)
|
74
|
+
end
|
75
|
+
|
76
|
+
def adb_push_to_ios(source_file_path, destination_file_path, is_real_device_connected, is_simulator_connected)
|
77
|
+
if is_real_device_connected
|
78
|
+
push_to_ios_device($zebugger_ios_bundle_id, source_file_path, destination_file_path)
|
79
|
+
|
80
|
+
#Pushing to old bundle id for backward compatibility
|
81
|
+
push_to_ios_device($old_zebugger_ios_bundle_id, source_file_path, destination_file_path)
|
82
|
+
end
|
83
|
+
|
84
|
+
if is_simulator_connected
|
85
|
+
push_to_ios_simulator($zebugger_ios_bundle_id, source_file_path, destination_file_path)
|
86
|
+
|
87
|
+
#Pushing to old bundle id for backward compatibility
|
88
|
+
push_to_ios_simulator($old_zebugger_ios_bundle_id, source_file_path, destination_file_path)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def push_to_ios_device(bundle_id, source_file_path, destination_file_path)
|
93
|
+
cmd = "ios-deploy --bundle_id #{bundle_id} --upload #{source_file_path} --to #{destination_file_path}"
|
94
|
+
puts "Pushing file #{source_file_path} to connected ios device for bundleId #{bundle_id}"
|
95
|
+
system(cmd)
|
96
|
+
end
|
97
|
+
|
98
|
+
def push_to_ios_simulator(bundle_id, source_file_path, destination_file_path)
|
99
|
+
final_destination_file_path = `xcrun simctl get_app_container booted #{bundle_id} data`
|
100
|
+
final_destination_file_path.to_s.delete!("\n")
|
101
|
+
final_destination_file_path = final_destination_file_path + "#{destination_file_path}"
|
102
|
+
cmd = "cp #{source_file_path} #{final_destination_file_path}"
|
103
|
+
puts "Pushing file #{source_file_path} to newest opened ios simulator for bundleId #{bundle_id}"
|
104
|
+
system(cmd)
|
105
|
+
end
|
106
|
+
|
107
|
+
def create_zebuggerX_folder()
|
108
|
+
adb_cmd = 'adb shell mkdir "/storage/emulated/0/Download/zebuggerX"'
|
109
|
+
system(adb_cmd)
|
110
|
+
end
|
111
|
+
|
112
|
+
def get_dependent_template_ids(string, template_id_set = Set.new)
|
113
|
+
string.scan /templateID\\*\":\s*\\*\"([a-zA-Z0-9\-]*)(_[A-Z][A-Z]*_[A-Z][A-Z]*)?\\*\"/ do |match|
|
114
|
+
template_id_set.add(match[0])
|
115
|
+
end
|
116
|
+
|
117
|
+
return template_id_set
|
118
|
+
end
|
119
|
+
|
120
|
+
def parse_template_id(configuration, template_id, language, view_type)
|
121
|
+
template_id_parts = template_id.split('_')
|
122
|
+
template_group = template_id_parts[0]
|
123
|
+
template_name = "default"
|
124
|
+
template_path = resolve_template_path(configuration, template_group, language, view_type, template_name)
|
125
|
+
return template_path
|
126
|
+
end
|
127
|
+
|
128
|
+
def check_for_device_connection(platform)
|
129
|
+
is_real_device_connected = false
|
130
|
+
is_simulator_connected = false
|
131
|
+
if(platform == "iOS")
|
132
|
+
is_real_device_connected = false
|
133
|
+
stdout, stderr, status = Open3.capture3("ios-deploy --detect --timeout 1")
|
134
|
+
if stdout.include? "Found"
|
135
|
+
is_real_device_connected = true
|
136
|
+
end
|
137
|
+
|
138
|
+
is_app_simulator_connected = check_ios_simulator_availability($zebugger_ios_bundle_id)
|
139
|
+
|
140
|
+
#Checking for old app simulator for backward compatibility
|
141
|
+
is_old_app_simulator_connected = check_ios_simulator_availability($old_zebugger_ios_bundle_id)
|
142
|
+
|
143
|
+
is_simulator_connected = is_app_simulator_connected || is_old_app_simulator_connected
|
144
|
+
end
|
145
|
+
|
146
|
+
return is_real_device_connected, is_simulator_connected
|
147
|
+
end
|
148
|
+
|
149
|
+
def check_ios_simulator_availability(bundle_id)
|
150
|
+
is_simulator_connected = true
|
151
|
+
stdout, stderr, status = Open3.capture3("xcrun simctl get_app_container booted #{bundle_id} data")
|
152
|
+
if stderr.include? "No devices are booted."
|
153
|
+
is_simulator_connected = false
|
154
|
+
end
|
155
|
+
if stderr.include? "No such file or directory"
|
156
|
+
is_simulator_connected = false
|
157
|
+
end
|
158
|
+
return is_simulator_connected
|
159
|
+
end
|