roku_builder_generator 0.1.0 → 0.3.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 +4 -4
- data/Gemfile +0 -2
- data/README.md +46 -3
- data/lib/roku_builder/plugins/generator.rb +88 -26
- data/lib/roku_builder_generator/brs_component.rb +20 -0
- data/lib/roku_builder_generator/templates/test.brs.erb +6 -0
- data/lib/roku_builder_generator/templates/test.setup.brs.erb +20 -0
- data/lib/roku_builder_generator/templates/test.xml.erb +16 -0
- data/lib/roku_builder_generator/version.rb +1 -1
- metadata +9 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50d50e79d829314444a02c6dfea8082c609185b2efdd0951c33f754daa6fcbda
|
4
|
+
data.tar.gz: 4ecb281d387c3eb92fa9dd345a75670ba2596d98dc831748a4cbe4842122cb69
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 226244599f730ae30f767a8473c48e9d416e0579b1e4ba643db134afd1fc2cd942210bb6dd80434735618f4fbd82f549314a9273bd789761bd501b9f8afded2c
|
7
|
+
data.tar.gz: 8e0a6d16062f870f60107977ad63a43e71945ede45d6d6aa7db5dd643d8efe4a3290b71efab6c1eac057799eaeda4dbc28755c040798ea1caab26e5e9dd8bab7
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -25,10 +25,16 @@ 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')
|
34
|
+
--with-tests Add unit tests
|
35
|
+
--only-tests Only unit tests
|
36
|
+
--tests-dir Use custom directory for unit tests
|
37
|
+
|
32
38
|
```
|
33
39
|
|
34
40
|
### Examples
|
@@ -41,6 +47,10 @@ Generate a task ("Bar"), but just display the output on screen:
|
|
41
47
|
|
42
48
|
`roku --generate task --name bar --dry-run -V`
|
43
49
|
|
50
|
+
Generate a module ("Buz"), and also generate config and unit tests
|
51
|
+
|
52
|
+
`roku --generate module --name buz --with-config --with-tests`
|
53
|
+
|
44
54
|
### Config
|
45
55
|
|
46
56
|
You can supplement the default configuration using a local file `.roku_builder_generator.json`
|
@@ -49,12 +59,45 @@ Format of config file:
|
|
49
59
|
|
50
60
|
```js
|
51
61
|
{
|
52
|
-
"component_dir": "base/directory/for/components", // default: "./brands
|
53
|
-
"config_dir": "base/directory/for/config/json/files", // default: "./brands
|
62
|
+
"component_dir": "base/directory/for/components", // default: "./brands/%brand%/components"
|
63
|
+
"config_dir": "base/directory/for/config/json/files", // default: "./brands/%brand%/region/US/configs"
|
54
64
|
"template_dir": "directory/for/templates" // default: "./roku_builder_generator"
|
55
65
|
}
|
56
66
|
```
|
57
67
|
|
68
|
+
### Directories and Brands
|
69
|
+
|
70
|
+
Unless you specify a custom directory, generated files will be placed in the default directory. For example,
|
71
|
+
`roku --generate manager --name foo --with-config`
|
72
|
+
will generate the following files:
|
73
|
+
|
74
|
+
- ./brands/core/components/Managers/FooManager/FooManager.xml
|
75
|
+
- ./brands/core/components/Managers/FooManager/FooManager.brs
|
76
|
+
- ./brands/core/region/US/configs/Managers/Foo.json
|
77
|
+
|
78
|
+
without specifying custom directories, files can be generated for other brands. For example,
|
79
|
+
|
80
|
+
`roku --generate manager --name foo --for-brand comedy --with-config`
|
81
|
+
|
82
|
+
will generate:
|
83
|
+
|
84
|
+
- ./brands/comedy/components/Managers/FooManager/FooManager.xml
|
85
|
+
- ./brands/comedy/components/Managers/FooManager/FooManager.brs
|
86
|
+
- ./brands/comedy/region/US/configs/Managers/Foo.json
|
87
|
+
|
88
|
+
To enable changing brands for directories specified in `.roku_builder_generator.json`, use `%brand%` in the position where the brand should be replaced.
|
89
|
+
|
90
|
+
For example, if you specify `"component_dir": "some/directory/%brand%/components"` and you ran the command
|
91
|
+
|
92
|
+
`roku --generate manager --name foo --for-brand my-brand`
|
93
|
+
|
94
|
+
it would generate files
|
95
|
+
|
96
|
+
- ./some/directory/my-brand/components/Managers/FooManager/FooManager.xml
|
97
|
+
- ./some/directory/my-brand/components/Managers/FooManager/FooManager.brs
|
98
|
+
|
99
|
+
Note: If nothing is specified by the `--for-brand` option, it will use "core".
|
100
|
+
|
58
101
|
### Custom Templates
|
59
102
|
|
60
103
|
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,36 @@ 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
|
+
:unitTests_dir => "brands/unit-tests/components/tests",
|
10
11
|
:template_dir => "roku_builder_generator"
|
11
12
|
}
|
12
13
|
end
|
13
14
|
|
14
|
-
def default_output_dir(component_type, base_dir = nil)
|
15
|
+
def default_output_dir(component_type, brand = 'core', base_dir = nil)
|
15
16
|
base_dir = base_dir || default_config[:component_dir]
|
17
|
+
base_dir = replace_brand(base_dir, brand)
|
16
18
|
return "#{base_dir}/#{component_type.capitalize()}s"
|
17
19
|
end
|
18
20
|
|
19
|
-
def default_config_dir(component_type, base_dir = nil)
|
21
|
+
def default_config_dir(component_type, brand = 'core', base_dir = nil)
|
20
22
|
base_dir = base_dir || default_config[:config_dir]
|
21
|
-
|
23
|
+
base_dir = replace_brand(base_dir, brand)
|
24
|
+
return "#{base_dir}/#{component_type.capitalize()}s"
|
25
|
+
end
|
26
|
+
|
27
|
+
def default_unitTests_dir(component_type, base_dir = nil)
|
28
|
+
base_dir = base_dir || default_config[:unitTests_dir]
|
29
|
+
return "#{base_dir}/#{component_type.capitalize()}s"
|
22
30
|
end
|
23
31
|
|
24
32
|
|
33
|
+
def replace_brand(directory, newBrand = 'core')
|
34
|
+
directory["%brand%"]=newBrand
|
35
|
+
return directory
|
36
|
+
end
|
37
|
+
|
25
38
|
module RokuBuilder
|
26
39
|
|
27
40
|
class Generator < Util
|
@@ -43,20 +56,24 @@ module RokuBuilder
|
|
43
56
|
end
|
44
57
|
|
45
58
|
|
46
|
-
def get_output_dir( component_type, component_name, parent_dir = nil, custom_dir = nil, base_component_dir = nil )
|
59
|
+
def get_output_dir( component_type, component_name, brand, parent_dir = nil, custom_dir = nil, base_component_dir = nil )
|
47
60
|
output_dir = get_directory_name(component_type, component_name)
|
48
61
|
unless parent_dir.nil? || "" === parent_dir
|
49
62
|
output_dir = parent_dir+"/"+output_dir
|
50
63
|
end
|
51
|
-
base_dir = custom_dir ? custom_dir : default_output_dir(component_type, base_component_dir)
|
64
|
+
base_dir = !custom_dir.nil? ? replace_brand(custom_dir, brand) : default_output_dir(component_type, brand, base_component_dir)
|
52
65
|
return "./#{base_dir}/#{output_dir}"
|
53
66
|
|
54
67
|
end
|
55
68
|
|
56
|
-
def get_config_output_dir( component_type,
|
57
|
-
base_dir = custom_dir ? custom_dir : default_config_dir(component_type,
|
69
|
+
def get_config_output_dir( component_type, brand, custom_dir = nil )
|
70
|
+
base_dir = !custom_dir.nil? ? replace_brand(custom_dir, brand) : default_config_dir(component_type, brand)
|
58
71
|
return "./#{base_dir}"
|
72
|
+
end
|
59
73
|
|
74
|
+
def get_unitTests_output_dir(component_type, custom_dir = nil )
|
75
|
+
base_dir = !custom_dir.nil? ? custom_dir : default_unitTests_dir(component_type)
|
76
|
+
return "./#{base_dir}"
|
60
77
|
end
|
61
78
|
|
62
79
|
# Hook to add options to the parser
|
@@ -64,16 +81,21 @@ module RokuBuilder
|
|
64
81
|
# hash
|
65
82
|
def self.parse_options(parser:, options:)
|
66
83
|
parser.separator "Commands:"
|
84
|
+
options[:brand] = 'core'
|
67
85
|
parser.on("--generate COMPONENT_TYPE", "Generate a component: manager, module, task, screen") do |component_type|
|
68
86
|
options[:generate] = component_type
|
69
87
|
end
|
70
88
|
parser.on("--name COMPONENT_NAME", "Name of the component") do |component_name|
|
71
89
|
options[:name] = component_name
|
72
90
|
end
|
91
|
+
parser.separator "Options:"
|
73
92
|
parser.on("--extends COMPONENT_NAME", "A component to extend") do |component_name|
|
74
93
|
options[:extends] = component_name
|
75
94
|
end
|
76
|
-
parser.on("--
|
95
|
+
parser.on("--for-brand BRAND", "Brand to put component in (default:' core')") do |brand|
|
96
|
+
options[:brand] = brand
|
97
|
+
end
|
98
|
+
parser.on("--base-dir", "Base directory for generated brs/xml code (eg.: '#{default_output_dir('<type>')}')") do |base_dir|
|
77
99
|
options[:custom_dir] = base_dir
|
78
100
|
end
|
79
101
|
parser.on("--with-config", "Add empty config JSON") do |d|
|
@@ -82,6 +104,16 @@ module RokuBuilder
|
|
82
104
|
parser.on("--config-dir", "Use custom directory for config json (eg.: '#{default_config_dir('<type>')}')") do |d|
|
83
105
|
options[:config_dir] = d
|
84
106
|
end
|
107
|
+
parser.on("--with-tests", "Add unit tests") do |d|
|
108
|
+
options[:with_tests] = true
|
109
|
+
end
|
110
|
+
parser.on("--only-tests", "Only unit tests") do |d|
|
111
|
+
options[:only_tests] = true
|
112
|
+
options[:with_tests] = true
|
113
|
+
end
|
114
|
+
parser.on("--tests-dir", "Use custom directory for unit tests (eg.: '#{default_unitTests_dir('<type>')}')") do |d|
|
115
|
+
options[:tests_dir] = d
|
116
|
+
end
|
85
117
|
parser.on("--dry-run", "Do not write files, just output") do |d|
|
86
118
|
options[:dry_run] = true
|
87
119
|
end
|
@@ -96,9 +128,11 @@ module RokuBuilder
|
|
96
128
|
#Setup
|
97
129
|
end
|
98
130
|
|
131
|
+
def capitalizeFirst(name)
|
132
|
+
name.slice(0,1).capitalize + name.slice(1..-1)
|
133
|
+
end
|
99
134
|
|
100
135
|
def get_file_name(component_type, name)
|
101
|
-
name = name.slice(0,1).capitalize + name.slice(1..-1)
|
102
136
|
if(component_type == 'screen' && !name.end_with?("Screen"))
|
103
137
|
return name+ "Screen"
|
104
138
|
end
|
@@ -109,7 +143,6 @@ module RokuBuilder
|
|
109
143
|
end
|
110
144
|
|
111
145
|
def get_directory_name(component_type, name)
|
112
|
-
name = name.slice(0,1).capitalize + name.slice(1..-1)
|
113
146
|
if(component_type === 'manager'&& !name.end_with?("Manager"))
|
114
147
|
return name+'Manager'
|
115
148
|
end
|
@@ -118,7 +151,6 @@ module RokuBuilder
|
|
118
151
|
|
119
152
|
def component_has_config_json(component_type)
|
120
153
|
['module', 'screen', 'manager'].include? component_type
|
121
|
-
|
122
154
|
end
|
123
155
|
|
124
156
|
def generate(options:)
|
@@ -131,8 +163,9 @@ module RokuBuilder
|
|
131
163
|
config = read_config()
|
132
164
|
component_type = options[:generate].downcase
|
133
165
|
component_name_parts = options[:name].split('/')
|
134
|
-
component_proper_name = component_name_parts.last
|
166
|
+
component_proper_name = capitalizeFirst(component_name_parts.last)
|
135
167
|
component_parent_dir = component_name_parts.first(component_name_parts.size-1).join('/')
|
168
|
+
brand = options[:brand].downcase
|
136
169
|
|
137
170
|
component_name = get_file_name(component_type, component_proper_name)
|
138
171
|
component = RokuBuilderGenerator::BrsComponent.new(component_name, options[:extends], component_type, @logger)
|
@@ -140,27 +173,52 @@ module RokuBuilder
|
|
140
173
|
brs_text = component.render("brs")
|
141
174
|
json_text = options[:with_config] && component_has_config_json(component_type) ? component.render("json") : nil
|
142
175
|
|
143
|
-
|
144
|
-
|
176
|
+
test_xml_text = options[:with_tests] ? component.renderTest("xml") : nil
|
177
|
+
test_brs_text = options[:with_tests] ? component.renderTest("brs") : nil
|
178
|
+
testSetup_brs_text = options[:with_tests] ? component.renderTestSetup() : nil
|
179
|
+
|
180
|
+
output_dir = get_output_dir(component_type, component_name, brand, component_parent_dir, options[:custom_dir], config[:component_dir])
|
181
|
+
output_config_dir = get_config_output_dir(component_type, brand, options[:config_dir])
|
145
182
|
output_file_name = File.join(output_dir, component_name)
|
146
183
|
output_config_file_name = File.join(output_config_dir, component_proper_name)
|
147
184
|
|
185
|
+
output_unitTests_dir = get_unitTests_output_dir(component_type, options[:config_dir])
|
186
|
+
|
187
|
+
test_component_name= "Test_"+component_proper_name
|
188
|
+
|
189
|
+
output_test_file_name = File.join(output_unitTests_dir, test_component_name)
|
190
|
+
output_test_setup_file_name= File.join(output_unitTests_dir, test_component_name+".setup")
|
191
|
+
|
148
192
|
if(options[:dry_run])
|
149
193
|
@logger.unknown "Dry Run, not writing files"
|
150
194
|
show_line()
|
151
|
-
|
152
|
-
|
153
|
-
|
195
|
+
unless options[:only_tests]
|
196
|
+
display_file(output_file_name+".xml", xml_text)
|
197
|
+
display_file(output_file_name+".brs", brs_text)
|
198
|
+
display_file(output_config_file_name+".json", json_text)
|
199
|
+
end
|
200
|
+
|
201
|
+
display_file(output_test_file_name+".xml", test_xml_text)
|
202
|
+
display_file(output_test_file_name+".brs", test_brs_text)
|
203
|
+
display_file(output_test_setup_file_name+".brs", testSetup_brs_text)
|
154
204
|
else
|
155
205
|
@logger.unknown "Writing files"
|
156
206
|
show_line()
|
157
|
-
|
158
|
-
|
159
|
-
|
207
|
+
unless options[:only_tests]
|
208
|
+
FileUtils.mkdir_p output_dir
|
209
|
+
unless json_text.nil?
|
210
|
+
FileUtils.mkdir_p output_config_dir
|
211
|
+
end
|
212
|
+
write_file(output_file_name+".xml", xml_text)
|
213
|
+
write_file(output_file_name+".brs", brs_text)
|
214
|
+
write_file(output_config_file_name+".json", json_text)
|
160
215
|
end
|
161
|
-
|
162
|
-
|
163
|
-
|
216
|
+
unless test_xml_text.nil?
|
217
|
+
FileUtils.mkdir_p output_unitTests_dir
|
218
|
+
end
|
219
|
+
write_file(output_test_file_name+".xml", test_xml_text)
|
220
|
+
write_file(output_test_file_name+".brs", test_brs_text)
|
221
|
+
write_file(output_test_setup_file_name+".brs", testSetup_brs_text)
|
164
222
|
end
|
165
223
|
end
|
166
224
|
|
@@ -176,7 +234,11 @@ module RokuBuilder
|
|
176
234
|
def write_file(output_file_name, contents)
|
177
235
|
unless contents.nil?
|
178
236
|
@logger.unknown output_file_name
|
179
|
-
File.
|
237
|
+
if File.exist?(output_file_name)
|
238
|
+
@logger.warn "#{output_file_name} already exists, skipping"
|
239
|
+
else
|
240
|
+
File.open(output_file_name, "w") { |f| f.write contents }
|
241
|
+
end
|
180
242
|
end
|
181
243
|
end
|
182
244
|
|
@@ -27,6 +27,26 @@ module RokuBuilderGenerator
|
|
27
27
|
return nil
|
28
28
|
end
|
29
29
|
|
30
|
+
def renderTest(file_type)
|
31
|
+
file_name = get_template_name("test", file_type)
|
32
|
+
|
33
|
+
unless file_name.nil?
|
34
|
+
template = File.read(file_name)
|
35
|
+
return render_template(template)
|
36
|
+
end
|
37
|
+
return nil
|
38
|
+
end
|
39
|
+
|
40
|
+
def renderTestSetup()
|
41
|
+
file_name = get_template_name("test.setup", "brs")
|
42
|
+
|
43
|
+
unless file_name.nil?
|
44
|
+
template = File.read(file_name)
|
45
|
+
return render_template(template)
|
46
|
+
end
|
47
|
+
return nil
|
48
|
+
end
|
49
|
+
|
30
50
|
def log(message)
|
31
51
|
unless @logger.nil?
|
32
52
|
@logger.info message
|
@@ -0,0 +1,20 @@
|
|
1
|
+
function TestSuite_<%= name %>_Setup()
|
2
|
+
' Inherit your test suite from BaseTestSuite
|
3
|
+
this = BaseTestSuite()
|
4
|
+
|
5
|
+
' Test suite name for log statistics
|
6
|
+
this.Name = "TestSuite_<%= name %>_Setup"
|
7
|
+
|
8
|
+
' Add tests to suite's tests collection
|
9
|
+
this.addTest("TestCase_Config_Exists", TestCase_Config_Exists)
|
10
|
+
|
11
|
+
return this
|
12
|
+
end function
|
13
|
+
|
14
|
+
function TestCase_Example()
|
15
|
+
config = getGlobalAA().channelConfig
|
16
|
+
codebox = getGlobalAA().codebox
|
17
|
+
|
18
|
+
m.assertNotInvalid(config)
|
19
|
+
m.assertNotInvalid(codebox)
|
20
|
+
end function
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8" ?>
|
2
|
+
<!-- ##COPYRIGHT HEADER## -->
|
3
|
+
|
4
|
+
<component name="Test_<%= name %>" extends="<%= name %>">
|
5
|
+
<!-- Function, used by framework, to run tests. Should not be called manually! -->
|
6
|
+
<interface>
|
7
|
+
<function name="TestFramework__RunNodeTests"/>
|
8
|
+
</interface>
|
9
|
+
|
10
|
+
<!-- Import test suites. -->
|
11
|
+
<script type="text/brightscript" uri="Test_<%= name %>.brs" />
|
12
|
+
<script type="text/brightscript" uri="Test_<%= name %>.setup.brs" />
|
13
|
+
|
14
|
+
<!-- Import test framework. -->
|
15
|
+
<script type="text/brightscript" uri="pkg:/source/UnitTestFramework.brs"/>
|
16
|
+
</component>
|
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.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Pearce
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-03-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: roku_builder
|
@@ -58,13 +58,16 @@ files:
|
|
58
58
|
- lib/roku_builder_generator/templates/manager.brs.erb
|
59
59
|
- lib/roku_builder_generator/templates/module.xml.erb
|
60
60
|
- lib/roku_builder_generator/templates/screen.xml.erb
|
61
|
+
- lib/roku_builder_generator/templates/test.brs.erb
|
62
|
+
- lib/roku_builder_generator/templates/test.setup.brs.erb
|
63
|
+
- lib/roku_builder_generator/templates/test.xml.erb
|
61
64
|
- lib/roku_builder_generator/utils.rb
|
62
65
|
- lib/roku_builder_generator/version.rb
|
63
66
|
- roku_builder_generator.gemspec
|
64
67
|
homepage: ''
|
65
68
|
licenses: []
|
66
69
|
metadata: {}
|
67
|
-
post_install_message:
|
70
|
+
post_install_message:
|
68
71
|
rdoc_options: []
|
69
72
|
require_paths:
|
70
73
|
- lib
|
@@ -79,8 +82,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
82
|
- !ruby/object:Gem::Version
|
80
83
|
version: '0'
|
81
84
|
requirements: []
|
82
|
-
rubygems_version: 3.
|
83
|
-
signing_key:
|
85
|
+
rubygems_version: 3.2.32
|
86
|
+
signing_key:
|
84
87
|
specification_version: 4
|
85
88
|
summary: RokuBuilder Generator Plugin
|
86
89
|
test_files: []
|