k_builder-watch 0.0.2 → 0.0.3

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: 26ee2c5e535147eb27bfba60457c209f1a60f4df655272ef39c3e58e53cbe07c
4
- data.tar.gz: 7008b9a06677786973e59c85043bf95c6bc62cbbbd5301c64a86641967df8e82
3
+ metadata.gz: ac2acbb5c87e56b57d85bf6d9b235789fd4421edb19791782b0565442618a4c4
4
+ data.tar.gz: d7d285877d96fa3442010259f2099e486096873de1c7a337efa3444420c495e1
5
5
  SHA512:
6
- metadata.gz: d5f84af918e41f24ed145a7b4aee2bdcac715e6042d3c32849889e9a2dbc510e0125b7983070639cac38b2dedfec19604c92ff6c2d28f4c58d3479df5f68dccb
7
- data.tar.gz: f1c6d444a73ed1a644cbc1210d8f9518ed1b00f4af3bbb554724c392364675815d8e09076ef3c91cc42736d0a4fc4d53c7bd5e2a4d252ce81e6ed3b2631a8f83
6
+ metadata.gz: 105e6a4a5fcf06960348e94e28ad9c62ac81de4db53f706eb89b8538c14c2586458b8334548c8cd2ef77b2494eeaa2a3dc06d650fae3771a19b67dec2be7c5d5
7
+ data.tar.gz: 871dfe063982d15ec60d2cf7bfe3c2f5469e5ae7f506ff9f31a2ca31f9b4e3f42f454d640255646c335ed897ed566a77a3b8b17a0dbdadc953d4c27ffc0ad300
@@ -0,0 +1,5 @@
1
+ {
2
+ "cSpell.words": [
3
+ "filewatcher"
4
+ ]
5
+ }
data/Rakefile CHANGED
@@ -11,7 +11,7 @@ desc 'Compile all the extensions'
11
11
  task build: :compile
12
12
 
13
13
  Rake::ExtensionTask.new('k_builder_watch') do |ext|
14
- ext.lib_dir = 'lib/k_builder_watch'
14
+ ext.lib_dir = 'lib/k_builder/watch'
15
15
  end
16
16
 
17
17
  task default: %i[clobber compile spec]
data/bin/console CHANGED
@@ -3,7 +3,7 @@
3
3
  # frozen_string_literal: true
4
4
 
5
5
  require 'bundler/setup'
6
- require 'k_builder_watch'
6
+ require 'k_builder/watch'
7
7
 
8
8
  # You can add fixtures and/or initialization code here to make experimenting
9
9
  # with your gem easier. You can also use a different console, if you like.
data/bin/run ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # frozen_string_literal: true
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '../lib'))
6
+
7
+ require 'k_builder/watch'
8
+
9
+ # directory = '/Users/davidcruwys/dev/c#/P04DomainMonopolyV1'
10
+
11
+ cli = KBuilder::Watch::Cli.new
12
+ cli.execute
13
+
14
+ unless cli.debug
15
+ watcher = KBuilder::Watch::Watcher.new(cli.watch_path)
16
+ watcher.start
17
+ end
@@ -36,7 +36,11 @@ Gem::Specification.new do |spec|
36
36
  spec.bindir = 'exe'
37
37
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
38
38
  spec.require_paths = ['lib']
39
- # spec.extensions = ['ext/k_builder_watch/extconf.rb']
39
+ # spec.extensions = ['ext/k_builder/watch/extconf.rb']
40
40
 
41
+ spec.add_dependency 'filewatcher', '~> 0.0'
42
+ spec.add_dependency 'k_builder', '~> 0.0'
43
+ spec.add_dependency 'k_builder-package_json', '~> 0.0'
44
+ spec.add_dependency 'k_builder-webpack5', '~> 0.0'
41
45
  # spec.add_dependency 'tty-box', '~> 0.5.0'
42
46
  end
@@ -1,12 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'k_builder/watch/version'
4
+ require 'k_builder/watch/cli'
5
+ require 'k_builder/watch/watcher'
4
6
 
5
7
  module KBuilder
6
8
  module Watch
7
9
  # raise KBuilder::Watch::Error, 'Sample message'
8
10
  class Error < StandardError; end
9
-
10
- # Your code goes here...
11
11
  end
12
12
  end
@@ -0,0 +1,137 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pry'
4
+ require 'k_builder'
5
+ require 'json'
6
+ require 'getoptlong'
7
+
8
+ module KBuilder
9
+ module Watch
10
+ # Command line interface for starting the watcher
11
+ class Cli
12
+ # attr_accessor :repetitions
13
+ # attr_accessor :name
14
+ attr_accessor :debug
15
+ attr_accessor :base_path
16
+ attr_accessor :path
17
+ attr_accessor :watch_path
18
+ attr_accessor :help
19
+
20
+ def initialize
21
+ # @repetitions = 1
22
+ # @name = nil
23
+ @debug = false
24
+ @watch_path = nil
25
+ @base_path = Dir.pwd
26
+ @path = nil
27
+
28
+ parse_arguments
29
+ post_process_arguments
30
+ end
31
+
32
+ def options
33
+ # ['--repeat' , '-r', GetoptLong::REQUIRED_ARGUMENT],
34
+ # ['--name' , '-n', GetoptLong::OPTIONAL_ARGUMENT]
35
+ GetoptLong.new(
36
+ ['--help' , '-h', GetoptLong::NO_ARGUMENT],
37
+ ['--debug' , GetoptLong::NO_ARGUMENT]
38
+ )
39
+ end
40
+
41
+ def post_process_arguments
42
+ set_watch_path
43
+ end
44
+
45
+ def parse_arguments
46
+ # bin/run -l -r 2 --name -- spec/samples
47
+ options.each do |opt, arg|
48
+ parse_option(opt, arg)
49
+ end
50
+
51
+ parse_final_argument
52
+ end
53
+
54
+ def parse_final_argument
55
+ if ARGV.length != 1
56
+ puts 'Missing dir argument (try --help)'
57
+ exit 0
58
+ end
59
+
60
+ @path = ARGV.shift
61
+ end
62
+
63
+ def parse_option(opt, _arg)
64
+ case opt
65
+ when '--help'
66
+ @help = true
67
+ when '--debug'
68
+ @debug = true
69
+ # when '--repeat'
70
+ # @repetitions = arg.to_i
71
+ # when '--name' # sample
72
+ # @name = (arg == '' ? 'John' : arg)
73
+ end
74
+ end
75
+
76
+ def execute
77
+ display_help if help
78
+ display_debug if debug
79
+
80
+ # Dir.chdir(dir)
81
+ # for i in (1..repetitions)
82
+ # print "Hello"
83
+ # if name
84
+ # print ", #{name}"
85
+ # end
86
+ # puts
87
+ # end
88
+ end
89
+
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
99
+
100
+ # --repeat x, -n x:
101
+ # repeat x times
102
+
103
+ # --name [name]:
104
+ # greet user by name, if name not supplied default is John
105
+
106
+ # DIR: The directory in which to issue the greeting.
107
+
108
+ exit
109
+ end
110
+
111
+ def display_debug
112
+ puts JSON.pretty_generate(to_h)
113
+ end
114
+
115
+ def to_h
116
+ # repetitions: repetitions,
117
+ # name: name,
118
+ {
119
+ debug: debug,
120
+ base_path: base_path,
121
+ watch_path: watch_path,
122
+ path: path
123
+ }
124
+ end
125
+
126
+ private
127
+
128
+ def set_watch_path
129
+ @watch_path = if path.start_with?('~')
130
+ File.expand_path(path)
131
+ else
132
+ File.absolute_path(path, base_path)
133
+ end
134
+ end
135
+ end
136
+ end
137
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module KBuilder
4
4
  module Watch
5
- VERSION = '0.0.2'
5
+ VERSION = '0.0.3'
6
6
  end
7
7
  end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'filewatcher'
4
+ # require 'json'
5
+ require 'io/console'
6
+ # require 'bundler/setup'
7
+ # require 'webpack5/builder'
8
+ # require 'handlebars/helpers/configuration'
9
+
10
+ module KBuilder
11
+ module Watch
12
+ # Watch fo
13
+ class Watcher
14
+ attr_accessor :directory
15
+
16
+ def initialize(directory)
17
+ @directory = directory
18
+ end
19
+
20
+ # May need some sort of pattern filters
21
+ # watch_file = File.join(directory, 'DOMAIN_INSTRUCTIONS.MD')
22
+
23
+ def start
24
+ puts 'Watching for file changes'
25
+ puts "Directory: #{directory}"
26
+ # puts "Watch File: #{watch_file}"
27
+
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
32
+
33
+ process_updated_file(filename)
34
+ end
35
+
36
+ puts "File deleted: #{filename}" if event == :delete
37
+ puts "Added file: #{filename}" if event == :new
38
+ end
39
+ end
40
+
41
+ def process_updated_file(filename)
42
+ puts "\n" * 70
43
+ $stdout.clear_screen
44
+ puts "File updated: #{filename}"
45
+
46
+ content = File.read(filename)
47
+ Object.class_eval content
48
+ rescue StandardError => e
49
+ puts e.message
50
+ puts e.backtrace.join("\n")
51
+ end
52
+ end
53
+ end
54
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: k_builder-watch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Cruwys
@@ -9,7 +9,63 @@ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
11
  date: 2021-03-23 00:00:00.000000000 Z
12
- dependencies: []
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: filewatcher
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: k_builder
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: k_builder-package_json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: k_builder-webpack5
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.0'
13
69
  description: " K-Builder-Watch will watch k_builder files and when they change,
14
70
  execute them\n"
15
71
  email:
@@ -22,6 +78,7 @@ files:
22
78
  - ".gitignore"
23
79
  - ".rspec"
24
80
  - ".rubocop.yml"
81
+ - ".vscode/settings.json"
25
82
  - CODE_OF_CONDUCT.md
26
83
  - Gemfile
27
84
  - Guardfile
@@ -34,12 +91,15 @@ files:
34
91
  - bin/k
35
92
  - bin/kgitsync
36
93
  - bin/khotfix
94
+ - bin/run
37
95
  - bin/setup
38
96
  - hooks/pre-commit
39
97
  - hooks/update-version
40
98
  - k_builder-watch.gemspec
41
99
  - lib/k_builder/watch.rb
100
+ - lib/k_builder/watch/cli.rb
42
101
  - lib/k_builder/watch/version.rb
102
+ - lib/k_builder/watch/watcher.rb
43
103
  homepage: http://appydave.com/gems/k-builder-watch
44
104
  licenses:
45
105
  - MIT