Skip to content

Commit

Permalink
Add source_files, depricate files/folders
Browse files Browse the repository at this point in the history
  • Loading branch information
greeneca committed Jan 17, 2019
1 parent 7a9d0fc commit b53a4c4
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 47 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
= 4.13.0 =

- Add combined source_files project config key
- Depricate files and folders keys
- Pass options to post_config_load hook

= 4.12.3 =

- Fix Windows incompatibility

= 4.12.2 =

- Fix Windows incompatibility
Expand Down
3 changes: 1 addition & 2 deletions config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
"project_dir": "<optional parent directory for all projects>",
"<project id>": {
"directory": "<path/to/repo>",
"folders": ["resources","source"],
"files": ["manifest"],
"source_files": ["resources","source", "manifest"],
"excludes": [],
"app_name": "<app name>",
"stage_method": "<git|script>",
Expand Down
2 changes: 1 addition & 1 deletion lib/roku_builder/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def load_config
merge_local_config
expand_repeatable_stages
fix_config_symbol_values
RokuBuilder.process_hook(hook: "post_config_load", params: {config: @config})
RokuBuilder.process_hook(hook: "post_config_load", params: {config: @config, options: @options})
end

def read_config(io)
Expand Down
12 changes: 10 additions & 2 deletions lib/roku_builder/config_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def setup_project_config
@parsed[:project] = @config[:projects][@options[:project].to_sym].dup
raise ParseError, "Unknown Project: #{@options[:project]}" unless @parsed[:project]
set_project_directory
convert_to_source_files
check_for_working
end
end
Expand All @@ -130,8 +131,7 @@ def stub_project_config_for_current
raise ParseError, "Missing Manifest: #{manifest}" unless File.exist?(manifest)
@parsed[:project] = {
directory: pwd,
folders: nil,
files: nil,
source_files: nil,
stage_method: :current
}
end
Expand All @@ -145,6 +145,14 @@ def set_project_directory
end
end

def convert_to_source_files
unless @parsed[:project][:source_files]
@parsed[:project][:source_files] = @parsed[:project][:files] + @parsed[:project][:folders]
@parsed[:project].delete(:files)
@parsed[:project].delete(:folders)
end
end

def check_for_working
@parsed[:project][:stage_method] = :working if @options[:working]
end
Expand Down
15 changes: 9 additions & 6 deletions lib/roku_builder/config_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
module RokuBuilder
class ConfigValidator

DEPRICATED_FILES_FOLDERS = -1
VALID_CONFIG = 0
MISSING_DEVICES = 1
MISSING_DEVICES_DEFAULT = 2
Expand All @@ -15,7 +16,7 @@ class ConfigValidator
DEVICE_MISSING_PASSWORD = 9
PROJECT_MISSING_APP_NAME = 10
PROJECT_MISSING_DIRECTORY = 11
PROJECT_MISSING_FOLDERS = 12
# = 12
PROJECT_FOLDERS_BAD = 13
PROJECT_MISSING_FILES = 14
PROJECT_FILES_BAD = 15
Expand Down Expand Up @@ -138,12 +139,12 @@ def validate_project(project:)
errors= [
[PROJECT_MISSING_APP_NAME, (!project[:app_name])],
[PROJECT_MISSING_DIRECTORY, (!project[:directory])],
[PROJECT_MISSING_FOLDERS, (!project[:folders])],
[PROJECT_FOLDERS_BAD, (project[:folders] and !project[:folders].is_a?(Array))],
[PROJECT_MISSING_FILES, (!project[:files])],
[PROJECT_MISSING_FILES, (!project[:source_files] and !(project[:files] and project[:folders]))],
[PROJECT_FILES_BAD, (project[:files] and !project[:files].is_a?(Array))],
[MISSING_STAGE_METHOD, ( !project[:stage_method])],
[PROJECT_STAGE_METHOD_BAD, (![:git, :script, nil].include?(project[:stage_method]))]
[PROJECT_STAGE_METHOD_BAD, (![:git, :script, nil].include?(project[:stage_method]))],
[DEPRICATED_FILES_FOLDERS, (project[:files] or project[:folders])],
]
process_errors(errors: errors)
end
Expand Down Expand Up @@ -195,7 +196,7 @@ def error_codes
"A device config is missing its password.",
"A project config is missing its app_name.", #10
"A project config is missing its directorty.",
"A project config is missing its folders.",
"",
"A project config's folders is not an array.",
"A project config is missing its files.",
"A project config's files is not an array.", #15
Expand All @@ -206,7 +207,9 @@ def error_codes
"A key is missing its password.", #20
"A input mapping is invalid",
"A key is missing from the keys section",
"A project is missing its stage method."
"A project is missing its stage method.",
#===============Warnings===============#
"Using depricated files/folders projects keys. Use the combined source_files instead" #-1
]
end
end
Expand Down
38 changes: 11 additions & 27 deletions lib/roku_builder/plugins/loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,13 @@ def file_path(type)
end

def setup_build_content()
content = {}
content[:excludes] = []
content = {
excludes: []
}
if @options[:current]
content[:folders] = Dir.entries(@config.root_dir).select {|entry| File.directory? File.join(@config.root_dir, entry) and !(entry =='.' || entry == '..') }
content[:files] = Dir.entries(@config.root_dir).select {|entry| File.file? File.join(@config.root_dir, entry)}
content[:source_files] = Dir.entries(@config.root_dir).select {|entry| !(entry =='.' || entry == '..') }
else
content[:folders] = @config.project[:folders]
content[:files] = @config.project[:files]
content[:source_files] = @config.project[:source_files]
content[:excludes] = @config.project[:excludes] if @config.project[:excludes] and (@options[:exclude] or @options.exclude_command?)
end
content
Expand All @@ -121,20 +120,7 @@ def build_zip(content)
path = file_path(:out)
File.delete(path) if File.exist?(path)
io = Zip::File.open(path, Zip::File::CREATE)
# Add folders to zip
content[:folders].each do |folder|
base_folder = File.join(@config.root_dir, folder)
if File.exist?(base_folder)
entries = Dir.entries(base_folder)
entries.delete(".")
entries.delete("..")
writeEntries(@config.root_dir, entries, folder, content[:excludes], io)
else
@logger.warn "Missing Folder: #{base_folder}"
end
end
# Add file to zip
writeEntries(@config.parsed[:root_dir], content[:files], "", content[:excludes], io)
writeEntries(@config.parsed[:root_dir], content[:source_files], "", content[:excludes], io)
io.close()
end

Expand Down Expand Up @@ -168,13 +154,11 @@ def writeEntries(root_dir, entries, path, excludes, io)
}
end
def copy_channel_files(content)
[:files, :folders].each do |type|
content[type].each do |entity|
begin
FileUtils.copy_entry(File.join(@config.parsed[:root_dir], entity), File.join(@target, entity))
rescue Errno::ENOENT
@logger.warn "Missing Entry: #{entity}"
end
content[:source_files].each do |entity|
begin
FileUtils.copy_entry(File.join(@config.parsed[:root_dir], entity), File.join(@target, entity))
rescue Errno::ENOENT
@logger.warn "Missing Entry: #{entity}"
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/roku_builder/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

module RokuBuilder
# Version of the RokuBuilder Gem
VERSION = "4.12.3"
VERSION = "4.13.0"
end
2 changes: 1 addition & 1 deletion test/roku_builder/plugins/test_analyzer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def test_raf_proper_intergration_different_case
end
def test_macosx_directory
config = good_config(AnalyzerTest)
config[:projects][:project1][:folders].push("Test__MACOSX")
config[:projects][:project1][:source_files].push("Test__MACOSX")
@config, @options = build_config_options_objects(AnalyzerTest, {analyze: true, working: true}, false, config)
folder = File.join(@root_dir, "Test__MACOSX")
Dir.mkdir(folder) unless File.exist?(folder)
Expand Down
17 changes: 14 additions & 3 deletions test/roku_builder/test_config_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,21 +137,32 @@ def test_config_manager_validate_project_directory

def test_config_manager_validate_project_folders
config = good_config
config[:projects][:project1][:files] = ["manifest"]
config[:projects][:project1][:folders] = nil
config[:projects][:project1][:source_files] = nil
validator = ConfigValidator.new(config: config)
assert_equal [12], validator.instance_variable_get(:@codes)
assert_equal [14, -1], validator.instance_variable_get(:@codes)
end

def test_config_manager_validate_project_folders_is_array
config = good_config
config[:projects][:project1][:folders] = "Folders"
validator = ConfigValidator.new(config: config)
assert_equal [13], validator.instance_variable_get(:@codes)
assert_equal [13, -1], validator.instance_variable_get(:@codes)
end

def test_config_manager_validate_project_files
config = good_config
config[:projects][:project1][:files] = nil
config[:projects][:project1][:folders] = ["images", "source"]
config[:projects][:project1][:source_files] = nil
validator = ConfigValidator.new(config: config)
assert_equal [14, -1], validator.instance_variable_get(:@codes)
end

def test_config_manager_validate_project_source_files
config = good_config
config[:projects][:project1][:source_files] = nil
validator = ConfigValidator.new(config: config)
assert_equal [14], validator.instance_variable_get(:@codes)
end
Expand All @@ -160,7 +171,7 @@ def test_config_manager_validate_project_filess_is_array
config = good_config
config[:projects][:project1][:files] = "Files"
validator = ConfigValidator.new(config: config)
assert_equal [15], validator.instance_variable_get(:@codes)
assert_equal [15, -1], validator.instance_variable_get(:@codes)
end

def test_config_manager_validate_project_key
Expand Down
6 changes: 2 additions & 4 deletions test/roku_builder/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ def good_config(klass=nil)
default: :project1,
project1: {
directory: root_dir,
folders: ["images","source"],
files: ["manifest"],
source_files: ["manifest", "images", "source"],
app_name: "<app name>",
stage_method: :git,
stages:{
Expand All @@ -93,8 +92,7 @@ def good_config(klass=nil)
},
project2: {
directory: root_dir,
folders: ["images","source"],
files: ["manifest"],
source_files: ["images","source","manifest"],
app_name: "<app name>",
stage_method: :script,
stages:{
Expand Down

0 comments on commit b53a4c4

Please sign in to comment.