livereload 1.3 → 1.4
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.
- data/bin/livereload +2 -2
- data/lib/livereload.rb +32 -26
- metadata +5 -6
data/bin/livereload
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#! /usr/bin/env ruby
|
2
2
|
require 'rubygems'
|
3
|
-
require 'livereload'
|
3
|
+
require File.join(File.dirname(__FILE__), '..', 'lib', 'livereload')
|
4
4
|
require 'optparse'
|
5
5
|
|
6
6
|
def parse_command_line_config(args)
|
@@ -16,7 +16,7 @@ def parse_command_line_config(args)
|
|
16
16
|
config.host = v
|
17
17
|
end
|
18
18
|
|
19
|
-
opts.on("--port [PORT]", Integer, "TCP port to listen on (default is
|
19
|
+
opts.on("--port [PORT]", Integer, "TCP port to listen on (default is 35729)") do |v|
|
20
20
|
config.port = v.to_i
|
21
21
|
end
|
22
22
|
|
data/lib/livereload.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'em-websocket'
|
2
|
-
require '
|
2
|
+
require 'em-dir-watcher'
|
3
3
|
require 'json/objects'
|
4
|
+
require 'stringio'
|
4
5
|
|
5
6
|
# Chrome sometimes sends HTTP/1.0 requests in violation of WebSockets spec
|
6
7
|
# hide the warning about redifinition of a constant
|
@@ -20,8 +21,8 @@ class Object
|
|
20
21
|
end
|
21
22
|
|
22
23
|
module LiveReload
|
23
|
-
GEM_VERSION = "1.
|
24
|
-
API_VERSION = "1.
|
24
|
+
GEM_VERSION = "1.4"
|
25
|
+
API_VERSION = "1.4"
|
25
26
|
|
26
27
|
PROJECT_CONFIG_FILE_TEMPLATE = <<-END.strip.split("\n").collect { |line| line.strip + "\n" }.join("")
|
27
28
|
# Lines starting with pound sign (#) are ignored.
|
@@ -40,11 +41,14 @@ module LiveReload
|
|
40
41
|
#config.apply_js_live = false
|
41
42
|
# reload the whole page when .css changes
|
42
43
|
#config.apply_css_live = false
|
44
|
+
|
45
|
+
# wait 100ms for more changes before reloading a page
|
46
|
+
#config.grace_period = 0.1
|
43
47
|
END
|
44
48
|
|
45
49
|
# note that host and port options do not make sense in per-project config files
|
46
50
|
class Config
|
47
|
-
attr_accessor :host, :port, :exts, :exclusions, :debug, :apply_js_live, :apply_css_live
|
51
|
+
attr_accessor :host, :port, :exts, :exts_overwrite, :exclusions, :debug, :apply_js_live, :apply_css_live, :grace_period
|
48
52
|
|
49
53
|
def initialize &block
|
50
54
|
@host = nil
|
@@ -54,13 +58,19 @@ module LiveReload
|
|
54
58
|
@exclusions = []
|
55
59
|
@apply_js_live = nil
|
56
60
|
@apply_css_live = nil
|
61
|
+
@grace_period = nil
|
57
62
|
|
58
63
|
update!(&block) if block
|
59
64
|
end
|
60
65
|
|
61
66
|
def update!
|
67
|
+
@exts = [nil] + @exts # nil is used as a marker to detect if the array has been overwritten
|
68
|
+
|
62
69
|
yield self
|
63
70
|
|
71
|
+
@exts_overwrite = @exts.empty? || ! @exts.first.nil?
|
72
|
+
@exts = @exts.compact
|
73
|
+
|
64
74
|
# remove leading dots
|
65
75
|
@exts = @exts.collect { |e| e.sub(/^\./, '') }
|
66
76
|
end
|
@@ -68,11 +78,16 @@ module LiveReload
|
|
68
78
|
def merge! other
|
69
79
|
@host = other.host if other.host
|
70
80
|
@port = other.port if other.port
|
71
|
-
|
81
|
+
if other.exts_overwrite
|
82
|
+
@exts = other.exts
|
83
|
+
else
|
84
|
+
@exts += other.exts.compact
|
85
|
+
end
|
72
86
|
@exclusions = other.exclusions + @exclusions
|
73
87
|
@debug = other.debug if other.debug != nil
|
74
88
|
@apply_js_live = other.apply_js_live if other.apply_js_live != nil
|
75
89
|
@apply_css_live = other.apply_css_live if other.apply_css_live != nil
|
90
|
+
@grace_period = other.grace_period if other.grace_period != nil
|
76
91
|
|
77
92
|
self
|
78
93
|
end
|
@@ -92,7 +107,7 @@ module LiveReload
|
|
92
107
|
end
|
93
108
|
|
94
109
|
def merge *configs
|
95
|
-
configs.
|
110
|
+
configs.inject(Config.new) { |merged, config| config && merged.merge!(config) || merged }
|
96
111
|
end
|
97
112
|
end
|
98
113
|
end
|
@@ -100,11 +115,12 @@ module LiveReload
|
|
100
115
|
DEFAULT_CONFIG = Config.new do |config|
|
101
116
|
config.debug = false
|
102
117
|
config.host = '0.0.0.0'
|
103
|
-
config.port =
|
118
|
+
config.port = 35729
|
104
119
|
config.exts = %w/html css js png gif jpg php php5 py rb erb/
|
105
120
|
config.exclusions = %w!*/.git/* */.svn/* */.hg/*!
|
106
121
|
config.apply_js_live = true
|
107
122
|
config.apply_css_live = true
|
123
|
+
config.grace_period = 0.05
|
108
124
|
end
|
109
125
|
|
110
126
|
USER_CONFIG_FILE = File.expand_path("~/.livereload")
|
@@ -143,18 +159,8 @@ module LiveReload
|
|
143
159
|
if @config.exclusions.size > 0
|
144
160
|
puts " - excluding changes in: " + @config.exclusions.join(" ")
|
145
161
|
end
|
146
|
-
|
147
|
-
|
148
|
-
def is_excluded? path
|
149
|
-
basename = File.basename(path)
|
150
|
-
@config.exclusions.any? do |exclusion|
|
151
|
-
if Regexp === exclusion
|
152
|
-
path =~ exclusion
|
153
|
-
elsif exclusion.include? '/'
|
154
|
-
File.fnmatch?(File.join(@directory, exclusion), path)
|
155
|
-
else
|
156
|
-
File.fnmatch?(exclusion, basename)
|
157
|
-
end
|
162
|
+
if @config.grace_period > 0
|
163
|
+
puts " - with a grace period of #{sprintf('%0.2f', @config.grace_period)} sec after each change"
|
158
164
|
end
|
159
165
|
end
|
160
166
|
|
@@ -166,15 +172,16 @@ module LiveReload
|
|
166
172
|
if @dw
|
167
173
|
@dw.stop
|
168
174
|
end
|
169
|
-
@dw =
|
170
|
-
|
175
|
+
@dw = EMDirWatcher.watch @directory,
|
176
|
+
:include_only => (['/.livereload'] + @config.exts.collect { |ext| ["*.#{ext}", ".*.#{ext}"]}).flatten,
|
177
|
+
:exclude => @config.exclusions,
|
178
|
+
:grace_period => @config.grace_period do |paths|
|
171
179
|
begin
|
172
|
-
|
173
|
-
path = event[:path]
|
180
|
+
paths.each do |path|
|
174
181
|
if File.basename(path) == '.livereload'
|
175
182
|
@when_changes_detected.call [:config_changed, path]
|
176
|
-
|
177
|
-
@when_changes_detected.call [
|
183
|
+
else
|
184
|
+
@when_changes_detected.call [:modified, path]
|
178
185
|
end
|
179
186
|
end
|
180
187
|
rescue
|
@@ -182,7 +189,6 @@ module LiveReload
|
|
182
189
|
puts $!.backtrace
|
183
190
|
end
|
184
191
|
end
|
185
|
-
@dw.start
|
186
192
|
end
|
187
193
|
end
|
188
194
|
|
metadata
CHANGED
@@ -4,8 +4,8 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 1
|
7
|
-
-
|
8
|
-
version: "1.
|
7
|
+
- 4
|
8
|
+
version: "1.4"
|
9
9
|
platform: ruby
|
10
10
|
authors:
|
11
11
|
- Andrey Tarantsov
|
@@ -31,17 +31,16 @@ dependencies:
|
|
31
31
|
type: :runtime
|
32
32
|
version_requirements: *id001
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
|
-
name:
|
34
|
+
name: em-dir-watcher
|
35
35
|
prerelease: false
|
36
36
|
requirement: &id002 !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
segments:
|
41
|
+
- 0
|
41
42
|
- 1
|
42
|
-
|
43
|
-
- 2
|
44
|
-
version: 1.3.2
|
43
|
+
version: "0.1"
|
45
44
|
type: :runtime
|
46
45
|
version_requirements: *id002
|
47
46
|
- !ruby/object:Gem::Dependency
|