filewatcher 0.5.4 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/banner.txt +17 -0
- data/bin/filewatcher +61 -124
- data/lib/filewatcher.rb +69 -122
- data/lib/filewatcher/cycles.rb +47 -0
- data/lib/filewatcher/env.rb +29 -0
- data/lib/filewatcher/runner.rb +33 -0
- data/lib/filewatcher/version.rb +7 -0
- data/test/dumpers/env_dumper.rb +10 -0
- data/test/dumpers/watched_dumper.rb +5 -0
- data/test/filewatcher/test_env.rb +70 -0
- data/test/filewatcher/test_runner.rb +75 -0
- data/test/filewatcher/test_version.rb +13 -0
- data/test/helper.rb +134 -0
- data/test/test_filewatcher.rb +266 -142
- metadata +30 -22
- data/LICENSE +0 -20
- data/README.md +0 -269
- data/Rakefile +0 -19
- data/test/fixtures/file1.txt +0 -1
- data/test/fixtures/file2.txt +0 -1
- data/test/fixtures/file3.rb +0 -1
- data/test/fixtures/file4.rb +0 -1
- data/test/fixtures/subdir/file5.rb +0 -1
- data/test/fixtures/subdir/file6.rb +0 -1
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: filewatcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Flemming
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-09-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: trollop
|
@@ -16,28 +16,34 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '2.
|
19
|
+
version: '2.1'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 2.1.2
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
27
|
- - "~>"
|
25
28
|
- !ruby/object:Gem::Version
|
26
|
-
version: '2.
|
29
|
+
version: '2.1'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.1.2
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: rake
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
30
36
|
requirements:
|
31
37
|
- - "~>"
|
32
38
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
39
|
+
version: '12.0'
|
34
40
|
type: :development
|
35
41
|
prerelease: false
|
36
42
|
version_requirements: !ruby/object:Gem::Requirement
|
37
43
|
requirements:
|
38
44
|
- - "~>"
|
39
45
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
46
|
+
version: '12.0'
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
48
|
name: bacon
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -60,17 +66,19 @@ executables:
|
|
60
66
|
extensions: []
|
61
67
|
extra_rdoc_files: []
|
62
68
|
files:
|
63
|
-
-
|
64
|
-
- README.md
|
65
|
-
- Rakefile
|
69
|
+
- bin/banner.txt
|
66
70
|
- bin/filewatcher
|
67
71
|
- lib/filewatcher.rb
|
68
|
-
-
|
69
|
-
-
|
70
|
-
-
|
71
|
-
-
|
72
|
-
- test/
|
73
|
-
- test/
|
72
|
+
- lib/filewatcher/cycles.rb
|
73
|
+
- lib/filewatcher/env.rb
|
74
|
+
- lib/filewatcher/runner.rb
|
75
|
+
- lib/filewatcher/version.rb
|
76
|
+
- test/dumpers/env_dumper.rb
|
77
|
+
- test/dumpers/watched_dumper.rb
|
78
|
+
- test/filewatcher/test_env.rb
|
79
|
+
- test/filewatcher/test_runner.rb
|
80
|
+
- test/filewatcher/test_version.rb
|
81
|
+
- test/helper.rb
|
74
82
|
- test/test_filewatcher.rb
|
75
83
|
homepage: http://github.com/thomasfl/filewatcher
|
76
84
|
licenses:
|
@@ -92,15 +100,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
100
|
version: '0'
|
93
101
|
requirements: []
|
94
102
|
rubyforge_project:
|
95
|
-
rubygems_version: 2.
|
103
|
+
rubygems_version: 2.6.13
|
96
104
|
signing_key:
|
97
105
|
specification_version: 4
|
98
106
|
summary: Lighweight filewatcher.
|
99
107
|
test_files:
|
100
|
-
- test/
|
101
|
-
- test/
|
102
|
-
- test/
|
103
|
-
- test/
|
104
|
-
- test/
|
105
|
-
- test/
|
108
|
+
- test/dumpers/env_dumper.rb
|
109
|
+
- test/dumpers/watched_dumper.rb
|
110
|
+
- test/filewatcher/test_env.rb
|
111
|
+
- test/filewatcher/test_runner.rb
|
112
|
+
- test/filewatcher/test_version.rb
|
113
|
+
- test/helper.rb
|
106
114
|
- test/test_filewatcher.rb
|
data/LICENSE
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
Copyright (c) 2009 - 2014 Thomas Flemming
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
-
a copy of this software and associated documentation files (the
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
the following conditions:
|
10
|
-
|
11
|
-
The above copyright notice and this permission notice shall be
|
12
|
-
included in all copies or substantial portions of the Software.
|
13
|
-
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
DELETED
@@ -1,269 +0,0 @@
|
|
1
|
-
Filewatcher
|
2
|
-
===========
|
3
|
-
|
4
|
-
[![Gem Version](https://badge.fury.io/rb/filewatcher.svg)](http://badge.fury.io/rb/filewatcher)
|
5
|
-
[![Build Status](https://secure.travis-ci.org/thomasfl/filewatcher.png?branch=master)](http://travis-ci.org/thomasfl/filewatcher)
|
6
|
-
[![Dependency Status](https://gemnasium.com/thomasfl/filewatcher.png?travis)](https://gemnasium.com/thomasfl/filewatcher)
|
7
|
-
[![Code Climate](https://codeclimate.com/github/thomasfl/filewatcher.png)](https://codeclimate.com/github/thomasfl/filewatcher)
|
8
|
-
|
9
|
-
Lightweight filewatcher weighing less than 200 LoC. No dependencies or platform specific code. Works everywhere. Monitors changes in the filesystem by polling. Has no config files. When running filewatcher from the command line, you specify which files to monitor and what action to perform on updates.
|
10
|
-
|
11
|
-
For example to search recursively for javascript files and run jshint when a file is updated, added, renamed or deleted:
|
12
|
-
|
13
|
-
Linux/OSX:
|
14
|
-
|
15
|
-
$ filewatcher '**/*.js' 'jshint $FILENAME'
|
16
|
-
|
17
|
-
In Windows:
|
18
|
-
|
19
|
-
> filewatcher "**/*.js" "jshint %FILENAME%"
|
20
|
-
|
21
|
-
Install
|
22
|
-
-------
|
23
|
-
|
24
|
-
Needs Ruby and Rubygems:
|
25
|
-
|
26
|
-
$ [sudo] gem install filewatcher
|
27
|
-
|
28
|
-
Command line utility
|
29
|
-
--------------------
|
30
|
-
|
31
|
-
Filewatcher scans the filesystem and execute shell commands when files are
|
32
|
-
updated, added, renamed or deleted.
|
33
|
-
|
34
|
-
Usage:
|
35
|
-
filewatcher [--restart][--list][--dontwait] "<filename>" "<shell command>"
|
36
|
-
|
37
|
-
Where
|
38
|
-
filename: filename(s) to scan.
|
39
|
-
shell command: shell command to execute when a file is changed
|
40
|
-
|
41
|
-
Examples
|
42
|
-
--------
|
43
|
-
|
44
|
-
Run the echo command when the file myfile is changed:
|
45
|
-
|
46
|
-
$ filewatcher "myfile" "echo 'myfile has changed'"
|
47
|
-
|
48
|
-
Run any javascript in the current directory when it is updated in Windows
|
49
|
-
Powershell:
|
50
|
-
|
51
|
-
> filewatcher *.js "node %FILENAME%"
|
52
|
-
|
53
|
-
In Linux/OSX:
|
54
|
-
|
55
|
-
$ filewatcher *.js 'node $FILENAME'
|
56
|
-
|
57
|
-
Place filenames or filenames in quotes to use ruby filename globbing instead
|
58
|
-
of shell filename globbing. This will make filewatcher look for files in
|
59
|
-
subdirectories too. To watch all javascript files in subdirectories in Windows:
|
60
|
-
|
61
|
-
> filewatcher "**/*.js" "node %FILENAME%"
|
62
|
-
|
63
|
-
In Linux/OSX:
|
64
|
-
|
65
|
-
> filewatcher '**/*.js' 'node $FILENAME'
|
66
|
-
|
67
|
-
Try to run the updated file as a script when it is updated by using the
|
68
|
-
--exec/-e option. Works with files with file extensions that looks like a
|
69
|
-
python, ruby, perl, php, javascript or awk script.
|
70
|
-
|
71
|
-
$ filewatcher -e *.rb
|
72
|
-
|
73
|
-
Print a list of all files matching *.css first and then output the filename
|
74
|
-
when a file is beeing updated by using the --list/-l option:
|
75
|
-
|
76
|
-
$ filewatcher -l '**/*.css' 'echo file: $FILENAME'
|
77
|
-
|
78
|
-
Watch the "src" and "test" folders recursively, and run test when the
|
79
|
-
filesystem gets updated:
|
80
|
-
|
81
|
-
$ filewatcher "src test" "ruby test/test_suite.rb"
|
82
|
-
|
83
|
-
Restart long running commands
|
84
|
-
-----------------------------
|
85
|
-
|
86
|
-
The `--restart` option kills the command if it's still running when a filesystem change happens. Can be used to restart locally running webservers on updates, or kill long running tests and restart on updates. This option often makes filewatcher faster in general. To not wait for tests to finish:
|
87
|
-
|
88
|
-
$ filewatcher --restart "**/*.rb" "rake test"
|
89
|
-
|
90
|
-
The `--dontwait` option starts the command on startup without waiting for filesystem updates. To start a webserver and have it automatically restart when html files are updated:
|
91
|
-
|
92
|
-
$ filewatcher --restart --dontwait "**/*.html" "python -m SimpleHTTPServer"
|
93
|
-
|
94
|
-
Available enviroment variables
|
95
|
-
------------------------------
|
96
|
-
|
97
|
-
The environment variable $FILENAME is available in the shell command argument.
|
98
|
-
On unix like systems the command has to be enclosed in single quotes. To run
|
99
|
-
node whenever a javascript file is updated:
|
100
|
-
|
101
|
-
$ filewatcher *.js 'node $FILENAME'
|
102
|
-
|
103
|
-
Environment variables available from the command string:
|
104
|
-
|
105
|
-
BASENAME File basename.
|
106
|
-
FILENAME Relative filename.
|
107
|
-
ABSOLUTE_FILENAME Asolute filename.
|
108
|
-
RELATIVE_FILENAME Same as FILENAME but starts with "./"
|
109
|
-
EVENT Event type. Is either 'changed', 'delete' or 'new'.
|
110
|
-
DIRNAME Absolute directory name.
|
111
|
-
|
112
|
-
Command line options
|
113
|
-
--------------------
|
114
|
-
|
115
|
-
Useful command line options:
|
116
|
-
|
117
|
-
--list, -l: Print name of matching files on startup
|
118
|
-
--restart, -r: Run command in separate fork and kill it on filesystem updates
|
119
|
-
--dontwait, -d: Run the command before any filesystem updates
|
120
|
-
--spinner, -s: Display an animated spinner while scanning
|
121
|
-
|
122
|
-
Other command line options:
|
123
|
-
|
124
|
-
--version, -v: Print version and exit
|
125
|
-
--help, -h: Show this message
|
126
|
-
--interval, -i <f>: Interval in seconds to scan filesystem. Defaults to 0.5 seconds.
|
127
|
-
--exec, -e: Execute file as a script when file is updated
|
128
|
-
--include, -n <s>: Include files (default: *)
|
129
|
-
--exclude, -x <s>: Exclude file(s) matching (default: "")
|
130
|
-
|
131
|
-
Ruby API
|
132
|
-
--------
|
133
|
-
|
134
|
-
Watch a list of files and directories:
|
135
|
-
|
136
|
-
require 'filewatcher'
|
137
|
-
|
138
|
-
FileWatcher.new(["lib/", "Rakefile"]).watch do |filename|
|
139
|
-
puts "Changed " + filename
|
140
|
-
end
|
141
|
-
|
142
|
-
Watch a single directory, for changes in all files and subdirectories:
|
143
|
-
|
144
|
-
FileWatcher.new("lib/").watch do |filename|
|
145
|
-
...
|
146
|
-
end
|
147
|
-
|
148
|
-
Notice that the previous is equivalent to the following:
|
149
|
-
|
150
|
-
FileWatcher.new("lib/**/*").watch do |filename|
|
151
|
-
...
|
152
|
-
end
|
153
|
-
|
154
|
-
Watch files and dirs in the given directory - and not in subdirectories:
|
155
|
-
|
156
|
-
FileWatcher.new("lib/*").watch do |filename|
|
157
|
-
...
|
158
|
-
end
|
159
|
-
|
160
|
-
Watch an absolute directory:
|
161
|
-
|
162
|
-
FileWatcher.new("/tmp/foo").watch do |filename|
|
163
|
-
...
|
164
|
-
end
|
165
|
-
|
166
|
-
To detect if a file is updated, added or deleted:
|
167
|
-
|
168
|
-
FileWatcher.new(["README.rdoc"]).watch() do |filename, event|
|
169
|
-
if(event == :changed)
|
170
|
-
puts "File updated: " + filename
|
171
|
-
end
|
172
|
-
if(event == :delete)
|
173
|
-
puts "File deleted: " + filename
|
174
|
-
end
|
175
|
-
if(event == :new)
|
176
|
-
puts "Added file: " + filename
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
When a file is renamed it is detected as a new file followed by a file deletion.
|
181
|
-
|
182
|
-
The API takes some of the same options as the command line interface. To watch all files recursively except files that matches *.rb, display a spinner and only wait for 0.1 seconds between each scan:
|
183
|
-
|
184
|
-
FileWatcher.new('**/*.*', exclude: '**/*.rb', spinner: true, interval: 0.1).watch() do |filename|
|
185
|
-
puts filename
|
186
|
-
end
|
187
|
-
|
188
|
-
To do the same from the command line, use the same options:
|
189
|
-
|
190
|
-
$ filewatcher '**/*.*' --exclude '**/*.rb' --spinner --interval 0.1 'echo $FILENAME'
|
191
|
-
|
192
|
-
Use patterns to match filenames in current directory and subdirectories. The
|
193
|
-
pattern is not a regular expression; instead it follows rules similar to shell
|
194
|
-
filename globbing. See Ruby
|
195
|
-
[documentation](http://www.ruby-doc.org/core-2.1.1/File.html#method-c-fnmatch)
|
196
|
-
for syntax.
|
197
|
-
|
198
|
-
FileWatcher.new(["*.rb", "*.xml"]).watch do |filename|
|
199
|
-
puts "Updated " + filename
|
200
|
-
end
|
201
|
-
|
202
|
-
Start, pause, resume, stop, and finalize a running watch. This is particularly
|
203
|
-
useful when the update block takes a while to process each file (eg. sending
|
204
|
-
over the network)
|
205
|
-
|
206
|
-
filewatcher = FileWatcher.new(["*.rb"])
|
207
|
-
thread = Thread.new(filewatcher){|fw| fw.watch{|f| puts "Updated " + f}}
|
208
|
-
...
|
209
|
-
filewatcher.pause # block stops responding to filesystem changes
|
210
|
-
filewatcher.finalize # Ensure all filesystem changes made prior to
|
211
|
-
# pausing are handled.
|
212
|
-
...
|
213
|
-
filewatcher.resume # block begins responding again, but is not given
|
214
|
-
# changes made between #pause_watch and
|
215
|
-
# #resume_watch
|
216
|
-
...
|
217
|
-
filewatcher.end # block stops responding to filesystem changes
|
218
|
-
# and takes a final snapshot of the filesystem
|
219
|
-
thread.join
|
220
|
-
|
221
|
-
filewatcher.finalize # Ensure all filesystem changes made prior to
|
222
|
-
# ending the watch are handled.
|
223
|
-
|
224
|
-
If basename, relative filename or absolute filename is necessary use the standard lib 'pathname' like this:
|
225
|
-
|
226
|
-
require 'pathname'
|
227
|
-
|
228
|
-
FileWatcher.new(["**/*.*"]).watch() do |filename|
|
229
|
-
path = Pathname.new(filename)
|
230
|
-
puys "Basename : " + path.basename.to_s
|
231
|
-
puts "Relative filename: " + File.join(Pathname.new('.').to_s, path.to_s)
|
232
|
-
puts "Absolute filename: " + File.join(Pathname.new('.').realpath.to_s, path.to_s)
|
233
|
-
end
|
234
|
-
|
235
|
-
The filewatcher library is a single file with 180 LOC (including comments)
|
236
|
-
with no dependencies.
|
237
|
-
|
238
|
-
Changelog
|
239
|
-
---------
|
240
|
-
* 0.5.3 Exclude files. More environment variables. Options in ruby api.
|
241
|
-
* 0.5.2 Start, stop and finalize API.
|
242
|
-
* 0.5.1 Kill and restart long running command with --restart option.
|
243
|
-
|
244
|
-
Credits
|
245
|
-
-------
|
246
|
-
This project would not be where it is today without the generous help provided by people reporting issues and these contributors:
|
247
|
-
|
248
|
-
* Penn Taylor: Spinner displayed in the terminal and Start, pause, resume, stop, and finalize a running watch.
|
249
|
-
|
250
|
-
* Franco Leonardo Bulgarelli: Support for absolute and globbed paths by https://github.com/flbulgarelli
|
251
|
-
|
252
|
-
* Kristoffer Roupé https://github.com/kitofr Command line globbing by
|
253
|
-
|
254
|
-
This gem was initially inspired by Tom Lieber's blogg posting: http://alltom.com/pages/detecting-file-changes-with-ruby
|
255
|
-
|
256
|
-
Note on Patches/Pull Requests
|
257
|
-
-----------------------------
|
258
|
-
|
259
|
-
* Fork the project.
|
260
|
-
* Make your feature addition or bug fix.
|
261
|
-
* Add tests for it. This is important so I don't break it in a future version unintentionally.
|
262
|
-
* Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
263
|
-
* Send me a pull request. Bonus points for topic branches.
|
264
|
-
|
265
|
-
|
266
|
-
Copyright
|
267
|
-
---------
|
268
|
-
|
269
|
-
Copyright (c) 2011 - 2015 Thomas Flemming. See LICENSE for details.
|
data/Rakefile
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'rake'
|
3
|
-
require 'rake/testtask'
|
4
|
-
|
5
|
-
task :default => :test
|
6
|
-
|
7
|
-
desc "Run tests"
|
8
|
-
task :test do
|
9
|
-
sh "bacon -Ilib -Itest --automatic --quiet"
|
10
|
-
delete_list =
|
11
|
-
%w(test/fixtures/file3.txt
|
12
|
-
test/fixtures/file4.txt
|
13
|
-
test/fixtures/file5.txt
|
14
|
-
test/fixtures/file6.txt
|
15
|
-
test/fixtures/file7.txt)
|
16
|
-
delete_list.each do |file|
|
17
|
-
FileUtils.rm(file)
|
18
|
-
end
|
19
|
-
end
|
data/test/fixtures/file1.txt
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
content1
|
data/test/fixtures/file2.txt
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
content2
|
data/test/fixtures/file3.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
|
data/test/fixtures/file4.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
puts "Hello world from Ruby!!!"
|
@@ -1 +0,0 @@
|
|
1
|
-
|
@@ -1 +0,0 @@
|
|
1
|
-
puts "This is file6.rb executing"
|