rerun 0.5.4 → 0.5.5
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/README.md +1 -1
- data/Rakefile +3 -3
- data/icons/rails_grn_sml.png +0 -0
- data/icons/rails_red_sml.png +0 -0
- data/lib/rerun.rb +9 -137
- data/lib/{fswatcher.rb → rerun/fswatcher.rb} +1 -1
- data/lib/{osxwatcher.rb → rerun/osxwatcher.rb} +2 -3
- data/lib/rerun/runner.rb +133 -0
- data/lib/rerun/system.rb +63 -0
- data/lib/{watcher.rb → rerun/watcher.rb} +0 -0
- data/rerun.gemspec +9 -6
- metadata +28 -42
- data/lib/system.rb +0 -48
data/README.md
CHANGED
@@ -59,7 +59,7 @@ Rackup can also be used to launch a Rack server, so let's try that:
|
|
59
59
|
--dir directory to watch (default = ".")
|
60
60
|
|
61
61
|
--pattern glob to match inside directory. This uses the Ruby Dir glob style -- see <http://www.ruby-doc.org/core/classes/Dir.html#M002322> for details.
|
62
|
-
By default it watches
|
62
|
+
By default it watches these files: `rb,js,css,scss,sass,erb,html,haml,ru`.
|
63
63
|
|
64
64
|
Also --version and --help.
|
65
65
|
|
data/Rakefile
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
require 'rake'
|
2
2
|
require 'rake/clean'
|
3
3
|
require 'rake/testtask'
|
4
|
-
require '
|
4
|
+
require 'rspec/core/rake_task'
|
5
5
|
|
6
6
|
task :default => [:spec]
|
7
7
|
task :test => :spec
|
8
8
|
|
9
9
|
desc "Run all specs"
|
10
|
-
|
10
|
+
RSpec::Core::RakeTask.new('spec') do |t|
|
11
11
|
ENV['ENV'] = "test"
|
12
|
-
t.
|
12
|
+
t.pattern = 'spec/**/*_spec.rb'
|
13
13
|
t.ruby_opts = ['-rubygems'] if defined? Gem
|
14
14
|
end
|
15
15
|
|
Binary file
|
Binary file
|
data/lib/rerun.rb
CHANGED
@@ -1,144 +1,16 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
require "
|
1
|
+
here = File.expand_path(File.dirname(__FILE__))
|
2
|
+
$: << here unless $:.include?(here)
|
3
|
+
|
4
|
+
require "rerun/system"
|
5
|
+
require "rerun/runner"
|
6
|
+
require "rerun/watcher"
|
7
|
+
require "rerun/osxwatcher"
|
8
|
+
require "rerun/fswatcher"
|
5
9
|
|
6
10
|
# todo: make sure this works in non-Mac environments (also Macs without growlnotify)
|
7
11
|
module Rerun
|
8
12
|
|
9
|
-
DEFAULT_PATTERN = "**/*.{rb,js,css,erb,ru}"
|
10
|
-
|
11
|
-
class Runner
|
12
|
-
|
13
|
-
include System
|
14
|
-
|
15
|
-
def initialize(run_command, options = {})
|
16
|
-
@run_command, @options = run_command, options
|
17
|
-
@run_command = "ruby #{@run_command}" if @run_command.split(' ').first =~ /\.rb$/
|
18
|
-
end
|
19
|
-
|
20
|
-
def restart
|
21
|
-
@restarting = true
|
22
|
-
stop
|
23
|
-
start
|
24
|
-
@restarting = false
|
25
|
-
end
|
26
|
-
|
27
|
-
def dir
|
28
|
-
@options[:dir] || "."
|
29
|
-
end
|
30
|
-
|
31
|
-
def pattern
|
32
|
-
@options[:pattern] || DEFAULT_PATTERN
|
33
|
-
end
|
34
|
-
|
35
|
-
def start
|
36
|
-
if windows?
|
37
|
-
raise "Sorry, Rerun does not work on Windows."
|
38
|
-
end
|
39
|
-
|
40
|
-
if (!@already_running)
|
41
|
-
taglines = [
|
42
|
-
"To infinity... and beyond!",
|
43
|
-
"Charge!",
|
44
|
-
]
|
45
|
-
notify "Launched", taglines[rand(taglines.size)]
|
46
|
-
@already_running = true
|
47
|
-
else
|
48
|
-
taglines = [
|
49
|
-
"Here we go again!",
|
50
|
-
"Once more unto the breach, dear friends, once more!",
|
51
|
-
]
|
52
|
-
notify "Restarted", taglines[rand(taglines.size)]
|
53
|
-
end
|
54
|
-
|
55
|
-
@pid = Kernel.fork do
|
56
|
-
begin
|
57
|
-
# Signal.trap("INT") { exit }
|
58
|
-
exec(@run_command)
|
59
|
-
rescue => e
|
60
|
-
puts e
|
61
|
-
exit
|
62
|
-
end
|
63
|
-
end
|
64
|
-
Process.detach(@pid) # so if the child exits, it dies
|
65
|
-
|
66
|
-
Signal.trap("INT") do # INT = control-C
|
67
|
-
stop # first stop the child
|
68
|
-
exit
|
69
|
-
end
|
70
|
-
|
71
|
-
begin
|
72
|
-
sleep 2
|
73
|
-
rescue Interrupt => e
|
74
|
-
# in case someone hits control-C immediately
|
75
|
-
stop
|
76
|
-
exit
|
77
|
-
end
|
78
|
-
|
79
|
-
unless running?
|
80
|
-
notify "Launch Failed", "See console for error output"
|
81
|
-
@already_running = false
|
82
|
-
end
|
83
|
-
|
84
|
-
unless @watcher
|
85
|
-
watcher_class = mac? ? OSXWatcher : FSWatcher
|
86
|
-
# watcher_class = FSWatcher
|
87
|
-
|
88
|
-
watcher = watcher_class.new do
|
89
|
-
restart unless @restarting
|
90
|
-
end
|
91
|
-
puts "Watching #{dir}/#{pattern}"
|
92
|
-
watcher.add_directory(dir, pattern)
|
93
|
-
watcher.sleep_time = 1
|
94
|
-
watcher.start
|
95
|
-
@watcher = watcher
|
96
|
-
end
|
97
|
-
|
98
|
-
end
|
99
|
-
|
100
|
-
def join
|
101
|
-
@watcher.join
|
102
|
-
end
|
103
|
-
|
104
|
-
def running?
|
105
|
-
signal(0)
|
106
|
-
end
|
107
|
-
|
108
|
-
def signal(signal)
|
109
|
-
Process.kill(signal, @pid)
|
110
|
-
true
|
111
|
-
rescue
|
112
|
-
false
|
113
|
-
end
|
114
|
-
|
115
|
-
def stop
|
116
|
-
if @pid && (@pid != 0)
|
117
|
-
notify "Stopped", "All good things must come to an end." unless @restarting
|
118
|
-
signal("KILL") && Process.wait(@pid)
|
119
|
-
end
|
120
|
-
rescue => e
|
121
|
-
false
|
122
|
-
end
|
123
|
-
|
124
|
-
def git_head_changed?
|
125
|
-
old_git_head = @git_head
|
126
|
-
read_git_head
|
127
|
-
@git_head and old_git_head and @git_head != old_git_head
|
128
|
-
end
|
129
|
-
|
130
|
-
def read_git_head
|
131
|
-
git_head_file = File.join(dir, '.git', 'HEAD')
|
132
|
-
@git_head = File.exists?(git_head_file) && File.read(git_head_file)
|
133
|
-
end
|
134
|
-
|
135
|
-
def notify(title, body)
|
136
|
-
growl title, body
|
137
|
-
puts
|
138
|
-
puts "#{Time.now.strftime("%T")} - #{app_name} #{title}"
|
139
|
-
end
|
140
|
-
|
141
|
-
end
|
13
|
+
DEFAULT_PATTERN = "**/*.{rb,js,css,scss,sass,erb,html,haml,ru}"
|
142
14
|
|
143
15
|
end
|
144
16
|
|
@@ -1,9 +1,8 @@
|
|
1
|
-
require "system"
|
2
|
-
require "watcher"
|
1
|
+
require "rerun/system"
|
2
|
+
require "rerun/watcher"
|
3
3
|
|
4
4
|
#TODO: make it notice deleted files natively, rather than passing to 'examine'
|
5
5
|
#TODO: use http://github.com/spicycode/fsevent
|
6
|
-
require "watcher"
|
7
6
|
module Rerun
|
8
7
|
class OSXWatcher < Rerun::Watcher
|
9
8
|
attr_reader :last_check, :valid_extensions
|
data/lib/rerun/runner.rb
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
module Rerun
|
2
|
+
class Runner
|
3
|
+
|
4
|
+
include System
|
5
|
+
|
6
|
+
def initialize(run_command, options = {})
|
7
|
+
@run_command, @options = run_command, options
|
8
|
+
@run_command = "ruby #{@run_command}" if @run_command.split(' ').first =~ /\.rb$/
|
9
|
+
end
|
10
|
+
|
11
|
+
def restart
|
12
|
+
@restarting = true
|
13
|
+
stop
|
14
|
+
start
|
15
|
+
@restarting = false
|
16
|
+
end
|
17
|
+
|
18
|
+
def dir
|
19
|
+
@options[:dir] || "."
|
20
|
+
end
|
21
|
+
|
22
|
+
def pattern
|
23
|
+
@options[:pattern] || DEFAULT_PATTERN
|
24
|
+
end
|
25
|
+
|
26
|
+
def start
|
27
|
+
if windows?
|
28
|
+
raise "Sorry, Rerun does not work on Windows."
|
29
|
+
end
|
30
|
+
|
31
|
+
if (!@already_running)
|
32
|
+
taglines = [
|
33
|
+
"To infinity... and beyond!",
|
34
|
+
"Charge!",
|
35
|
+
]
|
36
|
+
notify "Launched", taglines[rand(taglines.size)]
|
37
|
+
@already_running = true
|
38
|
+
else
|
39
|
+
taglines = [
|
40
|
+
"Here we go again!",
|
41
|
+
"Once more unto the breach, dear friends, once more!",
|
42
|
+
]
|
43
|
+
notify "Restarted", taglines[rand(taglines.size)]
|
44
|
+
end
|
45
|
+
|
46
|
+
@pid = Kernel.fork do
|
47
|
+
begin
|
48
|
+
# Signal.trap("INT") { exit }
|
49
|
+
exec(@run_command)
|
50
|
+
rescue => e
|
51
|
+
puts e
|
52
|
+
exit
|
53
|
+
end
|
54
|
+
end
|
55
|
+
Process.detach(@pid) # so if the child exits, it dies
|
56
|
+
|
57
|
+
Signal.trap("INT") do # INT = control-C
|
58
|
+
stop # first stop the child
|
59
|
+
exit
|
60
|
+
end
|
61
|
+
|
62
|
+
begin
|
63
|
+
sleep 2
|
64
|
+
rescue Interrupt => e
|
65
|
+
# in case someone hits control-C immediately
|
66
|
+
stop
|
67
|
+
exit
|
68
|
+
end
|
69
|
+
|
70
|
+
unless running?
|
71
|
+
notify "Launch Failed", "See console for error output"
|
72
|
+
@already_running = false
|
73
|
+
end
|
74
|
+
|
75
|
+
unless @watcher
|
76
|
+
watcher_class = osx_foundation? ? OSXWatcher : FSWatcher
|
77
|
+
# watcher_class = FSWatcher
|
78
|
+
|
79
|
+
watcher = watcher_class.new do
|
80
|
+
restart unless @restarting
|
81
|
+
end
|
82
|
+
puts "Watching #{dir}/#{pattern}"
|
83
|
+
watcher.add_directory(dir, pattern)
|
84
|
+
watcher.sleep_time = 1
|
85
|
+
watcher.start
|
86
|
+
@watcher = watcher
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
def join
|
92
|
+
@watcher.join
|
93
|
+
end
|
94
|
+
|
95
|
+
def running?
|
96
|
+
signal(0)
|
97
|
+
end
|
98
|
+
|
99
|
+
def signal(signal)
|
100
|
+
Process.kill(signal, @pid)
|
101
|
+
true
|
102
|
+
rescue
|
103
|
+
false
|
104
|
+
end
|
105
|
+
|
106
|
+
def stop
|
107
|
+
if @pid && (@pid != 0)
|
108
|
+
notify "Stopped", "All good things must come to an end." unless @restarting
|
109
|
+
signal("KILL") && Process.wait(@pid)
|
110
|
+
end
|
111
|
+
rescue => e
|
112
|
+
false
|
113
|
+
end
|
114
|
+
|
115
|
+
def git_head_changed?
|
116
|
+
old_git_head = @git_head
|
117
|
+
read_git_head
|
118
|
+
@git_head and old_git_head and @git_head != old_git_head
|
119
|
+
end
|
120
|
+
|
121
|
+
def read_git_head
|
122
|
+
git_head_file = File.join(dir, '.git', 'HEAD')
|
123
|
+
@git_head = File.exists?(git_head_file) && File.read(git_head_file)
|
124
|
+
end
|
125
|
+
|
126
|
+
def notify(title, body)
|
127
|
+
growl title, body
|
128
|
+
puts
|
129
|
+
puts "#{Time.now.strftime("%T")} - #{app_name} #{title}"
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
133
|
+
end
|
data/lib/rerun/system.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
module Rerun
|
2
|
+
module System
|
3
|
+
|
4
|
+
def mac?
|
5
|
+
# puts "RUBY_PLATFORM=#{RUBY_PLATFORM}"
|
6
|
+
RUBY_PLATFORM =~ /darwin/i
|
7
|
+
end
|
8
|
+
|
9
|
+
def osx_foundation?
|
10
|
+
mac? and begin
|
11
|
+
if $osx_foundation.nil?
|
12
|
+
require 'osx/foundation'
|
13
|
+
OSX.require_framework '/System/Library/Frameworks/CoreServices.framework/Frameworks/CarbonCore.framework'
|
14
|
+
$osx_foundation = true
|
15
|
+
end
|
16
|
+
$osx_foundation
|
17
|
+
rescue LoadError
|
18
|
+
$osx_foundation = false
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def windows?
|
23
|
+
RUBY_PLATFORM =~ /mswin/i
|
24
|
+
end
|
25
|
+
|
26
|
+
def linux?
|
27
|
+
RUBY_PLATFORM =~ /linux/i
|
28
|
+
end
|
29
|
+
|
30
|
+
# do we have growl or not?
|
31
|
+
def growl?
|
32
|
+
mac? && (growlcmd != "")
|
33
|
+
end
|
34
|
+
|
35
|
+
def growlcmd
|
36
|
+
`which growlnotify`.chomp
|
37
|
+
end
|
38
|
+
|
39
|
+
def app_name
|
40
|
+
# todo: make sure this works in non-Mac and non-Unix environments
|
41
|
+
File.expand_path(".").gsub(/^.*\//, '').capitalize
|
42
|
+
end
|
43
|
+
|
44
|
+
def icon
|
45
|
+
libdir = "#{File.expand_path(File.dirname(File.dirname(__FILE__)))}/lib"
|
46
|
+
$LOAD_PATH.unshift libdir unless $LOAD_PATH.include?(libdir)
|
47
|
+
|
48
|
+
rails_sig_file = File.expand_path(".")+"/config/boot.rb"
|
49
|
+
return "#{libdir}/../icons/rails_red_sml.png" if File.exists? rails_sig_file
|
50
|
+
return nil
|
51
|
+
end
|
52
|
+
|
53
|
+
def growl(title, body, background = true)
|
54
|
+
if growl?
|
55
|
+
icon_str = ("--image \"#{icon}\"" if icon)
|
56
|
+
s = "#{growlcmd} -n \"#{app_name}\" -m \"#{body}\" \"#{app_name} #{title}\" #{icon_str}"
|
57
|
+
s += " &" if background
|
58
|
+
`#{s}`
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
File without changes
|
data/rerun.gemspec
CHANGED
@@ -3,8 +3,8 @@ $spec = Gem::Specification.new do |s|
|
|
3
3
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
4
4
|
|
5
5
|
s.name = 'rerun'
|
6
|
-
s.version = '0.5.
|
7
|
-
s.date = '
|
6
|
+
s.version = '0.5.5'
|
7
|
+
s.date = '2011-05-14'
|
8
8
|
|
9
9
|
s.description = "Restarts your app when a file changes"
|
10
10
|
s.summary = "Launches an app, and restarts it whenever the filesystem changes."
|
@@ -18,11 +18,14 @@ $spec = Gem::Specification.new do |s|
|
|
18
18
|
Rakefile
|
19
19
|
rerun.gemspec
|
20
20
|
bin/rerun
|
21
|
+
icons/rails_grn_sml.png
|
22
|
+
icons/rails_red_sml.png
|
21
23
|
lib/rerun.rb
|
22
|
-
lib/fswatcher.rb
|
23
|
-
lib/osxwatcher.rb
|
24
|
-
lib/
|
25
|
-
lib/
|
24
|
+
lib/rerun/fswatcher.rb
|
25
|
+
lib/rerun/osxwatcher.rb
|
26
|
+
lib/rerun/runner.rb
|
27
|
+
lib/rerun/system.rb
|
28
|
+
lib/rerun/watcher.rb
|
26
29
|
]
|
27
30
|
s.executables = ['rerun']
|
28
31
|
s.test_files = s.files.select {|path| path =~ /^spec\/.*_spec.rb/}
|
metadata
CHANGED
@@ -1,73 +1,59 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: rerun
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 5
|
8
|
-
- 4
|
9
|
-
version: 0.5.4
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.5
|
5
|
+
prerelease:
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
7
|
+
authors:
|
12
8
|
- Alex Chaffee
|
13
9
|
autorequire:
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
|
-
|
17
|
-
date: 2010-11-20 00:00:00 -08:00
|
18
|
-
default_executable:
|
12
|
+
date: 2011-05-14 00:00:00.000000000Z
|
19
13
|
dependencies: []
|
20
|
-
|
21
14
|
description: Restarts your app when a file changes
|
22
15
|
email: alex@stinky.com
|
23
|
-
executables:
|
16
|
+
executables:
|
24
17
|
- rerun
|
25
18
|
extensions: []
|
26
|
-
|
27
|
-
extra_rdoc_files:
|
19
|
+
extra_rdoc_files:
|
28
20
|
- README.md
|
29
|
-
files:
|
21
|
+
files:
|
30
22
|
- README.md
|
31
23
|
- LICENSE
|
32
24
|
- Rakefile
|
33
25
|
- rerun.gemspec
|
34
26
|
- bin/rerun
|
27
|
+
- icons/rails_grn_sml.png
|
28
|
+
- icons/rails_red_sml.png
|
35
29
|
- lib/rerun.rb
|
36
|
-
- lib/fswatcher.rb
|
37
|
-
- lib/osxwatcher.rb
|
38
|
-
- lib/
|
39
|
-
- lib/
|
40
|
-
|
30
|
+
- lib/rerun/fswatcher.rb
|
31
|
+
- lib/rerun/osxwatcher.rb
|
32
|
+
- lib/rerun/runner.rb
|
33
|
+
- lib/rerun/system.rb
|
34
|
+
- lib/rerun/watcher.rb
|
41
35
|
homepage: http://github.com/alexch/rerun/
|
42
36
|
licenses: []
|
43
|
-
|
44
37
|
post_install_message:
|
45
38
|
rdoc_options: []
|
46
|
-
|
47
|
-
require_paths:
|
39
|
+
require_paths:
|
48
40
|
- lib
|
49
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
42
|
none: false
|
51
|
-
requirements:
|
52
|
-
- -
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
|
55
|
-
|
56
|
-
version: "0"
|
57
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
48
|
none: false
|
59
|
-
requirements:
|
60
|
-
- -
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
|
63
|
-
- 0
|
64
|
-
version: "0"
|
49
|
+
requirements:
|
50
|
+
- - ! '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
65
53
|
requirements: []
|
66
|
-
|
67
54
|
rubyforge_project: pivotalrb
|
68
|
-
rubygems_version: 1.
|
55
|
+
rubygems_version: 1.8.1
|
69
56
|
signing_key:
|
70
57
|
specification_version: 2
|
71
58
|
summary: Launches an app, and restarts it whenever the filesystem changes.
|
72
59
|
test_files: []
|
73
|
-
|
data/lib/system.rb
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
def mac?
|
2
|
-
RUBY_PLATFORM =~ /darwin/i && !$osx_foundation_failed_to_load
|
3
|
-
end
|
4
|
-
|
5
|
-
def windows?
|
6
|
-
RUBY_PLATFORM =~ /mswin/i
|
7
|
-
end
|
8
|
-
|
9
|
-
def linux?
|
10
|
-
RUBY_PLATFORM =~ /linux/i
|
11
|
-
end
|
12
|
-
|
13
|
-
if mac?
|
14
|
-
begin
|
15
|
-
require 'osx/foundation'
|
16
|
-
OSX.require_framework '/System/Library/Frameworks/CoreServices.framework/Frameworks/CarbonCore.framework'
|
17
|
-
rescue LoadError
|
18
|
-
$osx_foundation_failed_to_load = true
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
module Rerun
|
23
|
-
module System
|
24
|
-
|
25
|
-
# do we have growl or not?
|
26
|
-
def growl?
|
27
|
-
mac? && (growlcmd != "")
|
28
|
-
end
|
29
|
-
|
30
|
-
def growlcmd
|
31
|
-
`which growlnotify`.chomp
|
32
|
-
end
|
33
|
-
|
34
|
-
def app_name
|
35
|
-
# todo: make sure this works in non-Mac and non-Unix environments
|
36
|
-
File.expand_path(".").gsub(/^.*\//, '').capitalize
|
37
|
-
end
|
38
|
-
|
39
|
-
def growl(title, body, background = true)
|
40
|
-
if growl?
|
41
|
-
s = "#{growlcmd} -n \"#{app_name}\" -m \"#{body}\" \"#{app_name} #{title}\""
|
42
|
-
s += " &" if background
|
43
|
-
`#{s}`
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
end
|
48
|
-
end
|