filewatcher 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.rdoc +21 -11
- data/Rakefile +0 -1
- data/VERSION +1 -1
- data/bin/filewatcher +44 -9
- data/lib/filewatcher.rb +1 -1
- data/test/filewatcher_spec.rb +28 -0
- data/test/fixtures/file1.txt +1 -0
- data/test/fixtures/file2.txt +1 -0
- data/test/fixtures/file3.rb +1 -0
- data/test/fixtures/file4.rb +1 -0
- data/test/fixtures/subdir/file5.rb +1 -0
- data/test/fixtures/subdir/file6.rb +1 -0
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24a9b40e9d109eadc83d2299a577b701c376a5c8
|
4
|
+
data.tar.gz: 159e4cf47ace11192f7ccae447008d2af2343a6a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: badd71331331d31b5e2bcd5db3654794332fa629fac3cdf46ae82db47d31f790e8e3952411b347816952433c8aa56864d64154ee1eac1c76feb3a302e27e7844
|
7
|
+
data.tar.gz: fcd7f82251d8dcc1625f9e8e74b5e9c171e3b1d0da493ad5551f3c36f9154fbb98c33f341cdf1656cf2d3c0bac44877bfde2ecc44401768ee1e75c1db32b57a5
|
data/README.rdoc
CHANGED
@@ -24,25 +24,35 @@ Run the echo command when the file myfile is changed:
|
|
24
24
|
|
25
25
|
$ filewatcher "myfile" "echo 'myfile has changed'"
|
26
26
|
|
27
|
-
Run any javascript in the current
|
27
|
+
Run any javascript in the current directory when it is updated in Windows Powershell:
|
28
28
|
|
29
29
|
> filewatcher *.js "node %FILENAME%"
|
30
30
|
|
31
31
|
In Linux/OSX:
|
32
32
|
|
33
|
-
$ filewatcher *.js
|
33
|
+
$ filewatcher *.js 'node $FILENAME'
|
34
|
+
|
35
|
+
Place filenames or filenames in quotes to use ruby filename globbing instead of shell filename globbing. This will make filewatcher look for files in subdirectories too.
|
36
|
+
|
37
|
+
> filewatcher "*.js" "node %FILENAME%"
|
34
38
|
|
39
|
+
In Linux/OSX:
|
35
40
|
|
36
|
-
|
41
|
+
> filewatcher '*.js' 'node $FILENAME'
|
37
42
|
|
38
|
-
|
43
|
+
Try to run the updated file as a script when it is updated by using the --exec/-e option. Works with files with file extensions that looks like a python, ruby, perl, php,
|
44
|
+
javascript or awk script.
|
39
45
|
|
40
|
-
|
46
|
+
$ filewatcher -e *.rb
|
41
47
|
|
42
|
-
Print a list of all files matching *.css first and the
|
48
|
+
Print a list of all files matching *.css first and then output the filename when a file is beeing updated by using the --list/-l option:
|
43
49
|
|
44
50
|
$ filewatcher -l *.css 'echo file: $FILENAME'
|
45
51
|
|
52
|
+
Watch the "src" and "test" folders recursively, and run test when the filesystem gets updated:
|
53
|
+
|
54
|
+
$ filewatcher "src test" "ruby test/test_suite.rb"
|
55
|
+
|
46
56
|
= Available enviroment variables
|
47
57
|
|
48
58
|
The environment variable $FILENAME is available in the command. On unix like systems the command
|
@@ -50,7 +60,7 @@ has to be enclosed in single quotes. To run node whenever a javascript file is u
|
|
50
60
|
|
51
61
|
$ filewatcher *.js 'node $FILENAME'
|
52
62
|
|
53
|
-
The environment variables $FILEPATH and $
|
63
|
+
The environment variables $FILEPATH, $FILEDIR and $FSEVENT is also available.
|
54
64
|
|
55
65
|
= Command line options
|
56
66
|
|
@@ -75,7 +85,7 @@ Watch a list of files and directories:
|
|
75
85
|
puts "Updated " + filename
|
76
86
|
end
|
77
87
|
|
78
|
-
To detect if a file is updated or deleted:
|
88
|
+
To detect if a file is updated, added or deleted:
|
79
89
|
|
80
90
|
FileWatcher.new(["README.rdoc"]).watch() do |filename, event|
|
81
91
|
if(event == :changed)
|
@@ -85,7 +95,7 @@ To detect if a file is updated or deleted:
|
|
85
95
|
puts "File deleted: " + filename
|
86
96
|
end
|
87
97
|
if(event == :new)
|
88
|
-
puts "
|
98
|
+
puts "Added file: " + filename
|
89
99
|
end
|
90
100
|
end
|
91
101
|
|
@@ -95,7 +105,7 @@ To check for changes more often than the default once every second:
|
|
95
105
|
puts "Updated " + filename
|
96
106
|
end
|
97
107
|
|
98
|
-
Print the names of files
|
108
|
+
Print the names of the files found before watching files and folders:
|
99
109
|
|
100
110
|
FileWatcher.new(["lib/"],true).watch do |filename|
|
101
111
|
puts "Updated " + filename
|
@@ -103,7 +113,7 @@ Print the names of files beeing watched before we begin:
|
|
103
113
|
=> Watching files:
|
104
114
|
lib/filewatcher.rb
|
105
115
|
|
106
|
-
Use patterns to match filenames. The pattern is not a regular expression; instead it follows rules similar to shell filename globbing. Se Ruby documentation[http://www.ruby-doc.org/core-2.1.1/File.html#method-c-fnmatch] for syntax.
|
116
|
+
Use patterns to match filenames in current directory and subdirectories. The pattern is not a regular expression; instead it follows rules similar to shell filename globbing. Se Ruby documentation[http://www.ruby-doc.org/core-2.1.1/File.html#method-c-fnmatch] for syntax.
|
107
117
|
|
108
118
|
FileWatcher.new(["*.rb", "*.xml"]).watch do |filename|
|
109
119
|
puts "Updated " + filename
|
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.4
|
data/bin/filewatcher
CHANGED
@@ -17,7 +17,7 @@ Where
|
|
17
17
|
|
18
18
|
Examples:
|
19
19
|
filewatcher "myfile" "echo 'myfile has changed'"
|
20
|
-
filewatcher
|
20
|
+
filewatcher '*.rb' 'ruby $FILENAME'
|
21
21
|
|
22
22
|
Options:
|
23
23
|
EOS
|
@@ -48,19 +48,53 @@ if(options[:recurse])
|
|
48
48
|
files = inc - exc
|
49
49
|
end
|
50
50
|
|
51
|
-
|
51
|
+
def split_files_void_escaped_whitespace(files)
|
52
|
+
splitted_filenames = []
|
53
|
+
files.each do |name|
|
54
|
+
name = name.gsub(/\\\s/,'_ESCAPED_WHITESPACE_')
|
55
|
+
splitted_filenames << name.split(/\s/)
|
56
|
+
end
|
57
|
+
files = splitted_filenames.flatten.uniq
|
58
|
+
splitted_filenames = []
|
59
|
+
files.each do |name|
|
60
|
+
splitted_filenames << name.gsub('_ESCAPED_WHITESPACE_','\ ')
|
61
|
+
end
|
62
|
+
files = splitted_filenames
|
63
|
+
end
|
64
|
+
|
65
|
+
files = split_files_void_escaped_whitespace(files)
|
52
66
|
|
53
67
|
FileWatcher.new(files, options[:list]).watch(options[:interval]) do |filename, event|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
68
|
+
cmd = nil
|
69
|
+
if(options[:exec] and File.exist?(filename))
|
70
|
+
extension = filename[/(\.[^\.]*)$/,0]
|
71
|
+
runners = {
|
72
|
+
".py" => "python",
|
73
|
+
".js" => "node",
|
74
|
+
".rb" => "ruby",
|
75
|
+
".pl" => "perl",
|
76
|
+
".awk" => "awk",
|
77
|
+
".php" => "php",
|
78
|
+
".phtml" => "php",
|
79
|
+
".php4" => "php",
|
80
|
+
".php3" => "php",
|
81
|
+
".php5" => "php",
|
82
|
+
".phps" => "php"
|
83
|
+
}
|
84
|
+
runner = runners[extension]
|
85
|
+
if(runner)
|
86
|
+
cmd = "env #{runner.to_s} #{filename}"
|
87
|
+
end
|
88
|
+
elsif(ARGV.length > 1)
|
60
89
|
cmd = ARGV[-1]
|
90
|
+
end
|
91
|
+
|
92
|
+
if(cmd)
|
93
|
+
path = Pathname.new(filename)
|
61
94
|
env = {
|
62
95
|
'FILENAME'=> path.to_s,
|
63
|
-
'FILEDIR' => path.parent.realpath.to_s
|
96
|
+
'FILEDIR' => path.parent.realpath.to_s,
|
97
|
+
'FSEVENT' => event.to_s
|
64
98
|
}
|
65
99
|
if(event != :delete)
|
66
100
|
ENV['FILEPATH'] = path.realpath.to_s
|
@@ -80,4 +114,5 @@ FileWatcher.new(files, options[:list]).watch(options[:interval]) do |filename, e
|
|
80
114
|
end
|
81
115
|
puts ": " + filename
|
82
116
|
end
|
117
|
+
|
83
118
|
end
|
data/lib/filewatcher.rb
CHANGED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'minitest/autorun'
|
3
|
+
require_relative '../lib/filewatcher'
|
4
|
+
|
5
|
+
describe FileWatcher do
|
6
|
+
|
7
|
+
filewatcher = FileWatcher.new([])
|
8
|
+
|
9
|
+
it "can find single files" do
|
10
|
+
files = filewatcher.expand_directories(["fixtures/file1.txt"])
|
11
|
+
assert files.size == 1
|
12
|
+
end
|
13
|
+
|
14
|
+
it "can expand directories recursively" do
|
15
|
+
files = filewatcher.expand_directories(["fixtures/"])
|
16
|
+
assert files.size == 6
|
17
|
+
files = filewatcher.expand_directories(["fixtures"])
|
18
|
+
assert files.size == 6
|
19
|
+
files = filewatcher.expand_directories(["./fixtures"])
|
20
|
+
assert files.size == 6
|
21
|
+
end
|
22
|
+
|
23
|
+
it "can use filename globbing to filter names" do
|
24
|
+
files = filewatcher.expand_directories(["fixtures/*.rb"])
|
25
|
+
assert files.size == 2
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
puts "Hello world from Ruby!!!"
|
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
puts "This is file6.rb executing"
|
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.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Flemming
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: trollop
|
@@ -39,6 +39,13 @@ files:
|
|
39
39
|
- VERSION
|
40
40
|
- bin/filewatcher
|
41
41
|
- lib/filewatcher.rb
|
42
|
+
- test/filewatcher_spec.rb
|
43
|
+
- test/fixtures/file1.txt
|
44
|
+
- test/fixtures/file2.txt
|
45
|
+
- test/fixtures/file3.rb
|
46
|
+
- test/fixtures/file4.rb
|
47
|
+
- test/fixtures/subdir/file5.rb
|
48
|
+
- test/fixtures/subdir/file6.rb
|
42
49
|
homepage: http://github.com/thomasfl/filewatcher
|
43
50
|
licenses:
|
44
51
|
- MIT
|