k_builder 0.0.58 → 0.0.63

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: f173e365f4bece5981d87548e67b32f9748e2ae8438d2d3bb54c121de957ec87
4
- data.tar.gz: 3d2c0d23e74b0049a112f8e175fa6dce05a1afad90b80f77a63f82d3231c772a
3
+ metadata.gz: 260817fcc90386176ab82712c52a9a15e5a822b04f348a1b3f5b9ba7ea57c0dd
4
+ data.tar.gz: 68587734f564fac66c1fe8378cb417f81a88539cfa1cb58f08d34a29dca288ff
5
5
  SHA512:
6
- metadata.gz: 63901b9242e0933f4d6b639fbdbba2212b5f37d614b1cf43cf7ace40d97560bd0afb47cba1879c4e2ba9d923f52c12f5456ce03c734a77d63472977adc996184
7
- data.tar.gz: eec21944c6e4d9cc64f2fa841ecbe1c655f14146626e04152b9ad152824b19f0a1d7450346781aaba1f0d4994649d99faa00ea39a5f40714a1df143b0adbc22a
6
+ metadata.gz: 57099e14149c32c39e02d85322bfa241ba5525ffe939a59824a21a67738db77a4fae2eb070cb777feb85dcaf9aa7113d107a53ed2be15e1219607a7f271f4852
7
+ data.tar.gz: e2b5a3aa292859d76c69f70ff0e99d20fd2b0f5ea67be17c20f4cf338f3c5be5fb37370528f44c64ad2376a8b22f1ecd21f011581f688b72dbf60cb7f830b5c0
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'
@@ -8,6 +10,8 @@ require 'k_builder/base_builder'
8
10
  require 'k_builder/base_configuration'
9
11
  require 'k_builder/configuration'
10
12
  require 'k_builder/file_segments'
13
+ require 'k_builder/commands/base_command'
14
+ require 'k_builder/commands/rubo_cop_command'
11
15
 
12
16
  require 'handlebars/helpers/template'
13
17
 
@@ -62,6 +62,8 @@ module KBuilder
62
62
  def debug
63
63
  log.subheading 'kbuilder'
64
64
 
65
+ log.kv 'current folder key' , current_folder_key
66
+ log.kv 'current folder' , target_folder
65
67
  target_folders.debug(title: 'target_folders')
66
68
 
67
69
  log.info ''
@@ -94,6 +96,7 @@ module KBuilder
94
96
  # @option opts [String] :to Recipient email
95
97
  # @option opts [String] :body The email's body
96
98
  def add_file(file, **opts)
99
+ # move to command
97
100
  full_file = opts.key?(:folder_key) ? target_file(file, folder: opts[:folder_key]) : target_file(file)
98
101
 
99
102
  # Need logging options that can log these internal details
@@ -111,6 +114,16 @@ module KBuilder
111
114
  end
112
115
  alias touch add_file # it is expected that you would not supply any options, just a file name
113
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
+
114
127
  # Add content to the clipboard
115
128
  #
116
129
  # @option opts [String] :content Supply the content that you want to write to the file
@@ -122,6 +135,7 @@ module KBuilder
122
135
  # @option opts [String] :to Recipient email
123
136
  # @option opts [String] :body The email's body
124
137
  def add_clipboard(**opts)
138
+ # move to command
125
139
  content = process_any_content(**opts)
126
140
 
127
141
  begin
@@ -139,6 +153,7 @@ module KBuilder
139
153
  alias clipboard_copy add_clipboard
140
154
 
141
155
  def vscode(*file_parts, folder: current_folder_key)
156
+ # move to command
142
157
  file = target_file(*file_parts, folder: folder)
143
158
 
144
159
  rc "code #{file}"
@@ -305,6 +320,15 @@ module KBuilder
305
320
  Handlebars::Helpers::Template.render(template_content, opts) unless template_content.nil?
306
321
  end
307
322
 
323
+ def run_cop(file, **opts)
324
+ command = Commands::RuboCopCommand.new(file, builder: self, **opts)
325
+ command.execute
326
+
327
+ self
328
+ end
329
+
330
+ # Need to handle absolute files, see
331
+ # /Users/davidcruwys/dev/printspeak/reference_application/printspeak-domain/.builders/presentation/presentation_builder/commands/copy_ruby_resource_command.rb
308
332
  def run_prettier(file, log_level: :log)
309
333
  # command = "prettier --check #{file} --write #{file}"
310
334
  command = "npx prettier --loglevel #{log_level} --write #{file}"
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KBuilder
4
+ module Commands
5
+ # Base command for single responsibility actions that can be fired
6
+ # from methods in the builder.
7
+ #
8
+ # Uses the command pattern
9
+ class BaseCommand
10
+ include KLog::Logging
11
+
12
+ attr_accessor :builder
13
+ attr_accessor :valid
14
+
15
+ def initialize(**opts)
16
+ @builder = opts[:builder]
17
+ @valid = true
18
+ end
19
+
20
+ def guard(message)
21
+ # THIS SHOULD ONLY LOG IF DEBUGGING IS TURNED ON
22
+ log.error(message)
23
+ @valid = false
24
+ end
25
+
26
+ def valid?
27
+ @valid
28
+ end
29
+
30
+ def debug(title: nil)
31
+ log.section_heading(title) if title
32
+ debug_values if respond_to?(:debug_values)
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,112 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KBuilder
4
+ module Commands
5
+ # Run RuboCop against a file
6
+ class RuboCopCommand < BaseCommand
7
+ attr_reader :file_pattern
8
+ attr_reader :fix_safe
9
+ attr_reader :fix_unsafe
10
+ attr_reader :rubo_config_file
11
+ attr_reader :show_console
12
+
13
+ attr_reader :cop_options
14
+ attr_reader :cop_opt_values
15
+
16
+ # Initialize RuboCop command
17
+ #
18
+ # @param [String] file_pattern File name or file pattern
19
+ # @param [Hash] **opts The options
20
+ # @option opts [Boolean] :fix_safe RuboCop -a option will fix simple and safe issues
21
+ # @option opts [Boolean] :fix_unsafe RuboCop -A option will fix simple but potentially unsafe issues
22
+ # @option opts [Boolean] :show_console This will show in console, or if false set --out ~/last_cop.txt so that console is redirected to file
23
+ # @option opts [String] :rubo_config_file YAML file with RuboCop configuration options
24
+ #
25
+ # @example Cop for single file with auto fix turned on for simple issues
26
+ #
27
+ # RubCopCommand.new('abc.rb', fix_safe: true)
28
+ #
29
+ # @example Cop for all spec files to auto simple and unsafe issues
30
+ #
31
+ # RubCopCommand.new('spec/**/*.rb', fix_unsafe: true)
32
+ def initialize(file_pattern, **opts)
33
+ super(**opts)
34
+
35
+ @valid = true
36
+
37
+ self.file_pattern = file_pattern
38
+
39
+ self.fix_safe = opts[:fix_safe]
40
+ self.fix_unsafe = opts[:fix_unsafe]
41
+ self.show_console = opts[:show_console]
42
+ self.rubo_config_file = opts[:rubo_config_file]
43
+ end
44
+
45
+ def execute
46
+ return unless valid?
47
+
48
+ cop_run
49
+ end
50
+
51
+ def cli_options
52
+ cli_options = []
53
+ # quite is the same as simple, except you will see nothing if no offenses
54
+ cli_options << '--format' << 'quiet' # 'simple'
55
+ cli_options << '-a' if fix_safe
56
+ cli_options << '-A' if fix_unsafe
57
+ cli_options << '--config' << rubo_config_file if rubo_config_file
58
+ cli_options << '--out' << File.expand_path('~/last_cop.txt') unless show_console
59
+ cli_options << file_pattern
60
+ cli_options
61
+ end
62
+
63
+ def debug_values
64
+ log.kv 'rubocop target', file_pattern
65
+ log.kv '-a', 'automatic fix for safe issues' if fix_safe
66
+ log.kv '-A', 'automatic fix for potentially unsafe issues' if fix_unsafe
67
+ log.kv '-config', rubo_config_file if rubo_config_file
68
+ end
69
+
70
+ private
71
+
72
+ def file_pattern=(value)
73
+ @file_pattern = value
74
+
75
+ if value.nil? || value.empty?
76
+ guard 'file_pattern is required'
77
+ elsif Pathname.glob(value).length.zero?
78
+ guard 'file_pattern does not reference an existing file'
79
+ end
80
+ end
81
+
82
+ def fix_safe=(value)
83
+ @fix_safe = value || false
84
+ end
85
+
86
+ def fix_unsafe=(value)
87
+ @fix_unsafe = value || false
88
+ end
89
+
90
+ def show_console=(value)
91
+ @show_console = value || false
92
+ end
93
+
94
+ def rubo_config_file=(value)
95
+ @rubo_config_file = value
96
+
97
+ return if value.nil? || value.empty?
98
+
99
+ guard("Unknown RuboCop config file: #{value}") unless File.exist?(value)
100
+ end
101
+
102
+ def cop_run
103
+ cli = RuboCop::CLI.new
104
+
105
+ # log.section_heading('CLI OPTIONS')
106
+ # log.block cli_options
107
+
108
+ cli.run(cli_options)
109
+ end
110
+ end
111
+ end
112
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KBuilder
4
- VERSION = '0.0.58'
4
+ VERSION = '0.0.63'
5
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.58
4
+ version: 0.0.63
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-06-26 00:00:00.000000000 Z
11
+ date: 2021-07-01 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:
@@ -97,6 +111,8 @@ files:
97
111
  - lib/k_builder.rb
98
112
  - lib/k_builder/base_builder.rb
99
113
  - lib/k_builder/base_configuration.rb
114
+ - lib/k_builder/commands/base_command.rb
115
+ - lib/k_builder/commands/rubo_cop_command.rb
100
116
  - lib/k_builder/configuration.rb
101
117
  - lib/k_builder/file_segments.rb
102
118
  - lib/k_builder/version.rb