Skip to content

Commit

Permalink
Implement Core plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
greeneca committed Jun 6, 2017
1 parent 06cecd6 commit 5c744bc
Show file tree
Hide file tree
Showing 21 changed files with 258 additions and 227 deletions.
101 changes: 0 additions & 101 deletions bin/roku
Original file line number Diff line number Diff line change
Expand Up @@ -10,112 +10,11 @@ RokuBuilder.run()



# opts.on("-l", "--sideload", "Command: Sideload an app") do
# options[:sideload] = true
# end
#
# opts.on("-p", "--package", "Command: Package an app") do
# options[:package] = true
# end
#
# opts.on("-t", "--test", "Command: Test an app") do
# options[:test] = true
# end
#
# opts.on("-L", "--deeplink", "Depricated: Deeplink now just requires -o or --deeplink-options") do
# options[:deeplink_depricated] = true
# end
#
# opts.on("-o", "--deeplink-options OPTIONS", "Command: Deeplink into app. Define options as keypairs. (eg. a:b, c:d,e:f)") do |o|
# options[:deeplink] = o
# end
#
# opts.on("-d", "--delete", "Command: Delete the currently sideloaded app") do
# options[:delete] = true
# end
#
# opts.on("-N", "--nav CMD", "Command: send the given command to the roku") do |n|
# options[:navigate] = n
# end
#
# opts.on("--navigate", "Command: Run interactive navigator") do
# options[:navigator] = true
# end
#
# opts.on("-S", "--screencapture", "Command: save a screencapture to the output file/folder") do
# options[:screencapture] = true
# end
#
# opts.on("-y", "--type TEXT", "Command: type the given text on the roku device") do |t|
# options[:text] = t
# end
#
# opts.on("-b", "--build", "Command: build a zip to be sideloaded") do
# options[:build] = true
# end
#
# opts.on("-k", "--key", "Command: change device key") do
# options[:key] = true
# end
#
# opts.on("--genkey", "Command: generate a new key") do
# options[:genkey] = true
# end
#
# opts.on("--profile COMMAND", "Command: Run various profiler options") do |c|
# options[:profile] = c
# end
#
# opts.on("--screen SCREEN", "Command: show a screen") do |s|
# options[:screen] = s
# end
#
# opts.on("--screens", "Command: show possible screens") do
# options[:screens] = true
# end
#
# opts.on("-m", "--monitor [TYPE]", "Command: run telnet to monitor roku log") do |m|
# options[:monitor] = m || "main"
# end
#
# opts.on("-u", "--update-manifest", "Command: update the manifest file") do
# options[:update] = true
# end
#
# opts.on("-A", "--app-list", "Command: List currently installed apps") do
# options[:applist] = true
# end
#
# opts.on("-M", "--manifest-update", "Update the manifest file while building or packaging") do
# options[:update_manifest] = true
# end
#
# opts.on("-i", "--inspect", "Print inspection information while packaging") do
# options[:inspect] = true
# end
#
# opts.on("-e", "--edit PARAMS", "Edit config params when configuring. (eg. a:b, c:d,e:f)") do |p|
# options[:edit_params] = p
# end
#
# opts.on("-a", "--app ID", "Send App id for deeplinking") do |a|
# options[:app_id] = a
# end
#
# opts.on("-O", "--out PATH", "Output file/folder. If PATH ends in .pkg/.zip/.jpg, file is assumed, otherwise folder is assumed") do |o|
# options[:out] = o
# end
#
# opts.on("-I", "--in PATH", "Input file for sideloading") do |i|
# options[:in] = i
# end
#
# opts.on("-r", "--regexp REGEXP", "A regular expression used to filter monitor logs") do |r|
# options[:regexp] = r
# end
#
# opts.on("-x", "--exclude", "Apply exclude config to sideload") do
# options[:exclude] = true
# end


3 changes: 3 additions & 0 deletions lib/roku_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ def self.process_plugins
plugin.dependencies.each do |dependency|
raise ImplementationError, "Missing dependency: #{dependency}" unless @@plugins.include?(dependency)
end
plugin.commands.keys.each do |command|
raise ImplementationError, "Missing command method '#{command}' in #{plugin}" unless plugin.instance_methods.include?(command)
end
end
end

Expand Down
33 changes: 0 additions & 33 deletions lib/roku_builder/controller_commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,6 @@ module RokuBuilder
# Commands that the controller uses to interface with the rest of the gem.
class ControllerCommands

# Run Package
# @param options [Hash] user options
# @param config [Conifg] config object
# @return [Integer] Success or Failure Code
def self.package(options:, config:)
loader_config = config.parsed[:device_config].dup
loader_config[:init_params] = config.parsed[:init_params][:loader]
keyer = Keyer.new(**config.parsed[:device_config])
stager = Stager.new(**config.parsed[:stage_config])
loader = Loader.new(**loader_config)
packager = Packager.new(**config.parsed[:device_config])
Logger.instance.warn "Packaging working directory" if options[:working]
if stager.stage
# Sideload #
code, build_version = loader.sideload(**config.parsed[:sideload_config])
return code unless code == SUCCESS
# Key #
_success = keyer.rekey(**config.parsed[:key])
# Package #
options[:build_version] = build_version
config.update
success = packager.package(**config.parsed[:package_config])
Logger.instance.info "Signing Successful: #{config.parsed[:package_config][:out_file]}" if success
return FAILED_SIGNING unless success
# Inspect #
if options[:inspect]
inspect_package(config: config)
end
end
stager.unstage
Logger.instance.info "App Packaged; staged using #{stager.method}"
SUCCESS
end
# Run update
# @param config [Config] config object
# @return [Integer] Success or Failure Code
Expand Down
74 changes: 2 additions & 72 deletions lib/roku_builder/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,83 +54,13 @@ def parse
options = {}
options[:config] = '~/.roku_config.json'
options[:update_manifest] = false
parser = build_parser(options: options)
parser = OptionParser.new
add_plugin_options(parser: parser, options:options)
validate_parser(parser: parser)
parser.parse!
options
end

def build_parser(options:)
OptionParser.new do |opts|
opts.banner = "Usage: roku <command> [options]"
opts.separator "Core Comamnads:"
opts.on("--configure", "Copy base configuration file to the --config location. Default: '~/.roku_config.json'") do
options[:configure] = true
end
opts.on("--validate", "Validate configuration'") do
options[:validate] = true
end
opts.on("--do-stage", "Run the stager. Used for scripting. Always run --do-unstage after") do
options[:dostage] = true
end
opts.on("--do-unstage", "Run the unstager. Used for scripting. Always run --do-script first") do
options[:dounstage] = true
end
opts.separator ""
opts.separator "Config Options:"
opts.on("-e", "--edit PARAMS", "Edit config params when configuring. (eg. a:b, c:d,e:f)") do |p|
options[:edit_params] = p
end
opts.on("--config CONFIG", "Set a custom config file. Default: '~/.roku_config.json'") do |c|
options[:config] = c
end
opts.separator ""
opts.separator "Source Options:"
opts.on("-r", "--ref REF", "Git referance to use for sideloading") do |r|
options[:ref] = r
end
opts.on("-w", "--working", "Use working directory to sideload or test") do
options[:working] = true
end
opts.on("-c", "--current", "Use current directory to sideload or test. Overrides any project config") do
options[:current] = true
end
opts.on("-s", "--stage STAGE", "Set the stage to use. Default: 'production'") do |b|
options[:stage] = b
end
opts.on("-P", "--project ID", "Use a different project") do |p|
options[:project] = p
end
opts.separator ""
opts.separator "Other Options:"
opts.on("-O", "--out PATH", "Output file/folder. If PATH ends in .pkg/.zip/.jpg, file is assumed, otherwise folder is assumed") do |o|
options[:out] = o
end
opts.on("-I", "--in PATH", "Input file for sideloading") do |i|
options[:in] = i
end
opts.on("-D", "--device ID", "Use a different device corresponding to the given ID") do |d|
options[:device] = d
options[:device_given] = true
end
opts.on("-V", "--verbose", "Print Info message") do
options[:verbose] = true
end
opts.on("--debug", "Print Debug messages") do
options[:debug] = true
end
opts.on("-h", "--help", "Show this message") do
puts opts
exit
end
opts.on("-v", "--version", "Show version") do
puts RokuBuilder::VERSION
exit
end
end
end

def add_plugin_options(parser:, options:)
RokuBuilder.plugins.each do |plugin|
plugin.parse_options(parser: parser, options: options)
Expand Down Expand Up @@ -183,7 +113,7 @@ def validate_deprivated
# List of command options
# @return [Array<Symbol>] List of command symbols that can be used in the options hash
def commands
@commands ||= [:configure, :validate, :dostage, :dounstage]
@commands ||= []
end

# List of depricated options
Expand Down
2 changes: 1 addition & 1 deletion lib/roku_builder/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module RokuBuilder
module Plugin

def commands
raise ImplementationError, "commands method not implemented"
raise ImplementationError, "commands method not implemented in #{self}"
#[
# {
# name: :command_name,
Expand Down
117 changes: 117 additions & 0 deletions lib/roku_builder/plugins/core.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# ********** Copyright Viacom, Inc. Apache 2.0 **********

module RokuBuilder

class Core
extend Plugin

def self.commands
{
configure: {},
validate: {},
increment: {source: true},
dostage: {},
dounstage: {}
}
end

def self.parse_options(parser:, options:)
parser.banner = "Usage: roku <command> [options]"
parser.separator "Core Comamnads:"
parser.on("--configure", "Copy base configuration file to the --config location. Default: '~/.roku_config.json'") do
options[:configure] = true
end
parser.on("--validate", "Validate configuration") do
options[:validate] = true
end
parser.on("-u", "--update-manifest", "Increment manifest build version") do
options[:increment] = true
end
parser.on("--do-stage", "Run the stager. Used for scripting. Always run --do-unstage after") do
options[:dostage] = true
end
parser.on("--do-unstage", "Run the unstager. Used for scripting. Always run --do-script first") do
options[:dounstage] = true
end
parser.separator ""
parser.separator "Config Options:"
parser.on("-e", "--edit PARAMS", "Edit config params when configuring. (eg. a:b, c:d,e:f)") do |p|
options[:edit_params] = p
end
parser.on("--config CONFIG", "Set a custom config file. Default: '~/.roku_config.json'") do |c|
options[:config] = c
end
parser.separator ""
parser.separator "Source Options:"
parser.on("-r", "--ref REF", "Git referance to use for sideloading") do |r|
options[:ref] = r
end
parser.on("-w", "--working", "Use working directory to sideload or test") do
options[:working] = true
end
parser.on("-c", "--current", "Use current directory to sideload or test. Overrides any project config") do
options[:current] = true
end
parser.on("-s", "--stage STAGE", "Set the stage to use. Default: 'production'") do |b|
options[:stage] = b
end
parser.on("-P", "--project ID", "Use a different project") do |p|
options[:project] = p
end
parser.separator ""
parser.separator "Other Options:"
parser.on("-O", "--out PATH", "Output file/folder. If PATH ends in .pkg/.zip/.jpg, file is assumed, otherwise folder is assumed") do |o|
options[:out] = o
end
parser.on("-I", "--in PATH", "Input file for sideloading") do |i|
options[:in] = i
end
parser.on("-D", "--device ID", "Use a different device corresponding to the given ID") do |d|
options[:device] = d
options[:device_given] = true
end
parser.on("-V", "--verbose", "Print Info message") do
options[:verbose] = true
end
parser.on("--debug", "Print Debug messages") do
options[:debug] = true
end
parser.on("-h", "--help", "Show this message") do
puts parser
exit
end
parser.on("-v", "--version", "Show version") do
puts RokuBuilder::VERSION
exit
end
end

def initialize(config:)
@config = config
end

def configure(options:)
# Stub command
# Handled in the config class
Logger.instance.unknown "Configured"
end
def validate(options:)
# Stub command
# Handled in the config class
Logger.instance.unknown "Config Validated"
end
def increment(options:)
manifest = Manifest.new(config: @config)
old = manifest.build_version
manifest.increment_build_version
new = manifest.build_version
Logger.instance.info "Update build version from:\n#{old}\nto:\n#{new}"
end
def dostage(options:)
Stager.new(config: @config).stage
end
def dounstage(options:)
Stager.new(config: @config).unstage
end
end
end
3 changes: 3 additions & 0 deletions lib/roku_builder/plugins/inspector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ def self.parse_options(parser:, options:)
parser.on("-S", "--screencapture", "Command: save a screencapture to the output file/folder") do
options[:screencapture] = true
end
parser.on("--password PASSWORD", "Password used for inspect") do |p|
options[:password] = p
end
end

# Inspects the given pkg
Expand Down
Loading

0 comments on commit 5c744bc

Please sign in to comment.