k_builder 0.0.56 → 0.0.61

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 758519925163c21cae5ef6bd99798577d7481f6bff55d6ce51599ee15bdd1baa
4
- data.tar.gz: 89fbffd295334411d71ea48279838e13029ed01e3fa9c5b76be2aea7f1d44c8b
3
+ metadata.gz: c78906798abec61e633a8e6447baed740f5618025e6ec1733655c5173ee62b43
4
+ data.tar.gz: fd412c1aab0fa24ea34c2394c43ae77bba5588d4d25c50e890f1dc4a14f84f7e
5
5
  SHA512:
6
- metadata.gz: a620cc2730bdac7d129de3b7975967d2bea5819213091c7c551a4ed59a480f994617f08fb2649c9aeb46968181f0dea956875c3c6e87d456eacbe29310ab5295
7
- data.tar.gz: 3bd54f3c7e9869fbb232239096ac201a62299b292fffa00cfd3612a7fb7f2b43b9242e86d6821142f1ed4743d7e68cff3d2e10789342dd346a8abb2241b3e9c7
6
+ metadata.gz: bbf46357650901ba2a5af3ba6c9371d6ca4752c281a57f88edcbb9b9264b75fa83afab90d679642dfe0475b4b48d5291fe936f83e70bc61cff193bdc96978105
7
+ data.tar.gz: a41800fce5dfe7297995317eed2441f1bd27d52e3af4def56558dcad53e1390c75cf4a699cd4f9fa2b90b76087d86c011b7204ff14a161be0b490edef09e3de9
data/.rubocop.yml CHANGED
@@ -7,6 +7,7 @@ AllCops:
7
7
  Exclude:
8
8
  - "_/**/*"
9
9
  - "spec/samples/**/*"
10
+ - "bin/*"
10
11
 
11
12
  Metrics/BlockLength:
12
13
  Exclude:
data/bin/k CHANGED
@@ -5,7 +5,7 @@
5
5
  # chmod +x bin/k
6
6
 
7
7
  help = %(
8
- ----------------------------------------------------------------------
8
+ ----------------------------------------------------------------------
9
9
  Klue Scripts - Help
10
10
  ----------------------------------------------------------------------
11
11
  k - This Help File
data/k_builder.gemspec CHANGED
@@ -42,6 +42,8 @@ Gem::Specification.new do |spec|
42
42
  spec.add_dependency 'k_log', '~> 0'
43
43
  spec.add_dependency 'k_type', '~> 0'
44
44
  spec.add_dependency 'k_util', '~> 0'
45
+ spec.add_dependency 'rubocop', '~> 1.8'
46
+
45
47
  # spec.add_dependency "anyway_config" , ">= 2.0.0"
46
48
  # spec.add_dependency "config" , ">= 3.0.0"
47
49
  end
data/lib/k_builder.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'rubocop'
4
+
3
5
  require 'k_log'
4
6
  require 'k_util'
5
7
  require 'k_type'
@@ -20,5 +22,5 @@ if ENV['KLUE_DEBUG']&.to_s&.downcase == 'true'
20
22
  namespace = 'KBuilder::Version'
21
23
  file_path = $LOADED_FEATURES.find { |f| f.include?('k_builder/version') }
22
24
  version = KBuilder::VERSION.ljust(9)
23
- puts "#{namespace.ljust(40)} : #{version.ljust(9)} : #{file_path}"
25
+ puts "#{namespace.ljust(35)} : #{version.ljust(9)} : #{file_path}"
24
26
  end
@@ -8,6 +8,8 @@ module KBuilder
8
8
  # Setter methods (are NOT fluent) can be created as needed
9
9
  # these methods would not be prefixed with the set_
10
10
  class BaseBuilder
11
+ include KLog::Logging
12
+
11
13
  attr_reader :configuration
12
14
 
13
15
  attr_accessor :target_folders
@@ -57,6 +59,19 @@ module KBuilder
57
59
  }
58
60
  end
59
61
 
62
+ def debug
63
+ log.subheading 'kbuilder'
64
+
65
+ log.kv 'current folder key' , current_folder_key
66
+ log.kv 'current folder' , target_folder
67
+ target_folders.debug(title: 'target_folders')
68
+
69
+ log.info ''
70
+
71
+ template_folders.debug(title: 'template folders (search order)')
72
+ ''
73
+ end
74
+
60
75
  # ----------------------------------------------------------------------
61
76
  # Fluent interface
62
77
  # ----------------------------------------------------------------------
@@ -81,6 +96,7 @@ module KBuilder
81
96
  # @option opts [String] :to Recipient email
82
97
  # @option opts [String] :body The email's body
83
98
  def add_file(file, **opts)
99
+ # move to command
84
100
  full_file = opts.key?(:folder_key) ? target_file(file, folder: opts[:folder_key]) : target_file(file)
85
101
 
86
102
  # Need logging options that can log these internal details
@@ -92,11 +108,22 @@ module KBuilder
92
108
 
93
109
  # Prettier needs to work with the original file name
94
110
  run_prettier file if opts.key?(:pretty)
111
+ # Need support for rubocop -a
95
112
 
96
113
  self
97
114
  end
98
115
  alias touch add_file # it is expected that you would not supply any options, just a file name
99
116
 
117
+ def make_folder(folder_key = nil, sub_path: nil)
118
+ folder_key = current_folder_key if folder_key.nil?
119
+ folder = target_folder(folder_key)
120
+ folder = File.join(folder, sub_path) unless sub_path.nil?
121
+
122
+ FileUtils.mkdir_p(folder)
123
+
124
+ self
125
+ end
126
+
100
127
  # Add content to the clipboard
101
128
  #
102
129
  # @option opts [String] :content Supply the content that you want to write to the file
@@ -108,6 +135,7 @@ module KBuilder
108
135
  # @option opts [String] :to Recipient email
109
136
  # @option opts [String] :body The email's body
110
137
  def add_clipboard(**opts)
138
+ # move to command
111
139
  content = process_any_content(**opts)
112
140
 
113
141
  begin
@@ -125,6 +153,7 @@ module KBuilder
125
153
  alias clipboard_copy add_clipboard
126
154
 
127
155
  def vscode(*file_parts, folder: current_folder_key)
156
+ # move to command
128
157
  file = target_file(*file_parts, folder: folder)
129
158
 
130
159
  rc "code #{file}"
@@ -234,9 +263,19 @@ module KBuilder
234
263
 
235
264
  return unless opts[:content_file]
236
265
 
237
- cf = opts[:content_file]
266
+ # NOTE: when using content file, you still want to search for it in the template folders, I THINK?
267
+ cf = find_template_file(opts[:content_file])
268
+
269
+ return "content not found: #{opts[:content_file]}" if cf.nil?
270
+
271
+ # cf = opts[:content_file]
238
272
 
239
- return "Content not found: #{File.expand_path(cf)}" unless File.exist?(cf)
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
240
279
 
241
280
  File.read(cf)
242
281
  end
@@ -281,6 +320,17 @@ module KBuilder
281
320
  Handlebars::Helpers::Template.render(template_content, opts) unless template_content.nil?
282
321
  end
283
322
 
323
+ def run_cop(file, auto_safe: false, auto_all: false)
324
+ cli = RuboCop::CLI.new
325
+ opts = ['--format', 'simple', file]
326
+ opts.prepend('-a') if auto_safe
327
+ opts.prepend('-A') if auto_all
328
+
329
+ cli.run(opts)
330
+ end
331
+
332
+ # Need to handle absolute files, see
333
+ # /Users/davidcruwys/dev/printspeak/reference_application/printspeak-domain/.builders/presentation/presentation_builder/commands/copy_ruby_resource_command.rb
284
334
  def run_prettier(file, log_level: :log)
285
335
  # command = "prettier --check #{file} --write #{file}"
286
336
  command = "npx prettier --loglevel #{log_level} --write #{file}"
@@ -298,6 +348,8 @@ module KBuilder
298
348
 
299
349
  puts build_command
300
350
 
351
+ # need to support the fork process options as I was not able to run
352
+ # k_builder_watch -n because it hid all the following output
301
353
  system(build_command)
302
354
  end
303
355
  alias rc run_command
@@ -1,63 +1,64 @@
1
- # frozen_string_literal: true
2
-
3
- module KBuilder
4
- # Base configuration object for all k_builder* GEM
5
- class BaseConfiguration
6
- class << self
7
- # Attach a child configuration with it's own settings to a parent configuration
8
- #
9
- # @param [Class] klass_child what class would you like as the child
10
- # @param [Class] klass_parent what class would you like to extend with a new child configuration
11
- # @param [Symbol] accessor_name what is the name of the accessor that you are adding
12
- def attach_config_to_parent(klass_child, klass_parent, accessor_name)
13
- # Create a memoized getter to an instance of the attaching class (:klass_child)
14
- #
15
- # def third_party
16
- # @third_party ||= KBuilder::ThirdPartyGem::Configuration.new
17
- # end
18
- klass_parent.send(:define_method, accessor_name) do
19
- return instance_variable_get("@#{accessor_name}") if instance_variable_defined?("@#{accessor_name}")
20
-
21
- instance_variable_set("@#{accessor_name}", klass_child.new)
22
- end
23
- end
24
- alias attach_to attach_config_to_parent
25
- end
26
-
27
- # move out into module
28
- def to_h
29
- hash = {}
30
- instance_variables.each do |var|
31
- value = instance_variable_get(var)
32
-
33
- value = KUtil.data.to_hash(value) if complex_type?(value)
34
-
35
- hash[var.to_s.delete('@')] = value
36
- end
37
- hash
38
- end
39
-
40
- # Any basic (aka primitive) type
41
- def basic_type?(value)
42
- value.is_a?(String) ||
43
- value.is_a?(Symbol) ||
44
- value.is_a?(FalseClass) ||
45
- value.is_a?(TrueClass) ||
46
- value.is_a?(Integer) ||
47
- value.is_a?(Float)
48
- end
49
-
50
- # Anything container that is not a regular class
51
- def complex_type?(value)
52
- value.is_a?(Array) ||
53
- value.is_a?(Hash) ||
54
- value.is_a?(Struct) ||
55
- value.is_a?(OpenStruct) ||
56
- value.respond_to?(:to_h)
57
- end
58
-
59
- def kv(name, value)
60
- puts "#{name.rjust(30)} : #{value}"
61
- end
62
- end
63
- end
1
+ # frozen_string_literal: true
2
+
3
+ module KBuilder
4
+ # Base configuration object for all k_builder* GEM
5
+ class BaseConfiguration
6
+ class << self
7
+ # Attach a child configuration with it's own settings to a parent configuration
8
+ #
9
+ # @param [Class] klass_child what class would you like as the child
10
+ # @param [Class] klass_parent what class would you like to extend with a new child configuration
11
+ # @param [Symbol] accessor_name what is the name of the accessor that you are adding
12
+ def attach_config_to_parent(klass_child, klass_parent, accessor_name)
13
+ # Create a memoized getter to an instance of the attaching class (:klass_child)
14
+ #
15
+ # def third_party
16
+ # @third_party ||= KBuilder::ThirdPartyGem::Configuration.new
17
+ # end
18
+ klass_parent.send(:define_method, accessor_name) do
19
+ return instance_variable_get("@#{accessor_name}") if instance_variable_defined?("@#{accessor_name}")
20
+
21
+ instance_variable_set("@#{accessor_name}", klass_child.new)
22
+ end
23
+ end
24
+ alias attach_to attach_config_to_parent
25
+ end
26
+
27
+ # move out into module
28
+ def to_h
29
+ hash = {}
30
+ instance_variables.each do |var|
31
+ value = instance_variable_get(var)
32
+
33
+ value = KUtil.data.to_hash(value) if complex_type?(value)
34
+
35
+ hash[var.to_s.delete('@')] = value
36
+ end
37
+ hash
38
+ end
39
+
40
+ # This code is being moved into k_util (data)
41
+ # Any basic (aka primitive) type
42
+ def basic_type?(value)
43
+ value.is_a?(String) ||
44
+ value.is_a?(Symbol) ||
45
+ value.is_a?(FalseClass) ||
46
+ value.is_a?(TrueClass) ||
47
+ value.is_a?(Integer) ||
48
+ value.is_a?(Float)
49
+ end
50
+
51
+ # Anything container that is not a regular class
52
+ def complex_type?(value)
53
+ value.is_a?(Array) ||
54
+ value.is_a?(Hash) ||
55
+ value.is_a?(Struct) ||
56
+ value.is_a?(OpenStruct) ||
57
+ value.respond_to?(:to_h)
58
+ end
59
+
60
+ def kv(name, value)
61
+ puts "#{name.rjust(30)} : #{value}"
62
+ end
63
+ end
64
+ end
@@ -1,72 +1,62 @@
1
- # frozen_string_literal: true
2
-
3
- # Attach configuration to the KBuilder module
4
- module KBuilder
5
- # Configuration for webpack5/builder
6
- class << self
7
- attr_writer :configuration
8
- end
9
-
10
- def self.configuration
11
- @configuration ||= Configuration.new
12
- end
13
-
14
- def self.reset
15
- @configuration = Configuration.new
16
- end
17
-
18
- def self.configure
19
- yield(configuration)
20
- end
21
-
22
- # Does this class need to move out into k_types?
23
- # It is being used with k_manager in a similar fashion
24
- #
25
- # Configuration class
26
- class Configuration < BaseConfiguration
27
- include KLog::Logging
28
-
29
- # Target folders provide a set named folders that can be written to
30
- attr_accessor :target_folders
31
-
32
- # Template folders provides layered folders that templates can exist within
33
- attr_accessor :template_folders
34
-
35
- def initialize
36
- super
37
- # @target_folder = Dir.getwd
38
- # @template_folder = File.join(Dir.getwd, '.templates')
39
- # @global_template_folder = nil
40
- @target_folders = KType::NamedFolders.new
41
- @template_folders = KType::LayeredFolders.new
42
- end
43
-
44
- def initialize_copy(orig)
45
- super(orig)
46
-
47
- @target_folders = orig.target_folders.clone
48
- @template_folders = orig.template_folders.clone
49
- end
50
-
51
- # rubocop:disable Metrics/AbcSize
52
- def debug
53
- log.subheading 'kbuilder base configuration'
54
-
55
- log.section_heading 'target_folders'
56
- target_folders.folders.each_key do |key|
57
- folder = target_folders.folders[key]
58
- log.kv key.to_s, folder
59
- end
60
- log.info ''
61
-
62
- log.section_heading 'template folders (search order)'
63
-
64
- template_folders.ordered_keys.each do |key|
65
- folder = template_folders.folders[key]
66
- log.kv key.to_s, folder
67
- end
68
- ''
69
- end
70
- # rubocop:enable Metrics/AbcSize
71
- end
72
- end
1
+ # frozen_string_literal: true
2
+
3
+ # Attach configuration to the KBuilder module
4
+ module KBuilder
5
+ # Configuration for webpack5/builder
6
+ class << self
7
+ attr_writer :configuration
8
+ end
9
+
10
+ def self.configuration
11
+ @configuration ||= Configuration.new
12
+ end
13
+
14
+ def self.reset
15
+ @configuration = Configuration.new
16
+ end
17
+
18
+ def self.configure
19
+ yield(configuration)
20
+ end
21
+
22
+ # Does this class need to move out into k_types?
23
+ # It is being used with k_manager in a similar fashion
24
+ #
25
+ # Configuration class
26
+ class Configuration < BaseConfiguration
27
+ include KLog::Logging
28
+
29
+ # Target folders provide a set named folders that can be written to
30
+ attr_accessor :target_folders
31
+
32
+ # Template folders provides layered folders that templates can exist within
33
+ attr_accessor :template_folders
34
+
35
+ def initialize
36
+ super
37
+ # @target_folder = Dir.getwd
38
+ # @template_folder = File.join(Dir.getwd, '.templates')
39
+ # @global_template_folder = nil
40
+ @target_folders = KType::NamedFolders.new
41
+ @template_folders = KType::LayeredFolders.new
42
+ end
43
+
44
+ def initialize_copy(orig)
45
+ super(orig)
46
+
47
+ @target_folders = orig.target_folders.clone
48
+ @template_folders = orig.template_folders.clone
49
+ end
50
+
51
+ def debug
52
+ log.subheading 'kbuilder base configuration'
53
+
54
+ target_folders.debug(title: 'target_folders')
55
+
56
+ log.info ''
57
+
58
+ template_folders.debug(title: 'template folders (search order)')
59
+ ''
60
+ end
61
+ end
62
+ end
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
-
3
- module KBuilder
4
- VERSION = '0.0.56'
5
- end
1
+ # frozen_string_literal: true
2
+
3
+ module KBuilder
4
+ VERSION = '0.0.61'
5
+ end
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.56
4
+ version: 0.0.61
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Cruwys
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-04-18 00:00:00.000000000 Z
11
+ date: 2021-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: handlebars-helpers
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.8'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.8'
69
83
  description: " K Builder provides various fluent builders for initializing applications
70
84
  with different language requirements\n"
71
85
  email: