k_builder-watch 0.0.13 → 0.0.15

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: 7e76a86d8343b281e5666d924e104ee5a0bf4e15014fb75aad48d84a9e355ef9
4
- data.tar.gz: b0b4b03e513eea00ef9c7754f3b2506ebd287daa54a41760ca1a4e799b3ca0dd
3
+ metadata.gz: a379652e102ecbfa747989d7c7e62a2d490c1d45f45c9c32974118e295432246
4
+ data.tar.gz: a1235bf9a4c8ed27bee303a5c4cdd08ac24f1a7fb6e54ebca8a5a73131b000d7
5
5
  SHA512:
6
- metadata.gz: defff1f756e63a15bf45702614008ea0212ce1e2d9043ea3126942c0f424f70c4d018d204b7e96942b0cab7cf3677dadd64b2866417ceeec6797abd57b5189c2
7
- data.tar.gz: 0a1a251d0bc95a44482491e830db8b58a172b303d7c67af3d54661fcf382f3bae48ee974d15229baa2fcad4f925591bc7cb07526818a7292c88da250d7fc9fce
6
+ metadata.gz: 6266476ab5cf6320a4e0390931f46882bd612adb80bf192c3696e19444845c6c60f232e1b6c34456a52b8e99932f354ca3ce4a1791d51e03485391905bb4ab02
7
+ data.tar.gz: 36ac20f9633c28f8e5f5e697a41c0ad958289e43ead3657e4bbf9657823049a09bd5d4b447eb15fb48d3618fbf83f9bff4b2807bdf16672e28ea2f45313957b7
data/.builders/basic.rb CHANGED
@@ -1,14 +1,7 @@
1
- # require '.builders/_initialize.rb'
1
+ require '_initialize.rb'
2
2
 
3
- $LOAD_PATH.unshift(File.join(Dir.pwd, '.builders'))
4
- load 'x.rb'
5
- puts 'fucit'
6
- # load 'x.rb'
7
- # puts JSON.pretty_generate(KBuilder.configuration.to_h)
8
-
9
- # builder = KBuilder::BaseBuilder.init
10
-
11
- # builder
3
+ builder = KBuilder::BaseBuilder
4
+ .init
12
5
  # .add_file('main.rb', template_file: 'class.rb', name: 'main')
13
6
  # .add_file('person.rb',
14
7
  # template_file: 'model.rb',
@@ -31,4 +24,6 @@ puts 'fucit'
31
24
  # puts file
32
25
  # puts File.exist?(file)
33
26
  # system("code #{file}")
34
- # puts 'basic'
27
+ # puts 'basic'
28
+
29
+ puts 'DONE!'
data/Gemfile CHANGED
@@ -23,3 +23,16 @@ group :development, :test do
23
23
  gem 'rubocop-rake', require: false
24
24
  gem 'rubocop-rspec', require: false
25
25
  end
26
+
27
+ # # If local dependency
28
+ # if true
29
+ # group :development, :test do
30
+ # # /Users/davidcruwys/dev/kgems/k_builder/lib/k_builder
31
+ # gem 'k_builder', path: '../k_builder'
32
+ # gem 'k_builder-package_json', path: '../k_builder-package_json'
33
+ # gem 'k_builder-webpack5', path: '../k_builder-webpack5'
34
+ # gem 'k_doc', path: '../k_doc'
35
+ # gem 'k_log', path: '../k_log'
36
+ # gem 'k_util', path: '../k_util'
37
+ # end
38
+ # end
data/bin/run CHANGED
@@ -11,7 +11,5 @@ require 'k_builder/watch'
11
11
  cli = KBuilder::Watch::Cli.new
12
12
  cli.execute
13
13
 
14
- unless cli.debug
15
- watcher = KBuilder::Watch::Watcher.new(cli.watch_path)
16
- watcher.start
17
- end
14
+ watcher = KBuilder::Watch::Watcher.new(cli.watch_path)
15
+ watcher.start
data/exe/k_builder-watch CHANGED
@@ -11,7 +11,5 @@ require 'k_builder/watch'
11
11
  cli = KBuilder::Watch::Cli.new
12
12
  cli.execute
13
13
 
14
- unless cli.debug
15
- watcher = KBuilder::Watch::Watcher.new(cli.watch_path)
16
- watcher.start
17
- end
14
+ watcher = KBuilder::Watch::Watcher.new(cli.watch_path)
15
+ watcher.start
@@ -42,4 +42,7 @@ Gem::Specification.new do |spec|
42
42
  spec.add_dependency 'k_builder', '~> 0.0'
43
43
  spec.add_dependency 'k_builder-package_json', '~> 0.0'
44
44
  spec.add_dependency 'k_builder-webpack5', '~> 0.0'
45
+ spec.add_dependency 'k_doc', '~> 0.0'
46
+ spec.add_dependency 'k_log', '~> 0.0'
47
+ spec.add_dependency 'k_util', '~> 0.0'
45
48
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'k_doc'
3
4
  require 'k_builder/watch/version'
4
5
  require 'k_builder/watch/cli'
5
6
  require 'k_builder/watch/watcher'
@@ -10,3 +11,5 @@ module KBuilder
10
11
  class Error < StandardError; end
11
12
  end
12
13
  end
14
+
15
+ puts "KBuilder::Watch::Version: #{KBuilder::Watch::VERSION}" if ENV['KLUE_DEBUG']&.to_s&.downcase == 'true'
@@ -14,16 +14,27 @@ module KBuilder
14
14
  attr_accessor :debug
15
15
  attr_accessor :base_path
16
16
  attr_accessor :path
17
+ attr_accessor :path_relative
18
+ attr_accessor :new_path
19
+ attr_accessor :new_path_relative
20
+ attr_accessor :new
21
+ attr_accessor :app_path
17
22
  attr_accessor :watch_path
18
23
  attr_accessor :help
19
24
 
20
25
  def initialize
26
+ # puts "Watch: #{KBuilder::Watch::VERSION}"
21
27
  # @repetitions = 1
22
28
  # @name = nil
23
29
  @debug = false
24
30
  @watch_path = nil
25
31
  @base_path = Dir.pwd
32
+ @path_relative = nil # '.'
26
33
  @path = nil
34
+ @app_path = nil
35
+ @new_path = nil
36
+ @new_path_relative = nil
37
+ @new = nil
27
38
 
28
39
  parse_arguments
29
40
  post_process_arguments
@@ -31,10 +42,10 @@ module KBuilder
31
42
 
32
43
  def options
33
44
  # ['--repeat' , '-r', GetoptLong::REQUIRED_ARGUMENT],
34
- # ['--name' , '-n', GetoptLong::OPTIONAL_ARGUMENT]
35
45
  GetoptLong.new(
36
- ['--help' , '-h', GetoptLong::NO_ARGUMENT],
37
- ['--debug' , GetoptLong::NO_ARGUMENT]
46
+ ['--help' , '-h', GetoptLong::NO_ARGUMENT],
47
+ ['--debug' , GetoptLong::NO_ARGUMENT],
48
+ ['--new' , '-n', GetoptLong::OPTIONAL_ARGUMENT]
38
49
  )
39
50
  end
40
51
 
@@ -52,15 +63,23 @@ module KBuilder
52
63
  end
53
64
 
54
65
  def parse_final_argument
55
- if ARGV.length != 1
56
- puts 'Missing dir argument (try --help)'
57
- exit 0
58
- end
66
+ # if ARGV.length != 1
67
+ # puts 'Missing dir argument (try --help)'
68
+ # exit 0
69
+ # end
70
+
71
+ @path_relative = if ARGV.length == 1
72
+ ARGV.shift
73
+ else
74
+ '.'
75
+ end
59
76
 
60
- @path = ARGV.shift
77
+ return unless @path.nil?
78
+
79
+ @path = File.join(base_path, path_relative)
61
80
  end
62
81
 
63
- def parse_option(opt, _arg)
82
+ def parse_option(opt, arg)
64
83
  case opt
65
84
  when '--help'
66
85
  @help = true
@@ -68,14 +87,20 @@ module KBuilder
68
87
  @debug = true
69
88
  # when '--repeat'
70
89
  # @repetitions = arg.to_i
71
- # when '--name' # sample
72
- # @name = (arg == '' ? 'John' : arg)
90
+ when '--new'
91
+ # Maybe better to call @new, @app_name
92
+ @new = arg
93
+ @app_path = File.join(base_path, arg)
94
+ @new_path_relative = arg == '' ? '.builders' : File.join(arg.to_s, '.builders')
95
+ @new_path = File.join(base_path, @new_path_relative)
96
+ @path = @new_path_relative
73
97
  end
74
98
  end
75
99
 
76
100
  def execute
77
101
  display_help if help
78
102
  display_debug if debug
103
+ new_builder unless @new.nil?
79
104
 
80
105
  # Dir.chdir(dir)
81
106
  # for i in (1..repetitions)
@@ -87,29 +112,41 @@ module KBuilder
87
112
  # end
88
113
  end
89
114
 
90
- def display_help
91
- puts 'This is the help menu.'
92
- puts ' -h This help file'
93
- puts ' --debug debug options'
94
-
95
- # hello [OPTION] ... DIR
96
-
97
- # -h, --help:
98
- # show help
115
+ def new_builder
116
+ setup_file = File.join(new_path, 'setup.rb')
117
+ config_file = File.join(new_path, 'config', '_.rb')
99
118
 
100
- # --repeat x, -n x:
101
- # repeat x times
119
+ FileUtils.mkdir_p(File.dirname(config_file))
120
+ File.write(setup_file, "require 'config/_'") unless File.exist?(setup_file)
121
+ File.write(config_file, "puts '_'\n\n#require 'config/_initialize'") unless File.exist?(config_file)
102
122
 
103
- # --name [name]:
104
- # greet user by name, if name not supplied default is John
123
+ system("code #{File.join(app_path, '.')}")
124
+ end
105
125
 
106
- # DIR: The directory in which to issue the greeting.
126
+ def display_help
127
+ puts 'HELP: k_watcher [OPTION] ... DIR'
128
+ puts ''
129
+ puts ' -h, --help: - show help'
130
+ puts ' --debug - display debug options'
131
+ puts ' -n, --new [folder_name] - create a new .builders folder with setup file, optionally create it under the [FolderName]'
132
+ puts ''
133
+ puts ' DIR: - The directory to watch, will default to current directory "."'
134
+ puts ''
135
+ puts 'examples'
136
+ puts ''
137
+ puts 'Get Help - k_watcher -h'
138
+ puts 'Debug - k_watcher --debug'
139
+ puts 'New builder project (./.builders) - k_watcher -n'
140
+ puts 'New builder project (./HelloWorld/.builders) - k_watcher -n HelloWorld'
141
+ puts 'Watch current folder (.) - k_watcher'
142
+ puts 'Watch the subfolder (.builders) - k_watcher .builders'
107
143
 
108
144
  exit
109
145
  end
110
146
 
111
147
  def display_debug
112
148
  puts JSON.pretty_generate(to_h)
149
+ exit
113
150
  end
114
151
 
115
152
  def to_h
@@ -117,14 +154,20 @@ module KBuilder
117
154
  # name: name,
118
155
  {
119
156
  debug: debug,
157
+ app_path: app_path,
120
158
  base_path: base_path,
159
+ path_relative: path_relative,
121
160
  watch_path: watch_path,
122
- path: path
161
+ new_path: new_path,
162
+ new_path_relative: new_path_relative,
163
+ new: new
123
164
  }
124
165
  end
125
166
 
126
167
  private
127
168
 
169
+ # Refactor to use KUtil.file.expand_path(path, base_path)
170
+ # Need tests
128
171
  def set_watch_path
129
172
  @watch_path = if path.start_with?('~')
130
173
  File.expand_path(path)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module KBuilder
4
4
  module Watch
5
- VERSION = '0.0.13'
5
+ VERSION = '0.0.15'
6
6
  end
7
7
  end
@@ -38,19 +38,33 @@ module KBuilder
38
38
 
39
39
  # rubocop:disable Lint/RescueException
40
40
  def process_updated_file(filename)
41
- $LOAD_PATH.unshift(File.join(Dir.pwd, '.builders'))
42
- # Can I set __FILE__ during class_eval
41
+ clear_screen
42
+ update_load_path(filename)
43
43
 
44
44
  puts "File updated: #{filename}"
45
45
 
46
46
  content = File.read(filename)
47
- Object.class_eval(content, __FILE__, __LINE__)
47
+ Object.class_eval(content, filename)
48
48
  rescue Exception => e
49
49
  puts e.message
50
- puts e.backtrace.select { |ex| ex.start_with?(filename) }.join("\n")
50
+ puts e.backtrace
51
+ .select { |ex| ex.start_with?(filename) }
52
+ .map { |m| m.delete_suffix(":in `process_updated_file'") }
53
+ .join("\n")
54
+ # puts '-' * 70
55
+ # puts e.backtrace.join("\n")
51
56
  end
52
57
  # rubocop:enable Lint/RescueException
53
58
 
59
+ private
60
+
61
+ def update_load_path(filename)
62
+ dirname = File.dirname(filename)
63
+
64
+ # This needs to be in detailed logging
65
+ $LOAD_PATH.unshift(dirname) unless $LOAD_PATH.find { |path| path.start_with?(dirname) }
66
+ end
67
+
54
68
  def clear_screen
55
69
  puts "\n" * 70
56
70
  $stdout.clear_screen
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: k_builder-watch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
4
+ version: 0.0.15
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-03-24 00:00:00.000000000 Z
11
+ date: 2021-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: filewatcher
@@ -66,6 +66,48 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: k_doc
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: k_log
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: k_util
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.0'
69
111
  description: " K-Builder-Watch will watch k_builder files and when they change,
70
112
  execute them\n"
71
113
  email:
@@ -77,7 +119,6 @@ extra_rdoc_files: []
77
119
  files:
78
120
  - ".builders/_initialize.rb"
79
121
  - ".builders/basic.rb"
80
- - ".builders/x.rb"
81
122
  - ".github/workflows/main.yml"
82
123
  - ".gitignore"
83
124
  - ".rspec"
data/.builders/x.rb DELETED
File without changes