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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0d4b98805e89224a1e9e541261229c977e619e9d
4
- data.tar.gz: de0872346252a32b53592875495158e23d102b53
3
+ metadata.gz: a1bf6f85dc0309457abed8306b761b5b7dd1d962
4
+ data.tar.gz: 6ada62fd9f25e790ac937be5619cec850cf677ef
5
5
  SHA512:
6
- metadata.gz: 5b239aa37a7b56eb029391cd4a1c9143899fe69a3972d812eab7a40ad66546ca7edf858c756514dc3c3b42f3da0fd57cacbb38af422711403898130447f0d7c3
7
- data.tar.gz: 15f1fc033d27c56fe4ae7719bcccd6c070a4037b1c6c969d2d4887fb6f291c62d7657ae1a544e7904b325fa9f9cacc6dd52747c5efc00da4a0f0784badf86e28
6
+ metadata.gz: fa8689e769de92e82466ef1108845aa160a4fce439f2b0d00dc4477c77dd40186ae266f09f173cf4275901537ec77de7b9738507d33f857fc7f6285567e95806
7
+ data.tar.gz: 3c303842d8d1110158f3bf9d04cb6d8b2e8f50c02ccbf1ce6439d5a2609e34fb63cd1bf9b3f10d1b32d32fb5796b918006806b5903d4ec951a57335581f4f1e3
@@ -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"
@@ -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
@@ -1,104 +1,116 @@
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
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: 1.0.0
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-02-07 00:00:00.000000000 Z
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.2.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.