app_archetype 1.5.0 → 1.5.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: be0d0a9624d6408fce0b1b397a87dcdb1498fcce7f087106bcf89bf170dcd501
4
- data.tar.gz: 01220c7659a2d799f79ab847a69751e1e928e41f0c280998cbfe51436c53bc85
3
+ metadata.gz: a4960f16cbaf3034a7facdbebc02ff0b0df95819b8f9fa36f74d663112e1d74f
4
+ data.tar.gz: ab95112f6710e036ac76f95e6656b49dd47c0502331587513ba9dc4bdb894dd6
5
5
  SHA512:
6
- metadata.gz: 50252b085dea58b00217c4a9e8d553564d0bc7bfddd12f8061344b91f75fb62a83388a191a4eff278e41de39c895133794d59cc6ba9d8f7f1adb46b165c9f1fc
7
- data.tar.gz: a67a216ec48665fcbf23a24e3a882ef2219b4cb170f50842cd976b88bbfabdb582980532a2be614e483238752d83111c8c88e4b4070a7433957069c8e500f6ef
6
+ metadata.gz: '093ab09ba553ef8329890ae26e7b048fdb0d2296223796269282b48ec71d103a4b0f353556211304d53ba6a74984aeb1bab4d175af6fa1178f391378529472ff'
7
+ data.tar.gz: 8e399efb92ef27a6a4a9a24455b8fc0d50517b1ac8b7ac96eb3401b80fcd37abdd6461d82c9c9a5420481a514c092fdd9c32bae71635a8ad2939117d76524da3
data/.rubocop.yml CHANGED
@@ -16,9 +16,21 @@
16
16
 
17
17
  Metrics/MethodLength:
18
18
  Max: 20
19
+ Exclude:
20
+ - 'lib/app_archetype/renderer.rb'
19
21
 
20
22
  Metrics/AbcSize:
21
23
  Max: 20
24
+ Exclude:
25
+ - 'lib/app_archetype/renderer.rb'
26
+
27
+ Metrics/CyclomaticComplexity:
28
+ Exclude:
29
+ - 'lib/app_archetype/renderer.rb'
30
+
31
+ Metrics/PerceivedComplexity:
32
+ Exclude:
33
+ - 'lib/app_archetype/renderer.rb'
22
34
 
23
35
  Lint/AssignmentInCondition:
24
36
  Enabled: false
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- app_archetype (1.5.0)
4
+ app_archetype (1.5.2)
5
5
  cli-format
6
6
  hashie
7
7
  highline
@@ -19,7 +19,7 @@ PATH
19
19
  GEM
20
20
  remote: https://rubygems.org/
21
21
  specs:
22
- activesupport (6.1.6)
22
+ activesupport (6.1.7.6)
23
23
  concurrent-ruby (~> 1.0, >= 1.0.2)
24
24
  i18n (>= 1.6, < 2)
25
25
  minitest (>= 5.1)
@@ -33,14 +33,14 @@ GEM
33
33
  ice_nine (~> 0.11.0)
34
34
  thread_safe (~> 0.3, >= 0.3.1)
35
35
  bump (0.10.0)
36
- cli-format (0.2.2)
36
+ cli-format (0.5.0)
37
37
  activesupport
38
38
  text-table
39
39
  zeitwerk
40
40
  coderay (1.1.3)
41
41
  coercible (1.0.0)
42
42
  descendants_tracker (~> 0.0.1)
43
- concurrent-ruby (1.1.10)
43
+ concurrent-ruby (1.2.2)
44
44
  descendants_tracker (0.0.4)
45
45
  thread_safe (~> 0.3, >= 0.3.1)
46
46
  diff-lcs (1.5.0)
@@ -57,24 +57,24 @@ GEM
57
57
  ruby_parser (~> 3.1, > 3.1.0)
58
58
  sexp_processor (~> 4.8)
59
59
  hashie (5.0.0)
60
- highline (2.0.3)
61
- i18n (1.10.0)
60
+ highline (2.1.0)
61
+ i18n (1.14.1)
62
62
  concurrent-ruby (~> 1.0)
63
63
  ice_nine (0.11.2)
64
- json (2.6.2)
65
- json-schema (3.0.0)
64
+ json (2.7.1)
65
+ json-schema (4.1.1)
66
66
  addressable (>= 2.8)
67
- jsonnet (0.4.0)
67
+ jsonnet (0.5.3)
68
68
  mini_portile2 (>= 2.2.0)
69
69
  kwalify (0.7.2)
70
70
  launchy (2.5.0)
71
71
  addressable (~> 2.7)
72
- logger (1.5.1)
72
+ logger (1.6.0)
73
73
  method_source (1.0.0)
74
- mini_portile2 (2.8.0)
75
- minitest (5.16.1)
74
+ mini_portile2 (2.8.5)
75
+ minitest (5.20.0)
76
76
  os (1.1.4)
77
- ostruct (0.5.5)
77
+ ostruct (0.6.0)
78
78
  parallel (1.21.0)
79
79
  parser (3.1.0.0)
80
80
  ast (~> 2.4.1)
@@ -161,13 +161,13 @@ GEM
161
161
  tty-cursor (~> 0.7)
162
162
  tty-screen (~> 0.8)
163
163
  wisper (~> 2.0)
164
- tty-screen (0.8.1)
164
+ tty-screen (0.8.2)
165
165
  tty-table (0.12.0)
166
166
  pastel (~> 0.8)
167
167
  strings (~> 0.2.0)
168
168
  tty-screen (~> 0.8)
169
169
  tty-which (0.4.2)
170
- tzinfo (2.0.4)
170
+ tzinfo (2.0.6)
171
171
  concurrent-ruby (~> 1.0)
172
172
  unicode-display_width (2.1.0)
173
173
  unicode_utils (1.4.0)
@@ -180,7 +180,7 @@ GEM
180
180
  wisper (2.0.1)
181
181
  yard (0.9.27)
182
182
  webrick (~> 1.7.0)
183
- zeitwerk (2.6.0)
183
+ zeitwerk (2.6.12)
184
184
 
185
185
  PLATFORMS
186
186
  ruby
@@ -44,6 +44,8 @@ module AppArchetype
44
44
  render_erb_file(file)
45
45
  elsif file.source_hbs?
46
46
  render_hbs_file(file)
47
+ elsif file.source_template?
48
+ render_template_file(file)
47
49
  elsif file.source_file?
48
50
  copy_file(file)
49
51
  end
@@ -100,7 +102,27 @@ module AppArchetype
100
102
  end
101
103
 
102
104
  ##
103
- # Copies source file to planned path only ovewriting if permitted by the
105
+ # Copies source file only overwriting if permitted by the
106
+ # renderer.
107
+ #
108
+ # The output file name removes the `.template` suffix. This
109
+ # is for circumstances where the template includes a hbs or erb
110
+ # file that we want to render untouched.
111
+ #
112
+ # @param [AppArchetype::OutputFile] file
113
+ #
114
+ def render_template_file(file)
115
+ raise 'cannot overwrite file' if file.exist? && !@overwrite
116
+
117
+ path = file.path.gsub('.template', '')
118
+
119
+ print_message("RENDER template ->: #{path}")
120
+
121
+ FileUtils.cp(file.source_file_path, path)
122
+ end
123
+
124
+ ##
125
+ # Copies source file to planned path only overwriting if permitted by the
104
126
  # renderer.
105
127
  #
106
128
  # @param [AppArchetype::Template::OutputFile] file
@@ -204,6 +204,24 @@ module AppArchetype
204
204
  def valid?
205
205
  validate.empty?
206
206
  end
207
+
208
+ ##
209
+ # Setter for variables
210
+ #
211
+ # @param [Hash] value
212
+ def variables=(value)
213
+ var_values = {}
214
+
215
+ value.each do |name, value|
216
+ var_values[name] = {
217
+ name: name,
218
+ description: name,
219
+ value: value
220
+ }
221
+ end
222
+
223
+ @variables = AppArchetype::Template::VariableManager.new(var_values)
224
+ end
207
225
  end
208
226
  end
209
227
  end
@@ -149,6 +149,18 @@ module AppArchetype
149
149
  File.extname(@source_file_path) == '.hbs'
150
150
  end
151
151
 
152
+ ##
153
+ # Evaluates whether the source file is a template.
154
+ #
155
+ # This is for cases where one wants to render a hbs or
156
+ # erb file without processing as a template file.
157
+ #
158
+ # @return [Boolean]
159
+ #
160
+ def source_template?
161
+ File.extname(@source_file_path) == '.template'
162
+ end
163
+
152
164
  ##
153
165
  # Evaluates whether the source file is a file as opposed to
154
166
  # being a directory.
@@ -2,5 +2,5 @@ module AppArchetype
2
2
  ##
3
3
  # AppArchetype version
4
4
  #
5
- VERSION = '1.5.0'.freeze
5
+ VERSION = '1.5.2'.freeze
6
6
  end
data/lib/app_archetype.rb CHANGED
@@ -38,12 +38,14 @@ module AppArchetype
38
38
  collection_dir: ENV.fetch('ARCHETYPE_TEMPLATE_DIR'),
39
39
  template_name: '',
40
40
  destination_path: '',
41
- overwrite: false
41
+ overwrite: false,
42
+ variables: nil
42
43
  )
43
44
  manager = AppArchetype::TemplateManager.new(collection_dir)
44
45
  manager.load
45
46
 
46
47
  manifest = manager.find_by_name(template_name)
48
+ manifest.variables = variables unless variables.nil?
47
49
 
48
50
  template = manifest.template
49
51
  template.load
@@ -47,6 +47,13 @@ RSpec.describe AppArchetype::Renderer do
47
47
  )
48
48
  end
49
49
 
50
+ let(:template) do
51
+ AppArchetype::Template::OutputFile.new(
52
+ 'path/to/template.hbs.template',
53
+ 'path/to/destination/template'
54
+ )
55
+ end
56
+
50
57
  let(:directory) do
51
58
  AppArchetype::Template::OutputFile.new(
52
59
  'path/to/source/dir',
@@ -60,6 +67,7 @@ RSpec.describe AppArchetype::Renderer do
60
67
  allow(subject).to receive(:write_dir)
61
68
  allow(subject).to receive(:render_erb_file)
62
69
  allow(subject).to receive(:render_hbs_file)
70
+ allow(subject).to receive(:render_template_file)
63
71
  allow(subject).to receive(:copy_file)
64
72
 
65
73
  allow(File).to receive(:new).and_return(file_double)
@@ -67,11 +75,12 @@ RSpec.describe AppArchetype::Renderer do
67
75
  allow(file).to receive(:source_file?).and_return(true)
68
76
  allow(erb_template).to receive(:source_erb?).and_return(true)
69
77
  allow(hbs_template).to receive(:source_hbs?).and_return(true)
78
+ allow(template).to receive(:source_template?).and_return(true)
70
79
  allow(directory).to receive(:source_directory?).and_return(true)
71
80
 
72
81
  plan.instance_variable_set(
73
82
  :@files,
74
- [file, erb_template, hbs_template, directory]
83
+ [file, erb_template, hbs_template, template, directory]
75
84
  )
76
85
 
77
86
  subject.render
@@ -93,6 +102,10 @@ RSpec.describe AppArchetype::Renderer do
93
102
  expect(subject).to have_received(:render_hbs_file).with(hbs_template)
94
103
  end
95
104
 
105
+ it 'renders template' do
106
+ expect(subject).to have_received(:render_template_file).with(template)
107
+ end
108
+
96
109
  it 'copies file' do
97
110
  expect(subject).to have_received(:copy_file).with(file)
98
111
  end
@@ -247,6 +260,48 @@ RSpec.describe AppArchetype::Renderer do
247
260
  end
248
261
  end
249
262
 
263
+ describe '#render_template_file' do
264
+ let(:source_path) { 'path/to/template/file.hbs.template' }
265
+ let(:dest_path) { 'path/to/destination/file' }
266
+
267
+ let(:file) do
268
+ AppArchetype::Template::OutputFile.new(source_path, dest_path)
269
+ end
270
+
271
+ let(:exists) { false }
272
+
273
+ before do
274
+ allow(FileUtils).to receive(:cp)
275
+ allow(file).to receive(:exist?).and_return(exists)
276
+ end
277
+
278
+ it 'copies file' do
279
+ subject.render_template_file(file)
280
+ expect(FileUtils).to have_received(:cp).with(source_path, dest_path)
281
+ end
282
+
283
+ context 'when file already exists and overwrite not allowed' do
284
+ let(:exists) { true }
285
+
286
+ it 'raises error' do
287
+ expect do
288
+ subject.render_template_file(file)
289
+ end.to raise_error('cannot overwrite file')
290
+ end
291
+ end
292
+
293
+ context 'when file already exists and overwrite is allowed' do
294
+ let(:exists) { true }
295
+ let(:overwrite) { true }
296
+
297
+ it 'raises error' do
298
+ expect do
299
+ subject.render_template_file(file)
300
+ end.not_to raise_error
301
+ end
302
+ end
303
+ end
304
+
250
305
  describe '#copy_file' do
251
306
  let(:source_path) { 'path/to/template/file' }
252
307
  let(:dest_path) { 'path/to/destination/file' }
@@ -272,4 +272,30 @@ RSpec.describe AppArchetype::Template::Manifest do
272
272
  end
273
273
  end
274
274
  end
275
+
276
+ describe '#variables=' do
277
+ let(:path) { 'path/to/manifest.json' }
278
+
279
+ let(:data) do
280
+ {
281
+ 'name' => 'test_manifest',
282
+ 'version' => '0.1.0',
283
+ 'variables' => {}
284
+ }
285
+ end
286
+
287
+ let(:vars) do
288
+ {
289
+ 'foo' => 'bar'
290
+ }
291
+ end
292
+
293
+ before do
294
+ subject.variables = vars
295
+ end
296
+
297
+ it 'sets variables from given hash' do
298
+ expect(subject.variables.get('foo').value).to eq 'bar'
299
+ end
300
+ end
275
301
  end
@@ -167,6 +167,31 @@ RSpec.describe AppArchetype::Template::OutputFile do
167
167
  end
168
168
  end
169
169
 
170
+ describe '#source_template?' do
171
+ let(:ext) { '.template' }
172
+
173
+ before do
174
+ allow(File).to receive(:extname).and_return(ext)
175
+ @result = subject.source_template?
176
+ end
177
+
178
+ it 'delegates source file template check to File' do
179
+ expect(File).to have_received(:extname).with(source_file)
180
+ end
181
+
182
+ it 'returns true if file is template' do
183
+ expect(@result).to be true
184
+ end
185
+
186
+ context 'when not template' do
187
+ let(:ext) { 'doc' }
188
+
189
+ it 'returns false' do
190
+ expect(@result).to be false
191
+ end
192
+ end
193
+ end
194
+
170
195
  describe '#source_file?' do
171
196
  before do
172
197
  allow(File).to receive(:file?)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: app_archetype
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Bigger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-27 00:00:00.000000000 Z
11
+ date: 2023-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cli-format