k_builder 0.0.57 → 0.0.62
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/.rubocop.yml +1 -0
- data/bin/k +1 -1
- data/k_builder.gemspec +2 -0
- data/lib/k_builder.rb +4 -0
- data/lib/k_builder/base_builder.rb +52 -2
- data/lib/k_builder/commands/base_command.rb +36 -0
- data/lib/k_builder/commands/rubo_cop_command.rb +112 -0
- data/lib/k_builder/configuration.rb +3 -13
- data/lib/k_builder/version.rb +1 -1
- data/~/last_cop.txt +19 -0
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c3544040b2994f74c65d824516980a5ca980d441c53e97629920c23513cf76a2
|
4
|
+
data.tar.gz: e0c8e494f82a58e1564f59cfb66f960f6a99561a3cc28bfab81c17a77a3b4f8d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a27d1f32b26b8878260c11f15a0285b64a65769d9b17631cb05f9c772deab1ddf97bb3f7db9ab392efd9d9b257344bb85272827de19228905b9fe4493d6a485
|
7
|
+
data.tar.gz: f1a237017caff54b821d750dc9e467ec659a7127abae3d9640afe4a997c83afd9347c0113c99eb60d78c849875d26c34305983dbfc478d9e33a6be229ad8149f
|
data/.rubocop.yml
CHANGED
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
|
|
@@ -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
|
-
|
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]
|
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)
|
238
276
|
|
239
|
-
|
277
|
+
# cf = cf_from_template_folders
|
278
|
+
# end
|
240
279
|
|
241
280
|
File.read(cf)
|
242
281
|
end
|
@@ -281,6 +320,15 @@ 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, **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
|
284
332
|
def run_prettier(file, log_level: :log)
|
285
333
|
# command = "prettier --check #{file} --write #{file}"
|
286
334
|
command = "npx prettier --loglevel #{log_level} --write #{file}"
|
@@ -298,6 +346,8 @@ module KBuilder
|
|
298
346
|
|
299
347
|
puts build_command
|
300
348
|
|
349
|
+
# need to support the fork process options as I was not able to run
|
350
|
+
# k_builder_watch -n because it hid all the following output
|
301
351
|
system(build_command)
|
302
352
|
end
|
303
353
|
alias rc run_command
|
@@ -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' << '~/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
|
@@ -48,25 +48,15 @@ module KBuilder
|
|
48
48
|
@template_folders = orig.template_folders.clone
|
49
49
|
end
|
50
50
|
|
51
|
-
# rubocop:disable Metrics/AbcSize
|
52
51
|
def debug
|
53
52
|
log.subheading 'kbuilder base configuration'
|
54
53
|
|
55
|
-
|
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 ''
|
54
|
+
target_folders.debug(title: 'target_folders')
|
61
55
|
|
62
|
-
log.
|
56
|
+
log.info ''
|
63
57
|
|
64
|
-
template_folders.
|
65
|
-
folder = template_folders.folders[key]
|
66
|
-
log.kv key.to_s, folder
|
67
|
-
end
|
58
|
+
template_folders.debug(title: 'template folders (search order)')
|
68
59
|
''
|
69
60
|
end
|
70
|
-
# rubocop:enable Metrics/AbcSize
|
71
61
|
end
|
72
62
|
end
|
data/lib/k_builder/version.rb
CHANGED
data/~/last_cop.txt
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
== /var/folders/jh/nffr8l5j4rzgc7s386gj770r0000gn/T/rspec-20210701-95573-12q1az6/make-pretty.rb ==
|
2
|
+
C: 1: 1: Naming/FileName: The name of this source file (make-pretty.rb) should use snake_case.
|
3
|
+
C: 1: 1: [Corrected] Style/FrozenStringLiteralComment: Missing frozen string literal comment.
|
4
|
+
C: 2: 1: [Corrected] Layout/EmptyLineAfterMagicComment: Add an empty line after magic comments.
|
5
|
+
C: 2: 1: [Corrected] Layout/IndentationWidth: Use 2 (not 0) spaces for indentation.
|
6
|
+
C: 2: 1: [Corrected] Style/SingleLineMethods: Avoid single-line method definitions.
|
7
|
+
C: 2: 19: [Corrected] Layout/SpaceAfterComma: Space missing after comma.
|
8
|
+
W: 2: 20: [Corrected] Lint/UnusedMethodArgument: Unused method argument - xyz. If it's necessary, use _ or _xyz as an argument name to indicate that it won't be used.
|
9
|
+
C: 2: 30: [Corrected] Layout/SpaceAroundOperators: Surrounding space missing for operator =.
|
10
|
+
C: 3: 1: Style/Documentation: Missing top-level class documentation comment.
|
11
|
+
C: 3: 4: [Corrected] Layout/TrailingEmptyLines: Final newline missing.
|
12
|
+
C: 3: 28: [Corrected] Style/Semicolon: Do not use semicolons to terminate expressions.
|
13
|
+
C: 3: 29: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
|
14
|
+
C: 4: 3: [Corrected] Layout/IndentationWidth: Use 2 (not 0) spaces for indentation.
|
15
|
+
C: 4: 13: [Corrected] Style/Semicolon: Do not use semicolons to terminate expressions.
|
16
|
+
C: 4: 14: [Corrected] Layout/TrailingWhitespace: Trailing whitespace detected.
|
17
|
+
W: 5: 1: [Corrected] Layout/DefEndAlignment: end at 5, 0 is not aligned with def at 3, 2.
|
18
|
+
|
19
|
+
1 file inspected, 16 offenses detected, 14 offenses corrected
|
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.62
|
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-
|
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
|
@@ -107,6 +123,7 @@ files:
|
|
107
123
|
- usage/_out5.png
|
108
124
|
- usage/_usage_folder_after.png
|
109
125
|
- usage/_usage_folder_before.png
|
126
|
+
- "~/last_cop.txt"
|
110
127
|
homepage: http://appydave.com
|
111
128
|
licenses:
|
112
129
|
- MIT
|