bunto-watch 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bunto-watch.rb +2 -2
- data/lib/bunto/commands/watch.rb +28 -28
- data/lib/bunto/watcher.rb +116 -104
- metadata +9 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1bf6f85dc0309457abed8306b761b5b7dd1d962
|
4
|
+
data.tar.gz: 6ada62fd9f25e790ac937be5619cec850cf677ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa8689e769de92e82466ef1108845aa160a4fce439f2b0d00dc4477c77dd40186ae266f09f173cf4275901537ec77de7b9738507d33f857fc7f6285567e95806
|
7
|
+
data.tar.gz: 3c303842d8d1110158f3bf9d04cb6d8b2e8f50c02ccbf1ce6439d5a2609e34fb63cd1bf9b3f10d1b32d32fb5796b918006806b5903d4ec951a57335581f4f1e3
|
data/lib/bunto-watch.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
require_relative "bunto/watcher"
|
2
|
-
require_relative "bunto/commands/watch"
|
1
|
+
require_relative "bunto/watcher"
|
2
|
+
require_relative "bunto/commands/watch"
|
data/lib/bunto/commands/watch.rb
CHANGED
@@ -1,28 +1,28 @@
|
|
1
|
-
module Bunto
|
2
|
-
module Commands
|
3
|
-
module Watch
|
4
|
-
extend self
|
5
|
-
|
6
|
-
def init_with_program(prog)
|
7
|
-
end
|
8
|
-
|
9
|
-
# Build your bunto site
|
10
|
-
# Continuously watch if `watch` is set to true in the config.
|
11
|
-
def process(options)
|
12
|
-
Bunto.logger.log_level = :error if options['quiet']
|
13
|
-
watch(site, options) if options['watch']
|
14
|
-
end
|
15
|
-
|
16
|
-
# Watch for file changes and rebuild the site.
|
17
|
-
#
|
18
|
-
# site - A Bunto::Site instance
|
19
|
-
# options - A Hash of options passed to the command
|
20
|
-
#
|
21
|
-
# Returns nothing.
|
22
|
-
def watch(_site, options)
|
23
|
-
Bunto::Watcher.watch(options)
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
1
|
+
module Bunto
|
2
|
+
module Commands
|
3
|
+
module Watch
|
4
|
+
extend self
|
5
|
+
|
6
|
+
def init_with_program(prog)
|
7
|
+
end
|
8
|
+
|
9
|
+
# Build your bunto site
|
10
|
+
# Continuously watch if `watch` is set to true in the config.
|
11
|
+
def process(options)
|
12
|
+
Bunto.logger.log_level = :error if options['quiet']
|
13
|
+
watch(site, options) if options['watch']
|
14
|
+
end
|
15
|
+
|
16
|
+
# Watch for file changes and rebuild the site.
|
17
|
+
#
|
18
|
+
# site - A Bunto::Site instance
|
19
|
+
# options - A Hash of options passed to the command
|
20
|
+
#
|
21
|
+
# Returns nothing.
|
22
|
+
def watch(_site, options)
|
23
|
+
Bunto::Watcher.watch(options)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/bunto/watcher.rb
CHANGED
@@ -1,104 +1,116 @@
|
|
1
|
-
require 'listen'
|
2
|
-
|
3
|
-
module Bunto
|
4
|
-
module Watcher
|
5
|
-
extend self
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
1
|
+
require 'listen'
|
2
|
+
|
3
|
+
module Bunto
|
4
|
+
module Watcher
|
5
|
+
extend self
|
6
|
+
|
7
|
+
# Public: Continuously watch for file changes and rebuild the site
|
8
|
+
# whenever a change is detected.
|
9
|
+
#
|
10
|
+
# If the optional site argument is populated, that site instance will be
|
11
|
+
# reused and the options Hash ignored. Otherwise, a new site instance will
|
12
|
+
# be instantiated from the options Hash and used.
|
13
|
+
#
|
14
|
+
# options - A Hash containing the site configuration
|
15
|
+
# site - The current site instance (populated starting with Bunto 3.2)
|
16
|
+
# (optional, default: nil)
|
17
|
+
#
|
18
|
+
# Returns nothing.
|
19
|
+
def watch(options, site = nil)
|
20
|
+
ENV["LISTEN_GEM_DEBUGGING"] ||= "1" if options['verbose']
|
21
|
+
|
22
|
+
site ||= Bunto::Site.new(options)
|
23
|
+
listener = build_listener(site, options)
|
24
|
+
listener.start
|
25
|
+
|
26
|
+
Bunto.logger.info "Auto-regeneration:", "enabled for '#{options["source"]}'"
|
27
|
+
|
28
|
+
unless options['serving']
|
29
|
+
trap("INT") do
|
30
|
+
listener.stop
|
31
|
+
puts " Halting auto-regeneration."
|
32
|
+
exit 0
|
33
|
+
end
|
34
|
+
|
35
|
+
sleep_forever
|
36
|
+
end
|
37
|
+
rescue ThreadError
|
38
|
+
# You pressed Ctrl-C, oh my!
|
39
|
+
end
|
40
|
+
|
41
|
+
# TODO: shouldn't be public API
|
42
|
+
def build_listener(site, options)
|
43
|
+
Listen.to(
|
44
|
+
options['source'],
|
45
|
+
:ignore => listen_ignore_paths(options),
|
46
|
+
:force_polling => options['force_polling'],
|
47
|
+
&(listen_handler(site))
|
48
|
+
)
|
49
|
+
end
|
50
|
+
|
51
|
+
def listen_handler(site)
|
52
|
+
proc do |modified, added, removed|
|
53
|
+
t = Time.now
|
54
|
+
c = modified + added + removed
|
55
|
+
n = c.length
|
56
|
+
print Bunto.logger.message("Regenerating:",
|
57
|
+
"#{n} file(s) changed at #{t.strftime("%Y-%m-%d %H:%M:%S")} ")
|
58
|
+
begin
|
59
|
+
site.process
|
60
|
+
puts "...done in #{Time.now - t} seconds."
|
61
|
+
rescue => e
|
62
|
+
puts "...error:"
|
63
|
+
Bunto.logger.warn "Error:", e.message
|
64
|
+
Bunto.logger.warn "Error:", "Run bunto build --trace for more information."
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def custom_excludes(options)
|
70
|
+
Array(options['exclude']).map { |e| Bunto.sanitized_path(options['source'], e) }
|
71
|
+
end
|
72
|
+
|
73
|
+
def config_files(options)
|
74
|
+
%w(yml yaml toml).map do |ext|
|
75
|
+
Bunto.sanitized_path(options['source'], "_config.#{ext}")
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def to_exclude(options)
|
80
|
+
[
|
81
|
+
config_files(options),
|
82
|
+
options['destination'],
|
83
|
+
custom_excludes(options)
|
84
|
+
].flatten
|
85
|
+
end
|
86
|
+
|
87
|
+
# Paths to ignore for the watch option
|
88
|
+
#
|
89
|
+
# options - A Hash of options passed to the command
|
90
|
+
#
|
91
|
+
# Returns a list of relative paths from source that should be ignored
|
92
|
+
def listen_ignore_paths(options)
|
93
|
+
source = Pathname.new(options['source']).expand_path
|
94
|
+
paths = to_exclude(options)
|
95
|
+
|
96
|
+
paths.map do |p|
|
97
|
+
absolute_path = Pathname.new(p).expand_path
|
98
|
+
next unless absolute_path.exist?
|
99
|
+
begin
|
100
|
+
relative_path = absolute_path.relative_path_from(source).to_s
|
101
|
+
unless relative_path.start_with?('../')
|
102
|
+
path_to_ignore = Regexp.new(Regexp.escape(relative_path))
|
103
|
+
Bunto.logger.debug "Watcher:", "Ignoring #{path_to_ignore}"
|
104
|
+
path_to_ignore
|
105
|
+
end
|
106
|
+
rescue ArgumentError
|
107
|
+
# Could not find a relative path
|
108
|
+
end
|
109
|
+
end.compact + [/\.bunto\-metadata/]
|
110
|
+
end
|
111
|
+
|
112
|
+
def sleep_forever
|
113
|
+
loop { sleep 1000 }
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bunto-watch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Parker Moore
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-08-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: listen
|
@@ -18,6 +18,9 @@ dependencies:
|
|
18
18
|
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
20
|
version: '3.0'
|
21
|
+
- - "<"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '3.1'
|
21
24
|
type: :runtime
|
22
25
|
prerelease: false
|
23
26
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -25,6 +28,9 @@ dependencies:
|
|
25
28
|
- - "~>"
|
26
29
|
- !ruby/object:Gem::Version
|
27
30
|
version: '3.0'
|
31
|
+
- - "<"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.1'
|
28
34
|
- !ruby/object:Gem::Dependency
|
29
35
|
name: wdm
|
30
36
|
requirement: !ruby/object:Gem::Requirement
|
@@ -140,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
146
|
version: '0'
|
141
147
|
requirements: []
|
142
148
|
rubyforge_project:
|
143
|
-
rubygems_version: 2.
|
149
|
+
rubygems_version: 2.6.6
|
144
150
|
signing_key:
|
145
151
|
specification_version: 4
|
146
152
|
summary: Rebuild your Bunto site when a file changes with the `--watch` switch.
|