roku_builder 3.3.3 → 3.3.4
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 +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +1158 -0
- data/.travis.yml +3 -0
- data/Gemfile.lock +19 -14
- data/README.md +5 -0
- data/bin/roku +32 -37
- data/config.json.example +2 -2
- data/lib/roku_builder/config_manager.rb +83 -118
- data/lib/roku_builder/config_parser.rb +192 -0
- data/lib/roku_builder/config_validator.rb +125 -0
- data/lib/roku_builder/controller.rb +97 -484
- data/lib/roku_builder/controller_commands.rb +112 -0
- data/lib/roku_builder/error_handler.rb +116 -0
- data/lib/roku_builder/inspector.rb +5 -18
- data/lib/roku_builder/keyer.rb +3 -11
- data/lib/roku_builder/linker.rb +3 -15
- data/lib/roku_builder/loader.rb +52 -89
- data/lib/roku_builder/manifest_manager.rb +2 -3
- data/lib/roku_builder/monitor.rb +15 -12
- data/lib/roku_builder/navigator.rb +2 -10
- data/lib/roku_builder/packager.rb +1 -7
- data/lib/roku_builder/tester.rb +1 -0
- data/lib/roku_builder/util.rb +39 -0
- data/lib/roku_builder/version.rb +1 -1
- data/lib/roku_builder.rb +96 -1
- data/roku_builder.gemspec +5 -4
- data/tests/roku_builder/config_manager_test.rb +80 -241
- data/tests/roku_builder/{controller_config_test.rb → config_parser_test.rb} +5 -5
- data/tests/roku_builder/config_validator_test.rb +158 -0
- data/tests/roku_builder/controller_commands_test.rb +304 -0
- data/tests/roku_builder/controller_test.rb +61 -620
- data/tests/roku_builder/error_handler_test.rb +76 -0
- data/tests/roku_builder/inspector_test.rb +3 -0
- data/tests/roku_builder/keyer_test.rb +3 -2
- data/tests/roku_builder/linker_test.rb +2 -1
- data/tests/roku_builder/loader_test.rb +2 -0
- data/tests/roku_builder/manifest_manager_test.rb +3 -6
- data/tests/roku_builder/monitor_test.rb +5 -13
- data/tests/roku_builder/navigator_test.rb +2 -0
- data/tests/roku_builder/test_helper.rb +38 -0
- metadata +34 -11
|
@@ -3,101 +3,11 @@ module RokuBuilder
|
|
|
3
3
|
# Controls all interaction with other classes
|
|
4
4
|
class Controller
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
### Validation Codes ###
|
|
9
|
-
|
|
10
|
-
# Valid Options
|
|
11
|
-
VALID = 0
|
|
12
|
-
|
|
13
|
-
# Too many commands given
|
|
14
|
-
EXTRA_COMMANDS = 1
|
|
15
|
-
|
|
16
|
-
# No commands given
|
|
17
|
-
NO_COMMANDS = 2
|
|
18
|
-
|
|
19
|
-
# Too many source options given
|
|
20
|
-
EXTRA_SOURCES = 3
|
|
21
|
-
|
|
22
|
-
# No source options given
|
|
23
|
-
NO_SOURCE = 4
|
|
24
|
-
|
|
25
|
-
# Incorrect use of current option
|
|
26
|
-
BAD_CURRENT = 5
|
|
27
|
-
|
|
28
|
-
# No deeplink options supplied for deeplink
|
|
29
|
-
BAD_DEEPLINK = 6
|
|
30
|
-
|
|
31
|
-
# Incorrect use of the in option
|
|
32
|
-
BAD_IN_FILE = 7
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
### Device Codes ###
|
|
37
|
-
|
|
38
|
-
# The default device is offline switched to a secondary device
|
|
39
|
-
CHANGED_DEVICE = -1
|
|
40
|
-
|
|
41
|
-
# Device is online
|
|
42
|
-
GOOD_DEVICE = 0
|
|
43
|
-
|
|
44
|
-
# User defined device was not online
|
|
45
|
-
BAD_DEVICE = 1
|
|
46
|
-
|
|
47
|
-
# No configured devices were online
|
|
48
|
-
NO_DEVICES = 2
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
### Run Codes ###
|
|
53
|
-
|
|
54
|
-
# Config has deplicated options
|
|
55
|
-
DEPRICATED_CONFIG = -1
|
|
56
|
-
|
|
57
|
-
# Valid config
|
|
58
|
-
SUCCESS = 0
|
|
59
|
-
|
|
60
|
-
# Tring to overwrite existing config file
|
|
61
|
-
CONFIG_OVERWRITE = 1
|
|
62
|
-
|
|
63
|
-
# Missing config file
|
|
64
|
-
MISSING_CONFIG = 2
|
|
65
|
-
|
|
66
|
-
# Invalid config file
|
|
67
|
-
INVALID_CONFIG = 3
|
|
68
|
-
|
|
69
|
-
# Missing manifest file
|
|
70
|
-
MISSING_MANIFEST = 4
|
|
71
|
-
|
|
72
|
-
# Unknow device given
|
|
73
|
-
UNKNOWN_DEVICE = 5
|
|
74
|
-
|
|
75
|
-
# Unknown project given
|
|
76
|
-
UNKNOWN_PROJECT = 6
|
|
77
|
-
|
|
78
|
-
# Unknown stage given
|
|
79
|
-
UNKNOWN_STAGE = 7
|
|
80
|
-
|
|
81
|
-
# Failed to sideload app
|
|
82
|
-
FAILED_SIDELOAD = 8
|
|
83
|
-
|
|
84
|
-
# Failed to sign app
|
|
85
|
-
FAILED_SIGNING = 9
|
|
86
|
-
|
|
87
|
-
# Failed to deeplink to app
|
|
88
|
-
FAILED_DEEPLINKING = 10
|
|
89
|
-
|
|
90
|
-
# Failed to send navigation command
|
|
91
|
-
FAILED_NAVIGATING = 11
|
|
92
|
-
|
|
93
|
-
# Failed to capture screen
|
|
94
|
-
FAILED_SCREENCAPTURE = 12
|
|
95
|
-
|
|
96
6
|
# Run the builder
|
|
97
7
|
# @param options [Hash] The options hash
|
|
98
8
|
def self.run(options:)
|
|
99
9
|
logger = Logger.new(STDOUT)
|
|
100
|
-
logger.formatter = proc {|severity, datetime,
|
|
10
|
+
logger.formatter = proc {|severity, datetime, _progname, msg|
|
|
101
11
|
"[%s #%s] %5s: %s\n\r" % [datetime.strftime("%Y-%m-%d %H:%M:%S.%4N"), $$, severity, msg]
|
|
102
12
|
}
|
|
103
13
|
if options[:debug]
|
|
@@ -108,142 +18,111 @@ module RokuBuilder
|
|
|
108
18
|
logger.level = Logger::WARN
|
|
109
19
|
end
|
|
110
20
|
|
|
21
|
+
# Validate Options
|
|
22
|
+
options_code = validate_options(options: options)
|
|
23
|
+
ErrorHandler.handle_options_codes(options_code: options_code, logger: logger)
|
|
111
24
|
|
|
112
|
-
|
|
25
|
+
# Configure Gem
|
|
26
|
+
configure_code = configure(options: options, logger: logger)
|
|
27
|
+
ErrorHandler.handle_configure_codes(configure_code: configure_code, logger: logger)
|
|
113
28
|
|
|
114
|
-
|
|
29
|
+
# Load Config
|
|
30
|
+
load_code, config, configs = ConfigManager.load_config(options: options, logger: logger)
|
|
31
|
+
ErrorHandler.handle_load_codes(options: options, load_code: load_code, logger: logger)
|
|
115
32
|
|
|
116
|
-
|
|
33
|
+
# Check devices
|
|
34
|
+
device_code, configs = check_devices(options: options, config: config, configs: configs, logger: logger)
|
|
35
|
+
ErrorHandler.handle_device_codes(device_code: device_code, logger: logger)
|
|
117
36
|
|
|
118
|
-
|
|
37
|
+
# Run Commands
|
|
38
|
+
command_code = execute_commands(options: options, config: config, configs: configs, logger: logger)
|
|
39
|
+
ErrorHandler.handle_command_codes(command_code: command_code, logger: logger)
|
|
119
40
|
end
|
|
120
41
|
|
|
121
|
-
|
|
42
|
+
# Validates the user options
|
|
43
|
+
# @param options [Hash] The options hash
|
|
44
|
+
# @return [Integer] Status code for command validation
|
|
45
|
+
def self.validate_options(options:)
|
|
46
|
+
command_result = validate_command_options(options: options)
|
|
47
|
+
return command_result unless command_result == VALID
|
|
48
|
+
source_result = validate_source_options(options: options)
|
|
49
|
+
return source_result unless source_result == VALID
|
|
50
|
+
combination_result = validate_option_combinations(options: options)
|
|
51
|
+
return combination_result
|
|
52
|
+
end
|
|
53
|
+
private_class_method :validate_options
|
|
122
54
|
|
|
123
|
-
# Validates
|
|
55
|
+
# Validates use of command options
|
|
124
56
|
# @param options [Hash] The options hash
|
|
125
57
|
# @return [Integer] Status code for command validation
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
return
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
58
|
+
def self.validate_command_options(options:)
|
|
59
|
+
all_commands = options.keys & commands
|
|
60
|
+
return EXTRA_COMMANDS if all_commands.count > 1
|
|
61
|
+
return NO_COMMANDS if all_commands.count < 1
|
|
62
|
+
VALID
|
|
63
|
+
end
|
|
64
|
+
private_class_method :validate_command_options
|
|
65
|
+
|
|
66
|
+
# Validates use of source options
|
|
67
|
+
# @param options [Hash] The options hash
|
|
68
|
+
# @return [Integer] Status code for command validation
|
|
69
|
+
def self.validate_source_options(options:)
|
|
70
|
+
all_sources = options.keys & sources
|
|
71
|
+
return EXTRA_SOURCES if all_sources.count > 1
|
|
72
|
+
if (options.keys & source_commands).count == 1
|
|
73
|
+
return NO_SOURCE unless all_sources.count == 1
|
|
135
74
|
end
|
|
136
|
-
|
|
75
|
+
VALID
|
|
76
|
+
end
|
|
77
|
+
private_class_method :validate_source_options
|
|
78
|
+
|
|
79
|
+
# Validates proper option combinations
|
|
80
|
+
# @param options [Hash] The options hash
|
|
81
|
+
# @return [Integer] Status code for command validation
|
|
82
|
+
def self.validate_option_combinations(options:)
|
|
83
|
+
all_sources = options.keys & sources
|
|
84
|
+
if all_sources.include?(:current)
|
|
137
85
|
return BAD_CURRENT unless options[:build] or options[:sideload]
|
|
138
86
|
end
|
|
139
87
|
if options[:in]
|
|
140
88
|
return BAD_IN_FILE unless options[:sideload]
|
|
141
89
|
end
|
|
142
90
|
if options[:deeplink]
|
|
143
|
-
return BAD_DEEPLINK if
|
|
91
|
+
return BAD_DEEPLINK if options[:deeplink_options].to_s.empty?
|
|
144
92
|
end
|
|
145
|
-
|
|
93
|
+
VALID
|
|
146
94
|
end
|
|
95
|
+
private_class_method :validate_option_combinations
|
|
147
96
|
|
|
148
97
|
# Run commands
|
|
149
98
|
# @param options [Hash] The options hash
|
|
150
99
|
# @return [Integer] Return code for options handeling
|
|
151
100
|
# @param logger [Logger] system logger
|
|
152
|
-
def self.
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
when :package
|
|
173
|
-
### Package App ###
|
|
174
|
-
keyer = Keyer.new(**configs[:device_config])
|
|
175
|
-
loader = Loader.new(**configs[:device_config])
|
|
176
|
-
packager = Packager.new(**configs[:device_config])
|
|
177
|
-
inspector = Inspector.new(**configs[:device_config])
|
|
178
|
-
logger.warn "Packaging working directory" if options[:working]
|
|
179
|
-
# Sideload #
|
|
180
|
-
build_version = loader.sideload(**configs[:sideload_config])
|
|
181
|
-
return FAILED_SIGNING unless build_version
|
|
182
|
-
# Key #
|
|
183
|
-
success = keyer.rekey(**configs[:key])
|
|
184
|
-
logger.info "Key did not change" unless success
|
|
185
|
-
# Package #
|
|
186
|
-
options[:build_version] = build_version
|
|
187
|
-
configs = self.update_configs(configs: configs, options: options)
|
|
188
|
-
success = packager.package(**configs[:package_config])
|
|
189
|
-
logger.info "Signing Successful: #{configs[:package_config][:out_file]}" if success
|
|
190
|
-
return FAILED_SIGNING unless success
|
|
191
|
-
# Inspect #
|
|
192
|
-
if options[:inspect]
|
|
193
|
-
info = inspector.inspect(configs[:inspect_config])
|
|
194
|
-
logger.unknown "App Name: #{info[:app_name]}"
|
|
195
|
-
logger.unknown "Dev ID: #{info[:dev_id]}"
|
|
196
|
-
logger.unknown "Creation Date: #{info[:creation_date]}"
|
|
197
|
-
logger.unknown "dev.zip: #{info[:dev_zip]}"
|
|
101
|
+
def self.execute_commands(options:, config:, configs:, logger:)
|
|
102
|
+
command = (commands & options.keys).first
|
|
103
|
+
if ControllerCommands.simple_commands.keys.include?(command)
|
|
104
|
+
params = ControllerCommands.simple_commands[command]
|
|
105
|
+
params[:configs] = configs
|
|
106
|
+
ControllerCommands.simple_command(**params)
|
|
107
|
+
else
|
|
108
|
+
params = ControllerCommands.method(command.to_s).parameters.collect{|a|a[1]}
|
|
109
|
+
args = {}
|
|
110
|
+
params.each do |key|
|
|
111
|
+
case key
|
|
112
|
+
when :options
|
|
113
|
+
args[:options] = options
|
|
114
|
+
when :config
|
|
115
|
+
args[:config] = config
|
|
116
|
+
when :configs
|
|
117
|
+
args[:configs] = configs
|
|
118
|
+
when :logger
|
|
119
|
+
args[:logger] = logger
|
|
120
|
+
end
|
|
198
121
|
end
|
|
199
|
-
|
|
200
|
-
### Build ###
|
|
201
|
-
loader = Loader.new(**configs[:device_config])
|
|
202
|
-
build_version = ManifestManager.build_version(**configs[:manifest_config])
|
|
203
|
-
options[:build_version] = build_version
|
|
204
|
-
configs = self.update_configs(configs: configs, options: options)
|
|
205
|
-
outfile = loader.build(**configs[:build_config])
|
|
206
|
-
logger.info "Build: #{outfile}"
|
|
207
|
-
when :update
|
|
208
|
-
### Update ###
|
|
209
|
-
old_version = ManifestManager.build_version(**configs[:manifest_config])
|
|
210
|
-
new_version = ManifestManager.update_build(**configs[:manifest_config])
|
|
211
|
-
logger.info "Update build version from:\n#{old_version}\nto:\n#{new_version}"
|
|
212
|
-
when :deeplink
|
|
213
|
-
### Deeplink ###
|
|
214
|
-
linker = Linker.new(**configs[:device_config])
|
|
215
|
-
success = linker.link(**configs[:deeplink_config])
|
|
216
|
-
return FAILED_DEEPLINKING unless success
|
|
217
|
-
when :delete
|
|
218
|
-
loader = Loader.new(**configs[:device_config])
|
|
219
|
-
loader.unload()
|
|
220
|
-
when :monitor
|
|
221
|
-
monitor = Monitor.new(**configs[:device_config])
|
|
222
|
-
monitor.monitor(**configs[:monitor_config])
|
|
223
|
-
when :navigate
|
|
224
|
-
navigator = Navigator.new(**configs[:device_config])
|
|
225
|
-
success = navigator.nav(**configs[:navigate_config])
|
|
226
|
-
return FAILED_NAVIGATING unless success
|
|
227
|
-
when :screen
|
|
228
|
-
navigator = Navigator.new(**configs[:device_config])
|
|
229
|
-
success = navigator.screen(**configs[:screen_config])
|
|
230
|
-
return FAILED_NAVIGATING unless success
|
|
231
|
-
when :screens
|
|
232
|
-
navigator = Navigator.new(**configs[:device_config])
|
|
233
|
-
navigator.screens
|
|
234
|
-
when :text
|
|
235
|
-
navigator = Navigator.new(**configs[:device_config])
|
|
236
|
-
navigator.type(**configs[:text_config])
|
|
237
|
-
when :test
|
|
238
|
-
tester = Tester.new(**configs[:device_config])
|
|
239
|
-
tester.run_tests(**configs[:test_config])
|
|
240
|
-
when :screencapture
|
|
241
|
-
inspector = Inspector.new(**configs[:device_config])
|
|
242
|
-
success = inspector.screencapture(**configs[:screencapture_config])
|
|
243
|
-
return FAILED_SCREENCAPTURE unless success
|
|
122
|
+
ControllerCommands.send(command, args)
|
|
244
123
|
end
|
|
245
|
-
return SUCCESS
|
|
246
124
|
end
|
|
125
|
+
private_class_method :execute_commands
|
|
247
126
|
|
|
248
127
|
# Ensure that the selected device is accessable
|
|
249
128
|
# @param options [Hash] The options hash
|
|
@@ -265,6 +144,7 @@ module RokuBuilder
|
|
|
265
144
|
}
|
|
266
145
|
return [NO_DEVICES, nil]
|
|
267
146
|
end
|
|
147
|
+
private_class_method :check_devices
|
|
268
148
|
|
|
269
149
|
# List of command options
|
|
270
150
|
# @return [Array<Symbol>] List of command symbols that can be used in the options hash
|
|
@@ -273,314 +153,47 @@ module RokuBuilder
|
|
|
273
153
|
:navigate, :text, :build, :monitor, :update, :screencapture, :screen,
|
|
274
154
|
:screens]
|
|
275
155
|
end
|
|
156
|
+
private_class_method :commands
|
|
276
157
|
|
|
277
158
|
# List of source options
|
|
278
159
|
# @return [Array<Symbol>] List of source symbols that can be used in the options hash
|
|
279
160
|
def self.sources
|
|
280
161
|
[:ref, :set_stage, :working, :current]
|
|
281
162
|
end
|
|
163
|
+
private_class_method :sources
|
|
282
164
|
|
|
283
165
|
# List of commands requiring a source option
|
|
284
166
|
# @return [Array<Symbol>] List of command symbols that require a source in the options hash
|
|
285
167
|
def self.source_commands
|
|
286
168
|
[:sideload, :package, :test, :build]
|
|
287
169
|
end
|
|
170
|
+
private_class_method :source_commands
|
|
288
171
|
|
|
289
|
-
# Handle error codes
|
|
290
|
-
# @param options_code [Integer] the error code returned by validate_options
|
|
291
|
-
# @param handle_code [Integer] the error code returned by handle_options
|
|
292
|
-
# @param logger [Logger] system logger
|
|
293
|
-
def self.handle_error_codes(options:, options_code: nil, device_code: nil, handle_code: nil, logger:)
|
|
294
|
-
if options_code
|
|
295
|
-
case options_code
|
|
296
|
-
when EXTRA_COMMANDS
|
|
297
|
-
logger.fatal "Only one command is allowed"
|
|
298
|
-
abort
|
|
299
|
-
when NO_COMMANDS
|
|
300
|
-
logger.fatal "At least one command is required"
|
|
301
|
-
abort
|
|
302
|
-
when EXTRA_SOURCES
|
|
303
|
-
logger.fatal "Only use one of --ref, --working, --current or --stage"
|
|
304
|
-
abort
|
|
305
|
-
when NO_SOURCE
|
|
306
|
-
logger.fatal "Must use at least one of --ref, --working, --current or --stage"
|
|
307
|
-
abort
|
|
308
|
-
when BAD_CURRENT
|
|
309
|
-
logger.fatal "Can only sideload or build 'current' directory"
|
|
310
|
-
abort
|
|
311
|
-
when BAD_DEEPLINK
|
|
312
|
-
logger.fatal "Must supply deeplinking options when deeplinking"
|
|
313
|
-
abort
|
|
314
|
-
when BAD_IN_FILE
|
|
315
|
-
logger.fatal "Can only supply in file for building"
|
|
316
|
-
abort
|
|
317
|
-
end
|
|
318
|
-
elsif device_code
|
|
319
|
-
case device_code
|
|
320
|
-
when CHANGED_DEVICE
|
|
321
|
-
logger.info "The default device was not online so a secondary device is being used"
|
|
322
|
-
when BAD_DEVICE
|
|
323
|
-
logger.fatal "The selected device was not online"
|
|
324
|
-
abort
|
|
325
|
-
when NO_DEVICES
|
|
326
|
-
logger.fatal "No configured devices were found"
|
|
327
|
-
abort
|
|
328
|
-
end
|
|
329
|
-
elsif handle_code
|
|
330
|
-
case handle_code
|
|
331
|
-
when DEPRICATED_CONFIG
|
|
332
|
-
logger.warn 'Depricated config. See Above'
|
|
333
|
-
when CONFIG_OVERWRITE
|
|
334
|
-
logger.fatal 'Config already exists. To create default please remove config first.'
|
|
335
|
-
abort
|
|
336
|
-
when MISSING_CONFIG
|
|
337
|
-
logger.fatal "Missing config file: #{options[:config]}"
|
|
338
|
-
abort
|
|
339
|
-
when INVALID_CONFIG
|
|
340
|
-
logger.fatal 'Invalid config. See Above'
|
|
341
|
-
abort
|
|
342
|
-
when MISSING_MANIFEST
|
|
343
|
-
logger.fatal 'Manifest file missing'
|
|
344
|
-
abort
|
|
345
|
-
when UNKNOWN_DEVICE
|
|
346
|
-
logger.fatal "Unkown device id"
|
|
347
|
-
abort
|
|
348
|
-
when UNKNOWN_PROJECT
|
|
349
|
-
logger.fatal "Unknown project id"
|
|
350
|
-
abort
|
|
351
|
-
when UNKNOWN_STAGE
|
|
352
|
-
logger.fatal "Unknown stage"
|
|
353
|
-
abort
|
|
354
|
-
when FAILED_SIDELOAD
|
|
355
|
-
logger.fatal "Failed Sideloading App"
|
|
356
|
-
abort
|
|
357
|
-
when FAILED_SIGNING
|
|
358
|
-
logger.fatal "Failed Signing App"
|
|
359
|
-
abort
|
|
360
|
-
when FAILED_DEEPLINKING
|
|
361
|
-
logger.fatal "Failed Deeplinking To App"
|
|
362
|
-
abort
|
|
363
|
-
when FAILED_NAVIGATING
|
|
364
|
-
logger.fatal "Command not sent"
|
|
365
|
-
abort
|
|
366
|
-
when FAILED_SCREENCAPTURE
|
|
367
|
-
logger.fatal "Failed to Capture Screen"
|
|
368
|
-
abort
|
|
369
|
-
end
|
|
370
|
-
end
|
|
371
|
-
end
|
|
372
172
|
|
|
373
173
|
# Configure the gem
|
|
374
174
|
# @param options [Hash] The options hash
|
|
375
175
|
# @return [Integer] Success or failure code
|
|
376
176
|
# @param logger [Logger] system logger
|
|
377
177
|
def self.configure(options:, logger:)
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
else
|
|
385
|
-
### Copy Config File ###
|
|
386
|
-
FileUtils.copy(source_config, target_config)
|
|
387
|
-
end
|
|
388
|
-
if options[:edit_params]
|
|
389
|
-
ConfigManager.edit_config(config: target_config, options: options[:edit_params], device: options[:device], project: options[:project], stage: options[:stage], logger: logger)
|
|
390
|
-
end
|
|
391
|
-
return SUCCESS
|
|
392
|
-
end
|
|
393
|
-
|
|
394
|
-
# Load config file and generate intermeidate configs
|
|
395
|
-
# @param options [Hash] The options hash
|
|
396
|
-
# @param logger [Logger] system logger
|
|
397
|
-
# @return [Integer] Return code
|
|
398
|
-
# @return [Hash] Loaded config
|
|
399
|
-
# @return [Hash] Intermeidate configs
|
|
400
|
-
def self.load_config(options:, logger:)
|
|
401
|
-
config_file = File.expand_path(options[:config])
|
|
402
|
-
return MISSING_CONFIG unless File.exists?(config_file)
|
|
403
|
-
code = SUCCESS
|
|
404
|
-
config = ConfigManager.get_config(config: config_file, logger: logger)
|
|
405
|
-
return INVALID_CONFIG unless config
|
|
406
|
-
configs = {}
|
|
407
|
-
codes = ConfigManager.validate_config(config: config, logger: logger)
|
|
408
|
-
fatal = false
|
|
409
|
-
warning = false
|
|
410
|
-
codes.each {|code|
|
|
411
|
-
if code > 0
|
|
412
|
-
logger.fatal "Invalid Config: "+ ConfigManager.error_codes()[code]
|
|
413
|
-
fatal = true
|
|
414
|
-
elsif code < 0
|
|
415
|
-
logger.warn "Depricated Config: "+ ConfigManager.error_codes()[code]
|
|
416
|
-
warning = true
|
|
417
|
-
elsif code == 0 and options[:validate]
|
|
418
|
-
logger.info "Config Valid"
|
|
419
|
-
end
|
|
420
|
-
}
|
|
421
|
-
return [INVALID_CONFIG, nil, nil] if fatal
|
|
422
|
-
code = DEPRICATED_CONFIG if warning
|
|
423
|
-
|
|
424
|
-
#set device
|
|
425
|
-
unless options[:device]
|
|
426
|
-
options[:device] = config[:devices][:default]
|
|
427
|
-
end
|
|
428
|
-
#set project
|
|
429
|
-
if options[:current] or not options[:project]
|
|
430
|
-
path = self.system(command: "pwd")
|
|
431
|
-
project = nil
|
|
432
|
-
config[:projects].each_pair {|key,value|
|
|
433
|
-
if value.is_a?(Hash)
|
|
434
|
-
repo_path = Pathname.new(value[:directory]).realdirpath.to_s
|
|
435
|
-
if path.start_with?(repo_path)
|
|
436
|
-
project = key
|
|
437
|
-
break
|
|
438
|
-
end
|
|
178
|
+
if options[:configure]
|
|
179
|
+
source_config = File.expand_path(File.join(File.dirname(__FILE__), "..", '..', 'config.json.example'))
|
|
180
|
+
target_config = File.expand_path(options[:config])
|
|
181
|
+
if File.exist?(target_config)
|
|
182
|
+
unless options[:edit_params]
|
|
183
|
+
return CONFIG_OVERWRITE
|
|
439
184
|
end
|
|
440
|
-
}
|
|
441
|
-
if project
|
|
442
|
-
options[:project] = project
|
|
443
185
|
else
|
|
444
|
-
|
|
186
|
+
### Copy Config File ###
|
|
187
|
+
FileUtils.copy(source_config, target_config)
|
|
445
188
|
end
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
options[:out_folder] = nil
|
|
449
|
-
options[:out_file] = nil
|
|
450
|
-
if options[:out]
|
|
451
|
-
if options[:out].end_with?(".zip") or options[:out].end_with?(".pkg") or options[:out].end_with?(".jpg")
|
|
452
|
-
options[:out_folder], options[:out_file] = Pathname.new(options[:out]).split.map{|p| p.to_s}
|
|
453
|
-
else
|
|
454
|
-
options[:out_folder] = options[:out]
|
|
455
|
-
end
|
|
456
|
-
end
|
|
457
|
-
unless options[:out_folder]
|
|
458
|
-
options[:out_folder] = "/tmp"
|
|
459
|
-
end
|
|
460
|
-
|
|
461
|
-
# Create Device Config
|
|
462
|
-
configs[:device_config] = config[:devices][options[:device].to_sym]
|
|
463
|
-
return [UNKNOWN_DEVICE, nil, nil] unless configs[:device_config]
|
|
464
|
-
configs[:device_config][:logger] = logger
|
|
465
|
-
|
|
466
|
-
#Create Project Config
|
|
467
|
-
project_config = {}
|
|
468
|
-
if options[:current]
|
|
469
|
-
pwd = self.system(command: "pwd")
|
|
470
|
-
return [MISSING_MANIFEST, nil, nil] unless File.exist?(File.join(pwd, "manifest"))
|
|
471
|
-
project_config = {
|
|
472
|
-
directory: pwd,
|
|
473
|
-
folders: nil,
|
|
474
|
-
files: nil,
|
|
475
|
-
stages: { production: { branch: nil } }
|
|
476
|
-
}
|
|
477
|
-
else
|
|
478
|
-
project_config = config[:projects][options[:project].to_sym]
|
|
479
|
-
end
|
|
480
|
-
return [UNKNOWN_PROJECT, nil, nil] unless project_config
|
|
481
|
-
configs[:project_config] = project_config
|
|
482
|
-
stage = options[:stage].to_sym
|
|
483
|
-
return [UNKNOWN_STAGE, nil, nil] unless project_config[:stages][stage]
|
|
484
|
-
configs[:stage] = stage
|
|
485
|
-
|
|
486
|
-
root_dir = project_config[:directory]
|
|
487
|
-
branch = project_config[:stages][stage][:branch]
|
|
488
|
-
branch = options[:ref] if options[:ref]
|
|
489
|
-
branch = nil if options[:current]
|
|
490
|
-
branch = nil if options[:working]
|
|
491
|
-
|
|
492
|
-
# Create Sideload Config
|
|
493
|
-
configs[:sideload_config] = {
|
|
494
|
-
root_dir: root_dir,
|
|
495
|
-
branch: branch,
|
|
496
|
-
update_manifest: options[:update_manifest],
|
|
497
|
-
fetch: options[:fetch],
|
|
498
|
-
folders: project_config[:folders],
|
|
499
|
-
files: project_config[:files]
|
|
500
|
-
}
|
|
501
|
-
if options[:package]
|
|
502
|
-
# Create Key Config
|
|
503
|
-
configs[:key] = project_config[:stages][stage][:key]
|
|
504
|
-
# Create Package Config
|
|
505
|
-
configs[:package_config] = {
|
|
506
|
-
password: configs[:key][:password],
|
|
507
|
-
app_name_version: "#{project_config[:app_name]} - #{stage}"
|
|
508
|
-
}
|
|
509
|
-
if options[:out_file]
|
|
510
|
-
configs[:package_config][:out_file] = File.join(options[:out_folder], options[:out_file])
|
|
511
|
-
end
|
|
512
|
-
# Create Inspector Config
|
|
513
|
-
configs[:inspect_config] = {
|
|
514
|
-
pkg: configs[:package_config][:out_file],
|
|
515
|
-
password: configs[:key][:password]
|
|
516
|
-
}
|
|
517
|
-
end if
|
|
518
|
-
# Create Build Config
|
|
519
|
-
configs[:build_config] = {
|
|
520
|
-
root_dir: root_dir,
|
|
521
|
-
branch: branch,
|
|
522
|
-
fetch: options[:fetch],
|
|
523
|
-
folders: project_config[:folders],
|
|
524
|
-
files: project_config[:files]
|
|
525
|
-
}
|
|
526
|
-
# Create Manifest Config
|
|
527
|
-
configs[:manifest_config] = {
|
|
528
|
-
root_dir: project_config[:directory],
|
|
529
|
-
logger: logger
|
|
530
|
-
}
|
|
531
|
-
# Create Deeplink Config
|
|
532
|
-
configs[:deeplink_config] ={
|
|
533
|
-
options: options[:deeplink_options]
|
|
534
|
-
}
|
|
535
|
-
# Create Monitor Config
|
|
536
|
-
if options[:monitor]
|
|
537
|
-
configs[:monitor_config] = {
|
|
538
|
-
type: options[:monitor].to_sym
|
|
539
|
-
}
|
|
540
|
-
end
|
|
541
|
-
# Create Navigate Config
|
|
542
|
-
if options[:navigate]
|
|
543
|
-
configs[:navigate_config] = {
|
|
544
|
-
command: options[:navigate].to_sym
|
|
545
|
-
}
|
|
546
|
-
end
|
|
547
|
-
# Create Text Config
|
|
548
|
-
configs[:text_config] = {
|
|
549
|
-
text: options[:text]
|
|
550
|
-
}
|
|
551
|
-
# Create Test Config
|
|
552
|
-
configs[:test_config] = {
|
|
553
|
-
sideload_config: configs[:sideload_config]
|
|
554
|
-
}
|
|
555
|
-
#Create screencapture config
|
|
556
|
-
configs[:screencapture_config] = {
|
|
557
|
-
out_folder: options[:out_folder],
|
|
558
|
-
out_file: options[:out_file]
|
|
559
|
-
}
|
|
560
|
-
|
|
561
|
-
if options[:screen]
|
|
562
|
-
configs[:screen_config] = {
|
|
563
|
-
type: options[:screen].to_sym
|
|
564
|
-
}
|
|
565
|
-
end
|
|
566
|
-
return [code, config, configs]
|
|
567
|
-
end
|
|
568
|
-
|
|
569
|
-
# Update the intermeidate configs
|
|
570
|
-
# @param configs [Hash] Intermeidate configs hash
|
|
571
|
-
# @param options [Hash] Options hash
|
|
572
|
-
# @return [Hash] New intermeidate configs hash
|
|
573
|
-
def self.update_configs(configs:, options:)
|
|
574
|
-
if options[:build_version]
|
|
575
|
-
configs[:package_config][:app_name_version] = "#{configs[:project_config][:app_name]} - #{configs[:stage]} - #{options[:build_version]}" if configs[:package_config]
|
|
576
|
-
unless options[:outfile]
|
|
577
|
-
configs[:package_config][:out_file] = File.join(options[:out_folder], "#{configs[:project_config][:app_name]}_#{configs[:stage]}_#{options[:build_version]}.pkg") if configs[:package_config]
|
|
578
|
-
configs[:build_config][:outfile] = File.join(options[:out_folder], "#{configs[:project_config][:app_name]}_#{configs[:stage]}_#{options[:build_version]}.zip") if configs[:build_config]
|
|
579
|
-
configs[:inspect_config][:pkg] = configs[:package_config][:out_file] if configs[:inspect_config] and configs[:package_config]
|
|
189
|
+
if options[:edit_params]
|
|
190
|
+
ConfigManager.edit_config(config: target_config, options: options, logger: logger)
|
|
580
191
|
end
|
|
192
|
+
return SUCCESS
|
|
581
193
|
end
|
|
582
|
-
|
|
194
|
+
nil
|
|
583
195
|
end
|
|
196
|
+
private_class_method :configure
|
|
584
197
|
|
|
585
198
|
# Run a system command
|
|
586
199
|
# @param command [String] The command to be run
|