forked from mockko/livereload
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
123 lines (99 loc) · 3.26 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
LIVERELOAD_VERSION = '1.6'
GEM_SRC = FileList["server/lib/*.rb", "server/*.gemspec", "server/bin/*"]
GEM_DIST = "server/livereload-#{LIVERELOAD_VERSION}.gem"
task :chrome do
content_script = 'LiveReload.chromeextension/LiveReload-content.js'
File.open content_script, 'w' do |f|
f.puts File.read('src/content.js') << File.read('src/chrome/content.js')
puts "+ #{content_script}"
end
background_script = 'LiveReload.chromeextension/LiveReload-background.js'
File.open background_script, 'w' do |f|
f.puts File.read('src/background.js') << File.read('src/chrome/background.js')
puts "+ #{background_script}"
end
end
task :safari do
injected_script = 'LiveReload.safariextension/LiveReload-injected.js'
File.open injected_script, 'w' do |f|
f.puts File.read('src/content.js') << File.read('src/safari/injected.js')
puts "+ #{injected_script}"
end
global_script = 'LiveReload.safariextension/LiveReload-global.js'
File.open global_script, 'w' do |f|
f.puts File.read('src/background.js') << File.read('src/safari/global.js')
puts "+ #{global_script}"
end
end
task :firefox do
require 'fileutils'
dest_dir = 'Firefox/content'
FileUtils.cp %w(src/background.js src/content.js), dest_dir
puts "+ #{dest_dir}/background.js"
puts "+ #{dest_dir}/content.js"
puts 'LiveReload.xpi: '
system 'cd Firefox && zip -r ../LiveReload.xpi .'
puts '+ LiveReload.xpi (drag it into Firefox window to install)'
end
namespace :gem do
file GEM_DIST => GEM_SRC do
cd 'server' do
sh 'gem', 'build', 'livereload.gemspec'
end
end
desc "Build the livereload gem"
task :build => GEM_DIST
desc "Install the livereload gem/command"
task :install => :build do
sh 'sudo', 'gem', 'install', GEM_DIST
end
desc "Uninstall the livereload gem/command"
task :uninstall do
sh 'sudo', 'gem', 'uninstall', 'livereload'
end
desc "Publish the gem on gemcutter"
task :publish => :build do
sh 'gem', 'push', GEM_DIST
end
end
task :test do
#`python -m SimpleHTTPServer`
require 'webrick'
# http://tobyho.com/HTTP_Server_in_5_Lines_With_Webrick
class NonCachingFileHandler < WEBrick::HTTPServlet::FileHandler
def prevent_caching(res)
res['ETag'] = nil
res['Last-Modified'] = Time.now + 100**4
res['Cache-Control'] = 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0'
end
def do_GET(req, res)
super
prevent_caching(res)
end
end
serv = Thread.new() {
server = WEBrick::HTTPServer.new :Port => 8000
server.mount('/', NonCachingFileHandler, './')
puts 'http://0.0.0.0:8000 started'
server.start
}
serv2 = Thread.new() {
server = WEBrick::HTTPServer.new :Port => 8001
server.mount('/', NonCachingFileHandler, './')
puts 'http://0.0.0.0:8001 started'
server.start
}
`open http://0.0.0.0:8000/test` unless `which open`.empty?
serv.join
serv2.join
end
require 'rake/clean'
CLEAN.include('LiveReload.xpi')
CLOBBER.include(%w(
LiveReload.chromeextension/LiveReload-content.js
LiveReload.chromeextension/LiveReload-background.js
LiveReload.safariextension/LiveReload-injected.js
LiveReload.safariextension/LiveReload-global.js
Firefox/content/background.js
Firefox/content/content.js
))