k_builder-watch 0.0.9 → 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: ffba6b210249e0a99bb8095803c1df6e215e499f0f841525ab87be0bb7326cb2
4
- data.tar.gz: f1ae33a4e14004351b27a09120a7baa58cb5b3277dbfa2f77ac39bd46b967b20
3
+ metadata.gz: a379652e102ecbfa747989d7c7e62a2d490c1d45f45c9c32974118e295432246
4
+ data.tar.gz: a1235bf9a4c8ed27bee303a5c4cdd08ac24f1a7fb6e54ebca8a5a73131b000d7
5
5
  SHA512:
6
- metadata.gz: a82f58fedc9e4a1d30d11b9fe9cd5f8a6595d0c05cbdabf698da0bebea1ecf61d68b7b8126bbad47fed00b85df7db3750bad01df3ecf122880e00d339dca2376
7
- data.tar.gz: d0a10ab980f218d39423140b16a0a8a2934ccf046bdc7378312c8d46756c5c593e4c8e1b78ccf08fadca244a10c951892d6612d09f211b2b1c67417cc5310112
6
+ metadata.gz: 6266476ab5cf6320a4e0390931f46882bd612adb80bf192c3696e19444845c6c60f232e1b6c34456a52b8e99932f354ca3ce4a1791d51e03485391905bb4ab02
7
+ data.tar.gz: 36ac20f9633c28f8e5f5e697a41c0ad958289e43ead3657e4bbf9657823049a09bd5d4b447eb15fb48d3618fbf83f9bff4b2807bdf16672e28ea2f45313957b7
@@ -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/.gitignore CHANGED
@@ -23,6 +23,7 @@ k_builder_watch.yml
23
23
  /doc/
24
24
  /pkg/
25
25
  /spec/reports/
26
+ /spec/samples-output/
26
27
  /tmp/
27
28
  !/tmp/.keep
28
29
  *.bundle
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
@@ -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
@@ -38,8 +38,11 @@ Gem::Specification.new do |spec|
38
38
  spec.require_paths = ['lib']
39
39
  # spec.extensions = ['ext/k_builder/watch/extconf.rb']
40
40
 
41
- spec.add_dependency 'filewatcher', '~> 0.0'
41
+ spec.add_dependency 'filewatcher', '~> 2.0.0.beta3'
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.9'
5
+ VERSION = '0.0.15'
6
6
  end
7
7
  end
@@ -8,8 +8,9 @@ require 'io/console'
8
8
  # require 'handlebars/helpers/configuration'
9
9
 
10
10
  module KBuilder
11
+ # Watch supports any watch and execute processes for builders
11
12
  module Watch
12
- # Watch fo
13
+ # Watcher does the actual file watching and run the processor
13
14
  class Watcher
14
15
  attr_accessor :directory
15
16
 
@@ -21,33 +22,52 @@ module KBuilder
21
22
  # watch_file = File.join(directory, 'DOMAIN_INSTRUCTIONS.MD')
22
23
 
23
24
  def start
24
- puts 'Watching for file changes'
25
+ clear_screen
26
+ puts "KBuilder-Watch: v#{KBuilder::Watch::VERSION} is watching for file changes"
25
27
  puts "Directory: #{directory}"
26
28
  # puts "Watch File: #{watch_file}"
27
29
 
28
- Filewatcher.new(directory).watch do |filename, event|
29
- if (event == :updated) && filename # .casecmp(watch_file).zero?
30
- # puts "\n" * 70
31
- # $stdout.clear_screen
30
+ Filewatcher.new(directory).watch do |changes|
31
+ changes.each do |filename, event|
32
+ puts "File #{event}: #{filename}"
32
33
 
33
- process_updated_file(filename)
34
+ process_updated_file(filename) if event == :updated
34
35
  end
35
-
36
- puts "File deleted: #{filename}" if event == :delete
37
- puts "Added file: #{filename}" if event == :new
38
36
  end
39
37
  end
40
38
 
39
+ # rubocop:disable Lint/RescueException
41
40
  def process_updated_file(filename)
42
- puts "\n" * 70
43
- $stdout.clear_screen
41
+ clear_screen
42
+ update_load_path(filename)
43
+
44
44
  puts "File updated: #{filename}"
45
45
 
46
46
  content = File.read(filename)
47
- Object.class_eval content
48
- rescue StandardError => e
47
+ Object.class_eval(content, filename)
48
+ rescue Exception => e
49
49
  puts e.message
50
- puts e.backtrace.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")
56
+ end
57
+ # rubocop:enable Lint/RescueException
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
+
68
+ def clear_screen
69
+ puts "\n" * 70
70
+ $stdout.clear_screen
51
71
  end
52
72
  end
53
73
  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.9
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
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.0'
19
+ version: 2.0.0.beta3
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.0'
26
+ version: 2.0.0.beta3
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: k_builder
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -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