roku_builder_generator 0.1.0 → 0.2.1
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/Gemfile +0 -2
- data/README.md +38 -3
- data/lib/roku_builder/plugins/generator.rb +34 -17
- data/lib/roku_builder_generator/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1689feb43f47e343530956db694328c6777d0949df073ee9187b274d53a4658c
|
4
|
+
data.tar.gz: 498b94cd2b6e266d3ef1dcd8bf145fa19e177de83e531fe04716e212e73e6202
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9937fb52d8f1701a4c40a85db4d793ae16b840c00ddb21b05b8070713d156f4a52951cf7a1de0dc7bfade4ce23ba0cec772695b889928c6c3fab4e22dc88b286
|
7
|
+
data.tar.gz: 5afc1b7ee76064e0ed340c15959bbbfb8e9755df8e917f5d3289e86b5556245401ab1a6ffe74423003265ead8327ecd03245fd78b08472982944bc76e945d683
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -25,8 +25,10 @@ Options for RokuBuilder::Generator:
|
|
25
25
|
Commands:
|
26
26
|
--generate COMPONENT_TYPE Generate a component: manager, module, task, screen
|
27
27
|
--name COMPONENT_NAME Name of the component
|
28
|
+
Options:
|
28
29
|
--extends COMPONENT_NAME A component to extend
|
29
|
-
--
|
30
|
+
--for-brand BRAND Brand to put component in (default:' core')
|
31
|
+
--base-dir Base directory for generated brs/xml code (eg.: 'brands/core/components/<type>s')
|
30
32
|
--with-config Add empty config JSON
|
31
33
|
--config-dir Use custom directory for config json (eg.: 'brands/core/region/US/configs/<type>s')
|
32
34
|
```
|
@@ -49,12 +51,45 @@ Format of config file:
|
|
49
51
|
|
50
52
|
```js
|
51
53
|
{
|
52
|
-
"component_dir": "base/directory/for/components", // default: "./brands
|
53
|
-
"config_dir": "base/directory/for/config/json/files", // default: "./brands
|
54
|
+
"component_dir": "base/directory/for/components", // default: "./brands/%brand%/components"
|
55
|
+
"config_dir": "base/directory/for/config/json/files", // default: "./brands/%brand%/region/US/configs"
|
54
56
|
"template_dir": "directory/for/templates" // default: "./roku_builder_generator"
|
55
57
|
}
|
56
58
|
```
|
57
59
|
|
60
|
+
### Directories and Brands
|
61
|
+
|
62
|
+
Unless you specify a custom directory, generated files will be placed in the default directory. For example,
|
63
|
+
`roku --generate manager --name foo --with-config`
|
64
|
+
will generate the following files:
|
65
|
+
|
66
|
+
- ./brands/core/components/Managers/FooManager/FooManager.xml
|
67
|
+
- ./brands/core/components/Managers/FooManager/FooManager.brs
|
68
|
+
- ./brands/core/region/US/configs/Managers/Foo.json
|
69
|
+
|
70
|
+
without specifying custom directories, files can be generated for other brands. For example,
|
71
|
+
|
72
|
+
`roku --generate manager --name foo --for-brand comedy --with-config`
|
73
|
+
|
74
|
+
will generate:
|
75
|
+
|
76
|
+
- ./brands/comedy/components/Managers/FooManager/FooManager.xml
|
77
|
+
- ./brands/comedy/components/Managers/FooManager/FooManager.brs
|
78
|
+
- ./brands/comedy/region/US/configs/Managers/Foo.json
|
79
|
+
|
80
|
+
To enable changing brands for directories specified in `.roku_builder_generator.json`, use `%brand%` in the position where the brand should be replaced.
|
81
|
+
|
82
|
+
For example, if you specify `"component_dir": "some/directory/%brand%/components"` and you ran the command
|
83
|
+
|
84
|
+
`roku --generate manager --name foo --for-brand my-brand`
|
85
|
+
|
86
|
+
it would generate files
|
87
|
+
|
88
|
+
- ./some/directory/my-brand/components/Managers/FooManager/FooManager.xml
|
89
|
+
- ./some/directory/my-brand/components/Managers/FooManager/FooManager.brs
|
90
|
+
|
91
|
+
Note: If nothing is specified by the `--for-brand` option, it will use "core".
|
92
|
+
|
58
93
|
### Custom Templates
|
59
94
|
|
60
95
|
You can add custom templates for different component types by adding [ERB](https://www.stuartellis.name/articles/erb/) files to the template directory (either `./roku_builder_generator` or whatever was defined in the config).
|
@@ -5,23 +5,30 @@ require_relative '../../roku_builder_generator'
|
|
5
5
|
|
6
6
|
def default_config()
|
7
7
|
return {
|
8
|
-
:component_dir => "brands
|
9
|
-
:config_dir => "brands
|
8
|
+
:component_dir => "brands/%brand%/components",
|
9
|
+
:config_dir => "brands/%brand%/region/US/configs",
|
10
10
|
:template_dir => "roku_builder_generator"
|
11
11
|
}
|
12
12
|
end
|
13
13
|
|
14
|
-
def default_output_dir(component_type, base_dir = nil)
|
14
|
+
def default_output_dir(component_type, brand = 'core', base_dir = nil)
|
15
15
|
base_dir = base_dir || default_config[:component_dir]
|
16
|
+
base_dir = replace_brand(base_dir, brand)
|
16
17
|
return "#{base_dir}/#{component_type.capitalize()}s"
|
17
18
|
end
|
18
19
|
|
19
|
-
def default_config_dir(component_type, base_dir = nil)
|
20
|
+
def default_config_dir(component_type, brand = 'core', base_dir = nil)
|
20
21
|
base_dir = base_dir || default_config[:config_dir]
|
21
|
-
|
22
|
+
base_dir = replace_brand(base_dir, brand)
|
23
|
+
return "#{base_dir}/#{component_type.capitalize()}s"
|
22
24
|
end
|
23
25
|
|
24
26
|
|
27
|
+
def replace_brand(directory, newBrand = 'core')
|
28
|
+
directory["%brand%"]=newBrand
|
29
|
+
return directory
|
30
|
+
end
|
31
|
+
|
25
32
|
module RokuBuilder
|
26
33
|
|
27
34
|
class Generator < Util
|
@@ -43,20 +50,19 @@ module RokuBuilder
|
|
43
50
|
end
|
44
51
|
|
45
52
|
|
46
|
-
def get_output_dir( component_type, component_name, parent_dir = nil, custom_dir = nil, base_component_dir = nil )
|
53
|
+
def get_output_dir( component_type, component_name, brand, parent_dir = nil, custom_dir = nil, base_component_dir = nil )
|
47
54
|
output_dir = get_directory_name(component_type, component_name)
|
48
55
|
unless parent_dir.nil? || "" === parent_dir
|
49
56
|
output_dir = parent_dir+"/"+output_dir
|
50
57
|
end
|
51
|
-
base_dir = custom_dir ? custom_dir : default_output_dir(component_type, base_component_dir)
|
58
|
+
base_dir = !custom_dir.nil? ? replace_brand(custom_dir, brand) : default_output_dir(component_type, brand, base_component_dir)
|
52
59
|
return "./#{base_dir}/#{output_dir}"
|
53
60
|
|
54
61
|
end
|
55
62
|
|
56
|
-
def get_config_output_dir( component_type,
|
57
|
-
base_dir = custom_dir ? custom_dir : default_config_dir(component_type,
|
63
|
+
def get_config_output_dir( component_type, brand, custom_dir = nil )
|
64
|
+
base_dir = !custom_dir.nil? ? replace_brand(custom_dir, brand) : default_config_dir(component_type, brand)
|
58
65
|
return "./#{base_dir}"
|
59
|
-
|
60
66
|
end
|
61
67
|
|
62
68
|
# Hook to add options to the parser
|
@@ -64,16 +70,21 @@ module RokuBuilder
|
|
64
70
|
# hash
|
65
71
|
def self.parse_options(parser:, options:)
|
66
72
|
parser.separator "Commands:"
|
73
|
+
options[:brand] = 'core'
|
67
74
|
parser.on("--generate COMPONENT_TYPE", "Generate a component: manager, module, task, screen") do |component_type|
|
68
75
|
options[:generate] = component_type
|
69
76
|
end
|
70
77
|
parser.on("--name COMPONENT_NAME", "Name of the component") do |component_name|
|
71
78
|
options[:name] = component_name
|
72
79
|
end
|
80
|
+
parser.separator "Options:"
|
73
81
|
parser.on("--extends COMPONENT_NAME", "A component to extend") do |component_name|
|
74
82
|
options[:extends] = component_name
|
75
83
|
end
|
76
|
-
parser.on("--
|
84
|
+
parser.on("--for-brand BRAND", "Brand to put component in (default:' core')") do |brand|
|
85
|
+
options[:brand] = brand
|
86
|
+
end
|
87
|
+
parser.on("--base-dir", "Base directory for generated brs/xml code (eg.: '#{default_output_dir('<type>')}')") do |base_dir|
|
77
88
|
options[:custom_dir] = base_dir
|
78
89
|
end
|
79
90
|
parser.on("--with-config", "Add empty config JSON") do |d|
|
@@ -96,9 +107,11 @@ module RokuBuilder
|
|
96
107
|
#Setup
|
97
108
|
end
|
98
109
|
|
110
|
+
def capitalizeFirst(name)
|
111
|
+
name.slice(0,1).capitalize + name.slice(1..-1)
|
112
|
+
end
|
99
113
|
|
100
114
|
def get_file_name(component_type, name)
|
101
|
-
name = name.slice(0,1).capitalize + name.slice(1..-1)
|
102
115
|
if(component_type == 'screen' && !name.end_with?("Screen"))
|
103
116
|
return name+ "Screen"
|
104
117
|
end
|
@@ -109,7 +122,6 @@ module RokuBuilder
|
|
109
122
|
end
|
110
123
|
|
111
124
|
def get_directory_name(component_type, name)
|
112
|
-
name = name.slice(0,1).capitalize + name.slice(1..-1)
|
113
125
|
if(component_type === 'manager'&& !name.end_with?("Manager"))
|
114
126
|
return name+'Manager'
|
115
127
|
end
|
@@ -131,8 +143,9 @@ module RokuBuilder
|
|
131
143
|
config = read_config()
|
132
144
|
component_type = options[:generate].downcase
|
133
145
|
component_name_parts = options[:name].split('/')
|
134
|
-
component_proper_name = component_name_parts.last
|
146
|
+
component_proper_name = capitalizeFirst(component_name_parts.last)
|
135
147
|
component_parent_dir = component_name_parts.first(component_name_parts.size-1).join('/')
|
148
|
+
brand = brand.downcase
|
136
149
|
|
137
150
|
component_name = get_file_name(component_type, component_proper_name)
|
138
151
|
component = RokuBuilderGenerator::BrsComponent.new(component_name, options[:extends], component_type, @logger)
|
@@ -140,8 +153,8 @@ module RokuBuilder
|
|
140
153
|
brs_text = component.render("brs")
|
141
154
|
json_text = options[:with_config] && component_has_config_json(component_type) ? component.render("json") : nil
|
142
155
|
|
143
|
-
output_dir = get_output_dir(component_type, component_name, component_parent_dir, options[:custom_dir], config[:component_dir])
|
144
|
-
output_config_dir = get_config_output_dir(component_type, options[:config_dir]
|
156
|
+
output_dir = get_output_dir(component_type, component_name, brand, component_parent_dir, options[:custom_dir], config[:component_dir])
|
157
|
+
output_config_dir = get_config_output_dir(component_type, brand, options[:config_dir])
|
145
158
|
output_file_name = File.join(output_dir, component_name)
|
146
159
|
output_config_file_name = File.join(output_config_dir, component_proper_name)
|
147
160
|
|
@@ -176,7 +189,11 @@ module RokuBuilder
|
|
176
189
|
def write_file(output_file_name, contents)
|
177
190
|
unless contents.nil?
|
178
191
|
@logger.unknown output_file_name
|
179
|
-
File.
|
192
|
+
if File.exist?(output_file_name)
|
193
|
+
@logger.warn "#{output_file_name} already exists, skipping"
|
194
|
+
else
|
195
|
+
File.open(output_file_name, "w") { |f| f.write contents }
|
196
|
+
end
|
180
197
|
end
|
181
198
|
end
|
182
199
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: roku_builder_generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Pearce
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-05-
|
11
|
+
date: 2020-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: roku_builder
|