k_builder-watch 0.0.10 → 0.0.16

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: 0ff99ee20f2a82adba8830ecb57ac6c5e30cc37f85c809280f3ed589ac0aa1f4
4
- data.tar.gz: c160a999a447feb43f651bcb32bdaa8520dd7906fe2bca483c2003e7780a97be
3
+ metadata.gz: 8280e2a147c617e2f8df524f01947fd2e175259af09b2304c4fbde5185179087
4
+ data.tar.gz: 59f3378f2d2cfdd4122dcd8d0f0cf8175a4bd46cdcc06ab545d3d0a8000796ef
5
5
  SHA512:
6
- metadata.gz: 0edaa80a8ab41ffbd91e411db84c5c8f0c1f87c83dd33b7e87a9f214cdf40776bc3932a3be5b7e1bd981cae1192504803defa3a98113ee50d541005904ded6c6
7
- data.tar.gz: 38075ef4c69d77c435ac2fd2abfb4d220ea5d069701da2d49e4623b73daa3bb4a7220a25925058ad8e8846528b89561528b18cbddcb3719f2eb2e16c253eb7bd
6
+ metadata.gz: 27041d6351f0e453d84ad439990bb80a6177c198d6137e57037e47a41773c59ffe48d7843ec00b7bed6497cbb8cb82250d84e2734abd7e7b7895ca82a879f229
7
+ data.tar.gz: 5d610cc2d6f3aaa37ed2f59a0c0ab0995594a648c814bb09b083aebd0b188fe606cbc46a7dd4837c6fca202450a40444dca108dcb2a94c409c05d57b3976f66b
@@ -0,0 +1,16 @@
1
+ Handlebars::Helpers.configure do |config|
2
+ config_file = File.join(Gem.loaded_specs['handlebars-helpers'].full_gem_path, '.handlebars_helpers.json')
3
+ config.helper_config_file = config_file
4
+ end
5
+
6
+ KBuilder.reset
7
+ templates_ruby = '~/dev/kgems/k_dsl/_/.template/ruby-cmdlet'
8
+ target_root = '~/dev/kgems/k_builder-watch/'
9
+
10
+ KBuilder.configure do |config|
11
+ config.target_folders.add(:app , target_root)
12
+
13
+ config.template_folders.add(:global , File.join(templates_ruby , '.global_template'))
14
+ # config.template_folders.add(:app , File.join(template_root , '.app_template'))
15
+ end
16
+
@@ -0,0 +1,29 @@
1
+ require '_initialize.rb'
2
+
3
+ builder = KBuilder::BaseBuilder
4
+ .init
5
+ # .add_file('main.rb', template_file: 'class.rb', name: 'main')
6
+ # .add_file('person.rb',
7
+ # template_file: 'model.rb',
8
+ # name: 'person',
9
+ # fields: %i[first_name last_name])
10
+ # .add_file('address.rb',
11
+ # template_file: 'model.rb',
12
+ # name: 'address',
13
+ # fields: %i[street1 street2 post_code state])
14
+ # .add_file('css/index.css',
15
+ # template: '{{#each colors}} .{{.}} { color: {{.}} } {{/each}}',
16
+ # colors: %w[red blue green],
17
+ # pretty: true)
18
+
19
+ # # /Users/davidcruwys/dev/xxx-watch
20
+ # # /Users/davidcruwys/dev/xxx-watch/basic.rb
21
+
22
+
23
+ # file = builder.target_file('main.rb')
24
+ # puts file
25
+ # puts File.exist?(file)
26
+ # system("code #{file}")
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
@@ -5,13 +5,11 @@
5
5
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '../lib'))
6
6
 
7
7
  require 'k_builder/watch'
8
-
8
+ puts 'yyyyyyyyyyy'
9
9
  # directory = '/Users/davidcruwys/dev/c#/P04DomainMonopolyV1'
10
10
 
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,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'k_doc'
4
+ require 'k_util'
5
+ require 'k_log'
6
+
7
+ require 'k_builder/dotnet'
8
+ require 'k_builder/package_json'
9
+ require 'k_builder/webpack5'
10
+
3
11
  require 'k_builder/watch/version'
4
12
  require 'k_builder/watch/cli'
5
13
  require 'k_builder/watch/watcher'
@@ -10,3 +18,5 @@ module KBuilder
10
18
  class Error < StandardError; end
11
19
  end
12
20
  end
21
+
22
+ 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.10'
5
+ VERSION = '0.0.16'
6
6
  end
7
7
  end
@@ -6,10 +6,10 @@ require 'io/console'
6
6
  # require 'bundler/setup'
7
7
  # require 'webpack5/builder'
8
8
  # require 'handlebars/helpers/configuration'
9
-
10
9
  module KBuilder
10
+ # Watch supports any watch and execute processes for builders
11
11
  module Watch
12
- # Watch fo
12
+ # Watcher does the actual file watching and run the processor
13
13
  class Watcher
14
14
  attr_accessor :directory
15
15
 
@@ -21,29 +21,52 @@ module KBuilder
21
21
  # watch_file = File.join(directory, 'DOMAIN_INSTRUCTIONS.MD')
22
22
 
23
23
  def start
24
- puts 'Watching for file changes'
24
+ clear_screen
25
+ puts "KBuilder-Watch: v#{KBuilder::Watch::VERSION} is watching for file changes"
25
26
  puts "Directory: #{directory}"
26
27
  # puts "Watch File: #{watch_file}"
27
28
 
28
29
  Filewatcher.new(directory).watch do |changes|
29
30
  changes.each do |filename, event|
30
31
  puts "File #{event}: #{filename}"
31
-
32
- process_updated_file(filename) if (event == :updated)
32
+
33
+ process_updated_file(filename) if event == :updated
33
34
  end
34
35
  end
35
36
  end
36
37
 
38
+ # rubocop:disable Lint/RescueException
37
39
  def process_updated_file(filename)
38
- puts "\n" * 70
39
- $stdout.clear_screen
40
+ clear_screen
41
+ update_load_path(filename)
42
+
40
43
  puts "File updated: #{filename}"
41
44
 
42
45
  content = File.read(filename)
43
- Object.class_eval content
44
- rescue StandardError => e
46
+ Object.class_eval(content, filename)
47
+ rescue Exception => e
45
48
  puts e.message
46
- puts e.backtrace.join("\n")
49
+ puts e.backtrace
50
+ .select { |ex| ex.start_with?(filename) }
51
+ .map { |m| m.delete_suffix(":in `process_updated_file'") }
52
+ .join("\n")
53
+ # puts '-' * 70
54
+ # puts e.backtrace.join("\n")
55
+ end
56
+ # rubocop:enable Lint/RescueException
57
+
58
+ private
59
+
60
+ def update_load_path(filename)
61
+ dirname = File.dirname(filename)
62
+
63
+ # This needs to be in detailed logging
64
+ $LOAD_PATH.unshift(dirname) unless $LOAD_PATH.find { |path| path.start_with?(dirname) }
65
+ end
66
+
67
+ def clear_screen
68
+ puts "\n" * 70
69
+ $stdout.clear_screen
47
70
  end
48
71
  end
49
72
  end
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.10
4
+ version: 0.0.16
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,15 +66,59 @@ 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:
72
114
  - david@ideasmen.com.au
73
115
  executables:
74
- - kw
116
+ - k_builder-watch
75
117
  extensions: []
76
118
  extra_rdoc_files: []
77
119
  files:
120
+ - ".builders/_initialize.rb"
121
+ - ".builders/basic.rb"
78
122
  - ".github/workflows/main.yml"
79
123
  - ".gitignore"
80
124
  - ".rspec"
@@ -94,7 +138,7 @@ files:
94
138
  - bin/khotfix
95
139
  - bin/run
96
140
  - bin/setup
97
- - exe/kw
141
+ - exe/k_builder-watch
98
142
  - hooks/pre-commit
99
143
  - hooks/update-version
100
144
  - k_builder-watch.gemspec