bunto-watch 1.0.0
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 +7 -0
- data/lib/bunto-watch.rb +2 -0
- data/lib/bunto/commands/watch.rb +28 -0
- data/lib/bunto/watcher.rb +104 -0
- metadata +147 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0d4b98805e89224a1e9e541261229c977e619e9d
|
4
|
+
data.tar.gz: de0872346252a32b53592875495158e23d102b53
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5b239aa37a7b56eb029391cd4a1c9143899fe69a3972d812eab7a40ad66546ca7edf858c756514dc3c3b42f3da0fd57cacbb38af422711403898130447f0d7c3
|
7
|
+
data.tar.gz: 15f1fc033d27c56fe4ae7719bcccd6c070a4037b1c6c969d2d4887fb6f291c62d7657ae1a544e7904b325fa9f9cacc6dd52747c5efc00da4a0f0784badf86e28
|
data/lib/bunto-watch.rb
ADDED
@@ -0,0 +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
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'listen'
|
2
|
+
|
3
|
+
module Bunto
|
4
|
+
module Watcher
|
5
|
+
extend self
|
6
|
+
|
7
|
+
def watch(options)
|
8
|
+
ENV["LISTEN_GEM_DEBUGGING"] ||= "1" if options['verbose']
|
9
|
+
|
10
|
+
site = Bunto::Site.new(options)
|
11
|
+
listener = build_listener(site, options)
|
12
|
+
listener.start
|
13
|
+
|
14
|
+
Bunto.logger.info "Auto-regeneration:", "enabled for '#{options["source"]}'"
|
15
|
+
|
16
|
+
unless options['serving']
|
17
|
+
trap("INT") do
|
18
|
+
listener.stop
|
19
|
+
puts " Halting auto-regeneration."
|
20
|
+
exit 0
|
21
|
+
end
|
22
|
+
|
23
|
+
sleep_forever
|
24
|
+
end
|
25
|
+
rescue ThreadError
|
26
|
+
# You pressed Ctrl-C, oh my!
|
27
|
+
end
|
28
|
+
|
29
|
+
# TODO: shouldn't be public API
|
30
|
+
def build_listener(site, options)
|
31
|
+
Listen.to(
|
32
|
+
options['source'],
|
33
|
+
:ignore => listen_ignore_paths(options),
|
34
|
+
:force_polling => options['force_polling'],
|
35
|
+
&(listen_handler(site))
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
39
|
+
def listen_handler(site)
|
40
|
+
proc do |modified, added, removed|
|
41
|
+
t = Time.now
|
42
|
+
c = modified + added + removed
|
43
|
+
n = c.length
|
44
|
+
print Bunto.logger.message("Regenerating:",
|
45
|
+
"#{n} file(s) changed at #{t.strftime("%Y-%m-%d %H:%M:%S")} ")
|
46
|
+
begin
|
47
|
+
site.process
|
48
|
+
puts "...done in #{Time.now - t} seconds."
|
49
|
+
rescue => e
|
50
|
+
puts "...error:"
|
51
|
+
Bunto.logger.warn "Error:", e.message
|
52
|
+
Bunto.logger.warn "Error:", "Run bunto build --trace for more information."
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def custom_excludes(options)
|
58
|
+
Array(options['exclude']).map { |e| Bunto.sanitized_path(options['source'], e) }
|
59
|
+
end
|
60
|
+
|
61
|
+
def config_files(options)
|
62
|
+
%w(yml yaml toml).map do |ext|
|
63
|
+
Bunto.sanitized_path(options['source'], "_config.#{ext}")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def to_exclude(options)
|
68
|
+
[
|
69
|
+
config_files(options),
|
70
|
+
options['destination'],
|
71
|
+
custom_excludes(options)
|
72
|
+
].flatten
|
73
|
+
end
|
74
|
+
|
75
|
+
# Paths to ignore for the watch option
|
76
|
+
#
|
77
|
+
# options - A Hash of options passed to the command
|
78
|
+
#
|
79
|
+
# Returns a list of relative paths from source that should be ignored
|
80
|
+
def listen_ignore_paths(options)
|
81
|
+
source = Pathname.new(options['source']).expand_path
|
82
|
+
paths = to_exclude(options)
|
83
|
+
|
84
|
+
paths.map do |p|
|
85
|
+
absolute_path = Pathname.new(p).expand_path
|
86
|
+
next unless absolute_path.exist?
|
87
|
+
begin
|
88
|
+
relative_path = absolute_path.relative_path_from(source).to_s
|
89
|
+
unless relative_path.start_with?('../')
|
90
|
+
path_to_ignore = Regexp.new(Regexp.escape(relative_path))
|
91
|
+
Bunto.logger.debug "Watcher:", "Ignoring #{path_to_ignore}"
|
92
|
+
path_to_ignore
|
93
|
+
end
|
94
|
+
rescue ArgumentError
|
95
|
+
# Could not find a relative path
|
96
|
+
end
|
97
|
+
end.compact + [/\.bunto\-metadata/]
|
98
|
+
end
|
99
|
+
|
100
|
+
def sleep_forever
|
101
|
+
loop { sleep 1000 }
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
metadata
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bunto-watch
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Parker Moore
|
8
|
+
- Suriyaa Kudo
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2016-02-07 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: listen
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '3.0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '3.0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: wdm
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 0.1.0
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 0.1.0
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: bundler
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '1.6'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '1.6'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rubocop
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 0.35.1
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 0.35.1
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rake
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: rspec
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - "~>"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '3.0'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '3.0'
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: bunto
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '2.0'
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '2.0'
|
112
|
+
description:
|
113
|
+
email:
|
114
|
+
- parkrmoore@gmail.com
|
115
|
+
- SuriyaaKudoIsc@users.noreply.github.com
|
116
|
+
executables: []
|
117
|
+
extensions: []
|
118
|
+
extra_rdoc_files: []
|
119
|
+
files:
|
120
|
+
- lib/bunto-watch.rb
|
121
|
+
- lib/bunto/commands/watch.rb
|
122
|
+
- lib/bunto/watcher.rb
|
123
|
+
homepage: https://github.com/bunto/bunto-watch
|
124
|
+
licenses:
|
125
|
+
- MIT
|
126
|
+
metadata: {}
|
127
|
+
post_install_message:
|
128
|
+
rdoc_options: []
|
129
|
+
require_paths:
|
130
|
+
- lib
|
131
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '0'
|
141
|
+
requirements: []
|
142
|
+
rubyforge_project:
|
143
|
+
rubygems_version: 2.2.2
|
144
|
+
signing_key:
|
145
|
+
specification_version: 4
|
146
|
+
summary: Rebuild your Bunto site when a file changes with the `--watch` switch.
|
147
|
+
test_files: []
|