roku_builder_generator 0.2.1 → 0.3.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/README.md +8 -0
- data/lib/roku_builder/plugins/generator.rb +57 -11
- 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.xml.erb +16 -0
- data/lib/roku_builder_generator/templates/test_Setup.brs.erb +20 -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: 1853683defadf4bb9cf28a4b5aea7cc60fc7726bbcdaefece8956c5bc9b9436d
|
4
|
+
data.tar.gz: 8e46fd60a6bee8db1f4dc5f5e747084377b3a4cb8f80b883f959bbab19c1c126
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9cab4f02389e86b1fe1a3ec96868a8919dbbfdee1ff956d6ee953c651eaa22e9f739e80b11b201504272dde389b9e2afba07d9be12ffc300d3032b998673e0b6
|
7
|
+
data.tar.gz: 7d314841d2473bfd2ff4f1fcc881a0eb5a3643e8c35ec111f69f29bf89cf7c28d8938a669864902b0f007f7b817415e051136c1bc76d17e4e19148b3e6e26b6d
|
data/README.md
CHANGED
@@ -31,6 +31,10 @@ Options:
|
|
31
31
|
--base-dir Base directory for generated brs/xml code (eg.: 'brands/core/components/<type>s')
|
32
32
|
--with-config Add empty config JSON
|
33
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
|
+
|
34
38
|
```
|
35
39
|
|
36
40
|
### Examples
|
@@ -43,6 +47,10 @@ Generate a task ("Bar"), but just display the output on screen:
|
|
43
47
|
|
44
48
|
`roku --generate task --name bar --dry-run -V`
|
45
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
|
+
|
46
54
|
### Config
|
47
55
|
|
48
56
|
You can supplement the default configuration using a local file `.roku_builder_generator.json`
|
@@ -7,6 +7,7 @@ def default_config()
|
|
7
7
|
return {
|
8
8
|
:component_dir => "brands/%brand%/components",
|
9
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
|
@@ -23,6 +24,11 @@ def default_config_dir(component_type, brand = 'core', base_dir = nil)
|
|
23
24
|
return "#{base_dir}/#{component_type.capitalize()}s"
|
24
25
|
end
|
25
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"
|
30
|
+
end
|
31
|
+
|
26
32
|
|
27
33
|
def replace_brand(directory, newBrand = 'core')
|
28
34
|
directory["%brand%"]=newBrand
|
@@ -65,6 +71,12 @@ module RokuBuilder
|
|
65
71
|
return "./#{base_dir}"
|
66
72
|
end
|
67
73
|
|
74
|
+
def get_unitTests_output_dir(component_type, component_name, custom_dir = nil )
|
75
|
+
output_dir = get_directory_name(component_type, component_name)
|
76
|
+
base_dir = !custom_dir.nil? ? custom_dir : default_unitTests_dir(component_type)
|
77
|
+
return "./#{base_dir}/#{output_dir}"
|
78
|
+
end
|
79
|
+
|
68
80
|
# Hook to add options to the parser
|
69
81
|
# The keys set in options for commands must match the keys in the commands
|
70
82
|
# hash
|
@@ -93,6 +105,16 @@ module RokuBuilder
|
|
93
105
|
parser.on("--config-dir", "Use custom directory for config json (eg.: '#{default_config_dir('<type>')}')") do |d|
|
94
106
|
options[:config_dir] = d
|
95
107
|
end
|
108
|
+
parser.on("--with-tests", "Add unit tests") do |d|
|
109
|
+
options[:with_tests] = true
|
110
|
+
end
|
111
|
+
parser.on("--only-tests", "Only unit tests") do |d|
|
112
|
+
options[:only_tests] = true
|
113
|
+
options[:with_tests] = true
|
114
|
+
end
|
115
|
+
parser.on("--tests-dir", "Use custom directory for unit tests (eg.: '#{default_unitTests_dir('<type>')}')") do |d|
|
116
|
+
options[:tests_dir] = d
|
117
|
+
end
|
96
118
|
parser.on("--dry-run", "Do not write files, just output") do |d|
|
97
119
|
options[:dry_run] = true
|
98
120
|
end
|
@@ -130,7 +152,6 @@ module RokuBuilder
|
|
130
152
|
|
131
153
|
def component_has_config_json(component_type)
|
132
154
|
['module', 'screen', 'manager'].include? component_type
|
133
|
-
|
134
155
|
end
|
135
156
|
|
136
157
|
def generate(options:)
|
@@ -145,7 +166,7 @@ module RokuBuilder
|
|
145
166
|
component_name_parts = options[:name].split('/')
|
146
167
|
component_proper_name = capitalizeFirst(component_name_parts.last)
|
147
168
|
component_parent_dir = component_name_parts.first(component_name_parts.size-1).join('/')
|
148
|
-
brand =
|
169
|
+
brand = options[:brand].downcase
|
149
170
|
|
150
171
|
component_name = get_file_name(component_type, component_proper_name)
|
151
172
|
component = RokuBuilderGenerator::BrsComponent.new(component_name, options[:extends], component_type, @logger)
|
@@ -153,27 +174,52 @@ module RokuBuilder
|
|
153
174
|
brs_text = component.render("brs")
|
154
175
|
json_text = options[:with_config] && component_has_config_json(component_type) ? component.render("json") : nil
|
155
176
|
|
177
|
+
test_xml_text = options[:with_tests] ? component.renderTest("xml") : nil
|
178
|
+
test_brs_text = options[:with_tests] ? component.renderTest("brs") : nil
|
179
|
+
testSetup_brs_text = options[:with_tests] ? component.renderTestSetup() : nil
|
180
|
+
|
156
181
|
output_dir = get_output_dir(component_type, component_name, brand, component_parent_dir, options[:custom_dir], config[:component_dir])
|
157
182
|
output_config_dir = get_config_output_dir(component_type, brand, options[:config_dir])
|
158
183
|
output_file_name = File.join(output_dir, component_name)
|
159
184
|
output_config_file_name = File.join(output_config_dir, component_proper_name)
|
160
185
|
|
186
|
+
output_unitTests_dir = get_unitTests_output_dir(component_type, component_proper_name, options[:tests_dir])
|
187
|
+
|
188
|
+
test_component_name= "Test_"+component_proper_name
|
189
|
+
|
190
|
+
output_test_file_name = File.join(output_unitTests_dir, test_component_name)
|
191
|
+
output_test_setup_file_name= File.join(output_unitTests_dir, test_component_name+"_Setup")
|
192
|
+
|
161
193
|
if(options[:dry_run])
|
162
194
|
@logger.unknown "Dry Run, not writing files"
|
163
195
|
show_line()
|
164
|
-
|
165
|
-
|
166
|
-
|
196
|
+
unless options[:only_tests]
|
197
|
+
display_file(output_file_name+".xml", xml_text)
|
198
|
+
display_file(output_file_name+".brs", brs_text)
|
199
|
+
display_file(output_config_file_name+".json", json_text)
|
200
|
+
end
|
201
|
+
|
202
|
+
display_file(output_test_file_name+".xml", test_xml_text)
|
203
|
+
display_file(output_test_file_name+".brs", test_brs_text)
|
204
|
+
display_file(output_test_setup_file_name+".brs", testSetup_brs_text)
|
167
205
|
else
|
168
206
|
@logger.unknown "Writing files"
|
169
207
|
show_line()
|
170
|
-
|
171
|
-
|
172
|
-
|
208
|
+
unless options[:only_tests]
|
209
|
+
FileUtils.mkdir_p output_dir
|
210
|
+
unless json_text.nil?
|
211
|
+
FileUtils.mkdir_p output_config_dir
|
212
|
+
end
|
213
|
+
write_file(output_file_name+".xml", xml_text)
|
214
|
+
write_file(output_file_name+".brs", brs_text)
|
215
|
+
write_file(output_config_file_name+".json", json_text)
|
216
|
+
end
|
217
|
+
unless test_xml_text.nil?
|
218
|
+
FileUtils.mkdir_p output_unitTests_dir
|
173
219
|
end
|
174
|
-
write_file(
|
175
|
-
write_file(
|
176
|
-
write_file(
|
220
|
+
write_file(output_test_file_name+".xml", test_xml_text)
|
221
|
+
write_file(output_test_file_name+".brs", test_brs_text)
|
222
|
+
write_file(output_test_setup_file_name+".brs", testSetup_brs_text)
|
177
223
|
end
|
178
224
|
end
|
179
225
|
|
@@ -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,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>
|
@@ -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_Config_Exists()
|
15
|
+
config = getGlobalAA().channelConfig
|
16
|
+
top = getGlobalAA().top
|
17
|
+
|
18
|
+
m.assertNotInvalid(config)
|
19
|
+
return m.assertNotInvalid(top)
|
20
|
+
end function
|
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.1
|
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-29 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.xml.erb
|
63
|
+
- lib/roku_builder_generator/templates/test_Setup.brs.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: []
|