k_builder-watch 0.0.2 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.vscode/settings.json +5 -0
- data/Rakefile +18 -2
- data/bin/console +1 -1
- data/bin/run +17 -0
- data/exe/kw +17 -0
- data/k_builder-watch.gemspec +5 -2
- data/lib/k_builder/watch.rb +2 -2
- data/lib/k_builder/watch/cli.rb +137 -0
- data/lib/k_builder/watch/version.rb +1 -1
- data/lib/k_builder/watch/watcher.rb +54 -0
- metadata +66 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ffba6b210249e0a99bb8095803c1df6e215e499f0f841525ab87be0bb7326cb2
|
4
|
+
data.tar.gz: f1ae33a4e14004351b27a09120a7baa58cb5b3277dbfa2f77ac39bd46b967b20
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a82f58fedc9e4a1d30d11b9fe9cd5f8a6595d0c05cbdabf698da0bebea1ecf61d68b7b8126bbad47fed00b85df7db3750bad01df3ecf122880e00d339dca2376
|
7
|
+
data.tar.gz: d0a10ab980f218d39423140b16a0a8a2934ccf046bdc7378312c8d46756c5c593e4c8e1b78ccf08fadca244a10c951892d6612d09f211b2b1c67417cc5310112
|
data/Rakefile
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# source: https://stephenagrice.medium.com/making-a-command-line-ruby-gem-write-build-and-push-aec24c6c49eb
|
4
|
+
|
5
|
+
GEM_NAME = 'k_builder-watch'
|
6
|
+
|
3
7
|
require 'bundler/gem_tasks'
|
4
8
|
require 'rspec/core/rake_task'
|
9
|
+
require 'k_builder/watch/version'
|
5
10
|
|
6
11
|
RSpec::Core::RakeTask.new(:spec)
|
7
12
|
|
@@ -10,8 +15,19 @@ require 'rake/extensiontask'
|
|
10
15
|
desc 'Compile all the extensions'
|
11
16
|
task build: :compile
|
12
17
|
|
13
|
-
Rake::ExtensionTask.new(
|
14
|
-
ext.lib_dir = 'lib/
|
18
|
+
Rake::ExtensionTask.new(GEM_NAME) do |ext|
|
19
|
+
ext.lib_dir = 'lib/k_builder/watch'
|
20
|
+
end
|
21
|
+
|
22
|
+
desc 'Publish the gem to RubyGems.org'
|
23
|
+
task :publish do
|
24
|
+
system 'gem build'
|
25
|
+
system "gem push #{GEM_NAME}-#{KBuilder::Watch::VERSION}.gem"
|
26
|
+
end
|
27
|
+
|
28
|
+
desc 'Remove old *.gem files'
|
29
|
+
task :clean do
|
30
|
+
system 'rm *.gem'
|
15
31
|
end
|
16
32
|
|
17
33
|
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 '
|
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
|
data/exe/kw
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
|
data/k_builder-watch.gemspec
CHANGED
@@ -36,7 +36,10 @@ 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/
|
39
|
+
# spec.extensions = ['ext/k_builder/watch/extconf.rb']
|
40
40
|
|
41
|
-
|
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'
|
42
45
|
end
|
data/lib/k_builder/watch.rb
CHANGED
@@ -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
|
@@ -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,20 +1,77 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: k_builder-watch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
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-
|
12
|
-
dependencies:
|
11
|
+
date: 2021-03-24 00:00:00.000000000 Z
|
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:
|
16
72
|
- david@ideasmen.com.au
|
17
|
-
executables:
|
73
|
+
executables:
|
74
|
+
- kw
|
18
75
|
extensions: []
|
19
76
|
extra_rdoc_files: []
|
20
77
|
files:
|
@@ -22,6 +79,7 @@ files:
|
|
22
79
|
- ".gitignore"
|
23
80
|
- ".rspec"
|
24
81
|
- ".rubocop.yml"
|
82
|
+
- ".vscode/settings.json"
|
25
83
|
- CODE_OF_CONDUCT.md
|
26
84
|
- Gemfile
|
27
85
|
- Guardfile
|
@@ -34,12 +92,16 @@ files:
|
|
34
92
|
- bin/k
|
35
93
|
- bin/kgitsync
|
36
94
|
- bin/khotfix
|
95
|
+
- bin/run
|
37
96
|
- bin/setup
|
97
|
+
- exe/kw
|
38
98
|
- hooks/pre-commit
|
39
99
|
- hooks/update-version
|
40
100
|
- k_builder-watch.gemspec
|
41
101
|
- lib/k_builder/watch.rb
|
102
|
+
- lib/k_builder/watch/cli.rb
|
42
103
|
- lib/k_builder/watch/version.rb
|
104
|
+
- lib/k_builder/watch/watcher.rb
|
43
105
|
homepage: http://appydave.com/gems/k-builder-watch
|
44
106
|
licenses:
|
45
107
|
- MIT
|