k_builder 0.0.62 → 0.0.70
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/Sample-original.xml +103 -0
- data/Sample.drawio +103 -0
- data/Sample.xml +103 -0
- data/assets/a.html +235 -0
- data/assets/b.html +109 -0
- data/assets/highlight.min.js +1120 -0
- data/assets/highlight_css +1 -0
- data/assets/ruby.min.js +7 -0
- data/hooks/pre-commit +4 -2
- data/k_builder.gemspec +0 -1
- data/lib/k_builder/base_builder.rb +292 -22
- data/lib/k_builder/commands/code_syntax_highlighter_command.rb +71 -0
- data/lib/k_builder/commands/rubo_cop_command.rb +1 -1
- data/lib/k_builder/configuration.rb +22 -12
- data/lib/k_builder/version.rb +1 -1
- data/lib/k_builder.rb +4 -0
- metadata +12 -4
- data/~/last_cop.txt +0 -19
@@ -0,0 +1 @@
|
|
1
|
+
/Users/davidcruwys/dev/slides-addons/highlight_css
|
data/assets/ruby.min.js
ADDED
data/hooks/pre-commit
CHANGED
@@ -8,8 +8,8 @@ require 'English'
|
|
8
8
|
|
9
9
|
exit 0 if ARGV.include?('--no-verify')
|
10
10
|
|
11
|
-
warning_keywords = %w[
|
12
|
-
keywords = %w[binding.pry console.dir byebug
|
11
|
+
warning_keywords = %w[]
|
12
|
+
keywords = %w[binding.pry console.dir byebug]
|
13
13
|
files_changed = `git diff-index --name-only HEAD --`.split
|
14
14
|
|
15
15
|
# puts '----------------------------------------------------------------------'
|
@@ -23,6 +23,8 @@ files_changed -= ['Gemfile']
|
|
23
23
|
files_changed -= ['Gemfile.lock']
|
24
24
|
files_changed -= ['.gitignore']
|
25
25
|
files_changed -= ['README.md']
|
26
|
+
files_changed -= ['lib/k_builder/assets/highlight.min.js']
|
27
|
+
files_changed -= ['spec/k_builder/base_builder_spec.rb']
|
26
28
|
|
27
29
|
files_changed = files_changed.reject { |f| f.downcase.end_with?('.json') }
|
28
30
|
files_changed = files_changed.reject { |f| f.downcase.end_with?('.yml') }
|
data/k_builder.gemspec
CHANGED
@@ -37,7 +37,6 @@ Gem::Specification.new do |spec|
|
|
37
37
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
38
38
|
spec.require_paths = ['lib']
|
39
39
|
# spec.extensions = ['ext/k_builder/extconf.rb']
|
40
|
-
|
41
40
|
spec.add_dependency 'handlebars-helpers', '~> 0'
|
42
41
|
spec.add_dependency 'k_log', '~> 0'
|
43
42
|
spec.add_dependency 'k_type', '~> 0'
|
@@ -1,21 +1,38 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module KBuilder
|
4
|
+
# TODO: Why is this called BaseBuilder, why not just builder
|
5
|
+
# TODO: Is this really the builder pattern, it could be the class used by a director
|
6
|
+
# but it is not really storing information for builder purposes.
|
7
|
+
#
|
4
8
|
# Base builder defines builder methods, build method and configuration
|
5
9
|
#
|
6
10
|
# Convention: Setter methods (are Fluent) and use the prefix set_
|
7
11
|
# Getter methods (are NOT fluent) and return the stored value
|
8
12
|
# Setter methods (are NOT fluent) can be created as needed
|
9
13
|
# these methods would not be prefixed with the set_
|
14
|
+
|
15
|
+
# process_any_content(content: 'abc')
|
16
|
+
# process_any_content(content_file: 'abc.txt')
|
17
|
+
# process_any_content(template: 'abc {{name}}', name: 'sean')
|
18
|
+
# process_any_content(template_file: 'abc.txt', name: 'sean')
|
19
|
+
|
20
|
+
# process_any_content(content_gist: 'https://gist.github.com/klueless-io/8d4b6d199dbe4a5d40807a47fff8ed1c')
|
21
|
+
# process_any_content(template_gist: 'https://gist.github.com/klueless-io/8d4b6d199dbe4a5d40807a47fff8ed1c', name: 'sean')
|
22
|
+
|
10
23
|
class BaseBuilder
|
11
24
|
include KLog::Logging
|
12
25
|
|
13
26
|
attr_reader :configuration
|
14
27
|
|
15
28
|
attr_accessor :target_folders
|
16
|
-
|
17
29
|
attr_accessor :template_folders
|
18
30
|
|
31
|
+
attr_accessor :last_output_file
|
32
|
+
attr_accessor :last_output_folder
|
33
|
+
# attr_accessor :last_template
|
34
|
+
attr_accessor :last_template_file
|
35
|
+
|
19
36
|
# Factory method that provides a builder for a specified structure
|
20
37
|
# runs through a configuration block and then builds the final structure
|
21
38
|
#
|
@@ -59,6 +76,7 @@ module KBuilder
|
|
59
76
|
}
|
60
77
|
end
|
61
78
|
|
79
|
+
# rubocop:disable Metrics/AbcSize
|
62
80
|
def debug
|
63
81
|
log.subheading 'kbuilder'
|
64
82
|
|
@@ -69,8 +87,16 @@ module KBuilder
|
|
69
87
|
log.info ''
|
70
88
|
|
71
89
|
template_folders.debug(title: 'template folders (search order)')
|
90
|
+
|
91
|
+
log.info ''
|
92
|
+
log.kv 'last output file' , last_output_file
|
93
|
+
log.kv 'last output folder' , last_output_folder
|
94
|
+
# log.kv 'last template' , last_template
|
95
|
+
log.kv 'last template file' , last_template_file
|
96
|
+
|
72
97
|
''
|
73
98
|
end
|
99
|
+
# rubocop:enable Metrics/AbcSize
|
74
100
|
|
75
101
|
# ----------------------------------------------------------------------
|
76
102
|
# Fluent interface
|
@@ -95,31 +121,116 @@ module KBuilder
|
|
95
121
|
# Extra options will be used as data for templates, e.g
|
96
122
|
# @option opts [String] :to Recipient email
|
97
123
|
# @option opts [String] :body The email's body
|
124
|
+
def add_file_action(file, **opts)
|
125
|
+
{
|
126
|
+
action: :add_file,
|
127
|
+
played: false,
|
128
|
+
file: file,
|
129
|
+
opts: opts
|
130
|
+
}
|
131
|
+
end
|
132
|
+
|
133
|
+
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
|
98
134
|
def add_file(file, **opts)
|
99
135
|
# move to command
|
100
|
-
full_file = opts.key?(:folder_key) ? target_file(file, folder: opts[:folder_key]) : target_file(file)
|
136
|
+
full_file = target_file(file, **opts) # opts.key?(:folder_key) || opts.key?(:folder) ? target_file(file, folder: opts[:folder], folder_key: opts[:folder_key]) : target_file(file)
|
101
137
|
|
102
138
|
# Need logging options that can log these internal details
|
103
|
-
|
139
|
+
mkdir_p(File.dirname(full_file))
|
104
140
|
|
105
141
|
content = process_any_content(**opts)
|
106
142
|
|
107
|
-
|
143
|
+
file_write(full_file, content, on_exist: opts[:on_exist])
|
108
144
|
|
109
145
|
# Prettier needs to work with the original file name
|
110
|
-
run_prettier file
|
146
|
+
run_prettier file if opts.key?(:pretty)
|
147
|
+
# TODO: Add test
|
148
|
+
run_cop(full_file, fix_safe: true) if opts.key?(:cop) || opts.key?(:ruby_cop)
|
149
|
+
# TODO: Add test
|
150
|
+
run_command(file) if opts.key?(:run)
|
151
|
+
|
111
152
|
# Need support for rubocop -a
|
153
|
+
open_file(last_output_file) if opts.key?(:open)
|
154
|
+
open_file(last_template_file) if opts.key?(:open_template)
|
155
|
+
browse_file(last_output_file) if opts.key?(:browse)
|
156
|
+
pause(opts[:pause]) if opts[:pause]
|
112
157
|
|
113
158
|
self
|
114
159
|
end
|
160
|
+
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity
|
161
|
+
|
162
|
+
def play_actions(actions)
|
163
|
+
actions.reject { |action| action[:played] }.each do |action|
|
164
|
+
play_action(action)
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
def play_action(action)
|
169
|
+
run_action(action)
|
170
|
+
action[:played] = true
|
171
|
+
end
|
172
|
+
|
173
|
+
# certain actions (e.g. set_current_folder) will run independently to play
|
174
|
+
def run_action(action)
|
175
|
+
case action[:action]
|
176
|
+
when :add_file
|
177
|
+
add_file(action[:file], action[:opts])
|
178
|
+
when :delete_file
|
179
|
+
delete_file(action[:file], action[:opts])
|
180
|
+
when :vscode
|
181
|
+
vscode(action[:file_parts], action[:opts])
|
182
|
+
when :browse
|
183
|
+
browse(action[:file_parts], action[:opts])
|
184
|
+
when :set_current_folder
|
185
|
+
set_current_folder(action[:folder_key])
|
186
|
+
when :run_command
|
187
|
+
run_command(action[:command])
|
188
|
+
when :run_script
|
189
|
+
run_script(action[:script])
|
190
|
+
else
|
191
|
+
log.error "Unknown action: #{action[:action]}"
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
115
195
|
alias touch add_file # it is expected that you would not supply any options, just a file name
|
116
196
|
|
197
|
+
def delete_file_action(file, **opts)
|
198
|
+
{
|
199
|
+
action: :delete_file,
|
200
|
+
played: false,
|
201
|
+
file: file,
|
202
|
+
opts: opts
|
203
|
+
}
|
204
|
+
end
|
205
|
+
|
206
|
+
def delete_file(file, **opts)
|
207
|
+
full_file = target_file(file, **opts) # = opts.key?(:folder_key) ? target_file(file, folder: opts[:folder_key]) : target_file(file)
|
208
|
+
|
209
|
+
File.delete(full_file) if File.exist?(full_file)
|
210
|
+
|
211
|
+
self
|
212
|
+
end
|
213
|
+
|
214
|
+
def file_exist?(file, **opts)
|
215
|
+
# full_file = opts.key?(:folder_key) ? target_file(file, folder_key: opts[:folder_key]) : target_file(file)
|
216
|
+
full_file = target_file(file, **opts)
|
217
|
+
|
218
|
+
File.exist?(full_file)
|
219
|
+
end
|
220
|
+
|
221
|
+
# ToDo
|
222
|
+
# def delete_folder(file)
|
223
|
+
# FileUtils.remove_dir(path_to_directory) if File.directory?(path_to_directory)
|
224
|
+
|
225
|
+
# self
|
226
|
+
# end
|
227
|
+
|
117
228
|
def make_folder(folder_key = nil, sub_path: nil)
|
118
229
|
folder_key = current_folder_key if folder_key.nil?
|
119
230
|
folder = target_folder(folder_key)
|
120
231
|
folder = File.join(folder, sub_path) unless sub_path.nil?
|
121
232
|
|
122
|
-
|
233
|
+
mkdir_p(folder)
|
123
234
|
|
124
235
|
self
|
125
236
|
end
|
@@ -140,6 +251,8 @@ module KBuilder
|
|
140
251
|
|
141
252
|
begin
|
142
253
|
IO.popen('pbcopy', 'w') { |f| f << content }
|
254
|
+
|
255
|
+
open_file(last_template_file) if opts.key?(:open_template)
|
143
256
|
rescue Errno::ENOENT => e
|
144
257
|
if e.message == 'No such file or directory - pbcopy'
|
145
258
|
# May want to use this GEM in the future
|
@@ -152,15 +265,84 @@ module KBuilder
|
|
152
265
|
end
|
153
266
|
alias clipboard_copy add_clipboard
|
154
267
|
|
155
|
-
def
|
268
|
+
def vscode_action(*file_parts, folder_key: current_folder_key, file: nil)
|
269
|
+
{
|
270
|
+
action: :vscode,
|
271
|
+
played: false,
|
272
|
+
file_parts: file_parts,
|
273
|
+
opts: { folder_key: folder_key, file: file }
|
274
|
+
}
|
275
|
+
end
|
276
|
+
|
277
|
+
def vscode(*file_parts, folder_key: current_folder_key, file: nil)
|
156
278
|
# move to command
|
157
|
-
file = target_file(*file_parts,
|
279
|
+
file = target_file(*file_parts, folder_key: folder_key) if file.nil?
|
158
280
|
|
159
281
|
rc "code #{file}"
|
160
282
|
|
161
283
|
self
|
162
284
|
end
|
163
285
|
|
286
|
+
def browse_action(*file_parts, folder_key: current_folder_key, file: nil)
|
287
|
+
{
|
288
|
+
action: :browse,
|
289
|
+
played: false,
|
290
|
+
file_parts: file_parts,
|
291
|
+
opts: { folder_key: folder_key, file: file }
|
292
|
+
}
|
293
|
+
end
|
294
|
+
|
295
|
+
def browse(*file_parts, folder_key: current_folder_key, file: nil)
|
296
|
+
# move to command
|
297
|
+
file = target_file(*file_parts, folder_key: folder_key) if file.nil?
|
298
|
+
|
299
|
+
rc "open -a \"Google Chrome\" #{file}"
|
300
|
+
|
301
|
+
self
|
302
|
+
end
|
303
|
+
|
304
|
+
def open
|
305
|
+
open_file(last_output_file)
|
306
|
+
|
307
|
+
self
|
308
|
+
end
|
309
|
+
alias o open
|
310
|
+
|
311
|
+
def open_template
|
312
|
+
open_file(last_template_file)
|
313
|
+
|
314
|
+
self
|
315
|
+
end
|
316
|
+
alias ot open_template
|
317
|
+
|
318
|
+
def open_file(file)
|
319
|
+
if file.nil?
|
320
|
+
log.warn('open_file will not open when file is nil')
|
321
|
+
return self
|
322
|
+
end
|
323
|
+
|
324
|
+
vscode(file: file)
|
325
|
+
|
326
|
+
self
|
327
|
+
end
|
328
|
+
|
329
|
+
def browse_file(file)
|
330
|
+
if file.nil?
|
331
|
+
log.warn('browse_file will not browse when file is nil')
|
332
|
+
return self
|
333
|
+
end
|
334
|
+
|
335
|
+
browse(file: file)
|
336
|
+
|
337
|
+
self
|
338
|
+
end
|
339
|
+
|
340
|
+
def pause(seconds = 1)
|
341
|
+
sleep(seconds)
|
342
|
+
|
343
|
+
self
|
344
|
+
end
|
345
|
+
|
164
346
|
# ----------------------------------------------------------------------
|
165
347
|
# Attributes: Think getter/setter
|
166
348
|
#
|
@@ -174,6 +356,14 @@ module KBuilder
|
|
174
356
|
# Target folders and files
|
175
357
|
# ----------------------------------------------------------------------
|
176
358
|
|
359
|
+
def set_current_folder_action(folder_key)
|
360
|
+
{
|
361
|
+
action: :set_current_folder,
|
362
|
+
played: false,
|
363
|
+
folder_key: folder_key
|
364
|
+
}
|
365
|
+
end
|
366
|
+
|
177
367
|
def set_current_folder(folder_key)
|
178
368
|
target_folders.current = folder_key
|
179
369
|
|
@@ -216,12 +406,18 @@ module KBuilder
|
|
216
406
|
# target_file('/abc.txt')
|
217
407
|
# target_file('/xyz/abc.txt')
|
218
408
|
# target_file('/xyz', 'abc.txt')
|
219
|
-
def target_file(*file_parts, folder:
|
409
|
+
def target_file(*file_parts, folder_key: current_folder_key, folder: nil, **)
|
410
|
+
# TODO: Mismatch (sometimes called folder, sometimes called folder_key:)
|
411
|
+
if folder
|
412
|
+
log.error("Change folder: to folder_key: for #{folder} - #{file_parts}")
|
413
|
+
return
|
414
|
+
end
|
415
|
+
|
220
416
|
# Absolute path
|
221
417
|
return File.join(*file_parts) if Pathname.new(file_parts.first).absolute?
|
222
418
|
|
223
|
-
# Relative to :
|
224
|
-
File.join(target_folder(
|
419
|
+
# Relative to :folder_key
|
420
|
+
File.join(target_folder(folder_key), *file_parts)
|
225
421
|
end
|
226
422
|
|
227
423
|
# Template folder & Files
|
@@ -242,7 +438,8 @@ module KBuilder
|
|
242
438
|
# Gets a template_file relative to the template folder, looks first in
|
243
439
|
# local template folder and if not found, looks in global template folder
|
244
440
|
def find_template_file(file_parts)
|
245
|
-
template_folders.find_file(file_parts)
|
441
|
+
self.last_template_file = template_folders.find_file(file_parts)
|
442
|
+
last_template_file
|
246
443
|
end
|
247
444
|
|
248
445
|
# Building content from templates
|
@@ -268,15 +465,6 @@ module KBuilder
|
|
268
465
|
|
269
466
|
return "content not found: #{opts[:content_file]}" if cf.nil?
|
270
467
|
|
271
|
-
# cf = opts[:content_file]
|
272
|
-
|
273
|
-
# unless File.exist?(cf)
|
274
|
-
# cf_from_template_folders = find_template_file(cf)
|
275
|
-
# return "Content not found: #{File.expand_path(cf)}" unless File.exist?(cf_from_template_folders)
|
276
|
-
|
277
|
-
# cf = cf_from_template_folders
|
278
|
-
# end
|
279
|
-
|
280
468
|
File.read(cf)
|
281
469
|
end
|
282
470
|
|
@@ -340,7 +528,7 @@ module KBuilder
|
|
340
528
|
# Deep path create if needed
|
341
529
|
tf = target_folder
|
342
530
|
|
343
|
-
|
531
|
+
mkdir_p(tf)
|
344
532
|
|
345
533
|
build_command = "cd #{tf} && #{command}"
|
346
534
|
|
@@ -349,7 +537,89 @@ module KBuilder
|
|
349
537
|
# need to support the fork process options as I was not able to run
|
350
538
|
# k_builder_watch -n because it hid all the following output
|
351
539
|
system(build_command)
|
540
|
+
|
541
|
+
# FROM k_dsl
|
542
|
+
# system "/usr/local/bin/zsh #{output_file}" if execution_context == :system
|
543
|
+
# fork { exec("/usr/local/bin/zsh #{output_file}") } if execution_context == :fork
|
544
|
+
|
352
545
|
end
|
353
546
|
alias rc run_command
|
547
|
+
|
548
|
+
def run_command_action(command)
|
549
|
+
{
|
550
|
+
action: :run_command,
|
551
|
+
played: false,
|
552
|
+
command: command
|
553
|
+
}
|
554
|
+
end
|
555
|
+
|
556
|
+
# NOT TESTED, and not working with opts, this code needs rewrite
|
557
|
+
def run_script(script)
|
558
|
+
# Deep path create if needed
|
559
|
+
tf = target_folder
|
560
|
+
|
561
|
+
mkdir_p(tf)
|
562
|
+
|
563
|
+
Dir.chdir(tf) do
|
564
|
+
output, status = Open3.capture2(script) # , **opts)
|
565
|
+
|
566
|
+
unless status.success?
|
567
|
+
log.error("Script failed")
|
568
|
+
puts script
|
569
|
+
return nil
|
570
|
+
end
|
571
|
+
|
572
|
+
return output
|
573
|
+
end
|
574
|
+
end
|
575
|
+
|
576
|
+
def run_script_action(script)
|
577
|
+
{
|
578
|
+
action: :run_script,
|
579
|
+
played: false,
|
580
|
+
script: script
|
581
|
+
}
|
582
|
+
end
|
583
|
+
|
584
|
+
def file_write(file, content, on_exist: :skip)
|
585
|
+
self.last_output_file = file # if file not found, we still want to record this as the last_output_file
|
586
|
+
|
587
|
+
not_found = !File.exist?(file)
|
588
|
+
|
589
|
+
if not_found
|
590
|
+
File.write(file, content)
|
591
|
+
return
|
592
|
+
end
|
593
|
+
|
594
|
+
return if %i[skip ignore].include?(on_exist)
|
595
|
+
|
596
|
+
if %i[overwrite write].include?(on_exist)
|
597
|
+
File.write(file, content)
|
598
|
+
return
|
599
|
+
end
|
600
|
+
|
601
|
+
return unless on_exist == :compare
|
602
|
+
|
603
|
+
vscompare(file, content)
|
604
|
+
end
|
605
|
+
|
606
|
+
def vscompare(file, content)
|
607
|
+
# need to use some sort of caching folder for this
|
608
|
+
ext = File.extname(file)
|
609
|
+
fn = File.basename(file, ext)
|
610
|
+
temp_file = Tempfile.new([fn, ext])
|
611
|
+
|
612
|
+
temp_file.write(content)
|
613
|
+
temp_file.close
|
614
|
+
|
615
|
+
return if File.read(file) == content
|
616
|
+
|
617
|
+
system("code -d #{file} #{temp_file.path}")
|
618
|
+
sleep 2
|
619
|
+
end
|
620
|
+
|
621
|
+
def mkdir_p(folder)
|
622
|
+
@last_output_folder = FileUtils.mkdir_p(folder).first
|
623
|
+
end
|
354
624
|
end
|
355
625
|
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module KBuilder
|
4
|
+
module Commands
|
5
|
+
# Run CodeSyntaxHighlighter against source code and produce a styled HTML representation
|
6
|
+
#
|
7
|
+
# Alternatives to Highlighter-js could be carbon-now and ray.so
|
8
|
+
class CodeSyntaxHighlighterCommand < BaseCommand
|
9
|
+
attr_reader :source_code
|
10
|
+
attr_reader :formatted_code
|
11
|
+
|
12
|
+
def initialize(source_code, **opts)
|
13
|
+
super(**opts)
|
14
|
+
|
15
|
+
self.source_code = source_code
|
16
|
+
end
|
17
|
+
|
18
|
+
def execute
|
19
|
+
return unless valid?
|
20
|
+
|
21
|
+
run
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def source_code=(value)
|
27
|
+
@source_code = value
|
28
|
+
|
29
|
+
guard('Source code is required for formatting') if value.nil? || value.empty?
|
30
|
+
end
|
31
|
+
|
32
|
+
def run
|
33
|
+
# @formatted_code = ExecJS.eval("'red yellow blue'.split(' ')")
|
34
|
+
|
35
|
+
# # highlight_source = 'lib/k_builder/assets/a.js'
|
36
|
+
# highlight_source = 'lib/k_builder/assets/highlight.min.js'
|
37
|
+
|
38
|
+
# log.error ExecJS.runtime.name
|
39
|
+
|
40
|
+
# a = File.read(highlight_source)
|
41
|
+
# # context = ExecJS.compile(a)
|
42
|
+
# context = ExecJS.compile(highlight_source)
|
43
|
+
# context.call("html = hljs.highlightAuto('<h1>Hello World!</h1>').value")
|
44
|
+
|
45
|
+
# get_js_asset('highlight')
|
46
|
+
# get_js_asset('ruby')
|
47
|
+
end
|
48
|
+
|
49
|
+
# https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.0.1/highlight.min.js
|
50
|
+
# https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.0.1/languages/ruby.min.js
|
51
|
+
|
52
|
+
def get_js_asset(name)
|
53
|
+
url = "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.0.1/#{name}.min.js"
|
54
|
+
target_folder = 'lib/k_builder/assets'
|
55
|
+
file = "#{name}.min.js"
|
56
|
+
|
57
|
+
get_asset(url, target_folder, file)
|
58
|
+
end
|
59
|
+
|
60
|
+
def get_asset(url, target_folder, file)
|
61
|
+
local_asset_file = File.join(target_folder, file)
|
62
|
+
|
63
|
+
return if File.exist?(local_asset_file)
|
64
|
+
|
65
|
+
content = Net::HTTP.get(URI.parse(url))
|
66
|
+
|
67
|
+
File.write(local_asset_file, content)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -55,7 +55,7 @@ module KBuilder
|
|
55
55
|
cli_options << '-a' if fix_safe
|
56
56
|
cli_options << '-A' if fix_unsafe
|
57
57
|
cli_options << '--config' << rubo_config_file if rubo_config_file
|
58
|
-
cli_options << '--out' << '~/last_cop.txt' unless show_console
|
58
|
+
cli_options << '--out' << File.expand_path('~/last_cop.txt') unless show_console
|
59
59
|
cli_options << file_pattern
|
60
60
|
cli_options
|
61
61
|
end
|
@@ -5,18 +5,24 @@ module KBuilder
|
|
5
5
|
# Configuration for webpack5/builder
|
6
6
|
class << self
|
7
7
|
attr_writer :configuration
|
8
|
-
end
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
def configuration(name = :default)
|
10
|
+
@configuration ||= Hash.new do |h, key|
|
11
|
+
h[key] = KBuilder::Configuration.new
|
12
|
+
end
|
13
|
+
@configuration[name]
|
14
|
+
end
|
13
15
|
|
14
|
-
|
15
|
-
|
16
|
-
|
16
|
+
def reset(name = :default)
|
17
|
+
@configuration ||= Hash.new do |h, key|
|
18
|
+
h[key] = KBuilder::Configuration.new
|
19
|
+
end
|
20
|
+
@configuration[name] = KBuilder::Configuration.new
|
21
|
+
end
|
17
22
|
|
18
|
-
|
19
|
-
|
23
|
+
def configure(name = :default)
|
24
|
+
yield(configuration(name))
|
25
|
+
end
|
20
26
|
end
|
21
27
|
|
22
28
|
# Does this class need to move out into k_types?
|
@@ -48,12 +54,16 @@ module KBuilder
|
|
48
54
|
@template_folders = orig.template_folders.clone
|
49
55
|
end
|
50
56
|
|
51
|
-
def debug
|
52
|
-
log.
|
57
|
+
def debug(heading: 'kbuilder base configuration')
|
58
|
+
log.section_heading 'kbuilder base configuration' if heading
|
59
|
+
|
60
|
+
# TODO: Add name to configuration object
|
61
|
+
# Don't have support for name on the configuration object yet
|
62
|
+
# log.kv 'config name', name
|
53
63
|
|
54
64
|
target_folders.debug(title: 'target_folders')
|
55
65
|
|
56
|
-
log.info ''
|
66
|
+
# log.info ''
|
57
67
|
|
58
68
|
template_folders.debug(title: 'template folders (search order)')
|
59
69
|
''
|
data/lib/k_builder/version.rb
CHANGED
data/lib/k_builder.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'rubocop'
|
4
|
+
require "open3"
|
4
5
|
|
5
6
|
require 'k_log'
|
6
7
|
require 'k_util'
|
@@ -10,8 +11,11 @@ require 'k_builder/base_builder'
|
|
10
11
|
require 'k_builder/base_configuration'
|
11
12
|
require 'k_builder/configuration'
|
12
13
|
require 'k_builder/file_segments'
|
14
|
+
|
15
|
+
# should commands be in their own gem?
|
13
16
|
require 'k_builder/commands/base_command'
|
14
17
|
require 'k_builder/commands/rubo_cop_command'
|
18
|
+
require 'k_builder/commands/code_syntax_highlighter_command'
|
15
19
|
|
16
20
|
require 'handlebars/helpers/template'
|
17
21
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: k_builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.70
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Cruwys
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: handlebars-helpers
|
@@ -99,7 +99,15 @@ files:
|
|
99
99
|
- README.md
|
100
100
|
- Rakefile
|
101
101
|
- STORIES.md
|
102
|
+
- Sample-original.xml
|
103
|
+
- Sample.drawio
|
104
|
+
- Sample.xml
|
102
105
|
- USAGE.md
|
106
|
+
- assets/a.html
|
107
|
+
- assets/b.html
|
108
|
+
- assets/highlight.min.js
|
109
|
+
- assets/highlight_css
|
110
|
+
- assets/ruby.min.js
|
103
111
|
- bin/console
|
104
112
|
- bin/k
|
105
113
|
- bin/kgitsync
|
@@ -112,6 +120,7 @@ files:
|
|
112
120
|
- lib/k_builder/base_builder.rb
|
113
121
|
- lib/k_builder/base_configuration.rb
|
114
122
|
- lib/k_builder/commands/base_command.rb
|
123
|
+
- lib/k_builder/commands/code_syntax_highlighter_command.rb
|
115
124
|
- lib/k_builder/commands/rubo_cop_command.rb
|
116
125
|
- lib/k_builder/configuration.rb
|
117
126
|
- lib/k_builder/file_segments.rb
|
@@ -123,7 +132,6 @@ files:
|
|
123
132
|
- usage/_out5.png
|
124
133
|
- usage/_usage_folder_after.png
|
125
134
|
- usage/_usage_folder_before.png
|
126
|
-
- "~/last_cop.txt"
|
127
135
|
homepage: http://appydave.com
|
128
136
|
licenses:
|
129
137
|
- MIT
|
@@ -146,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
146
154
|
- !ruby/object:Gem::Version
|
147
155
|
version: '0'
|
148
156
|
requirements: []
|
149
|
-
rubygems_version: 3.2.
|
157
|
+
rubygems_version: 3.2.33
|
150
158
|
signing_key:
|
151
159
|
specification_version: 4
|
152
160
|
summary: K Builder provides various fluent builders for initializing applications
|