forked from rails/rails-ujs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
56 lines (46 loc) · 1.44 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
require "bundler/gem_tasks"
desc %(Starts the test server and opens it in a web browser)
multitask develop: ["test:server", "test:open"]
desc %(Build source files into dist/rails-ujs.js)
task :build do
system "bundle exec blade build"
end
task default: :develop
PORT = 4567
namespace :test do
desc %(Starts the test server)
task :server do
system "bundle exec ruby test/server.rb"
end
desc %(Starts the test server which reloads everything on each refresh)
task :reloadable do
system "bundle exec shotgun test/config.ru -p #{PORT} --server thin"
end
task :open do
url = "http://localhost:#{PORT}"
puts "Opening test app at #{url} ..."
sleep 3
system(*browse_cmd(url))
end
end
# Returns an array e.g.: ['open', 'http://example.com']
def browse_cmd(url)
require "rbconfig"
browser = ENV["BROWSER"] ||
(RbConfig::CONFIG["host_os"].include?("darwin") && "open") ||
(RbConfig::CONFIG["host_os"] =~ /msdos|mswin|djgpp|mingw|windows/ && "start") ||
%w[xdg-open x-www-browser firefox opera mozilla netscape].find { |comm| which comm }
abort("ERROR: no web browser detected") unless browser
Array(browser) << url
end
# which('ruby') #=> /usr/bin/ruby
def which(cmd)
exts = ENV["PATHEXT"] ? ENV["PATHEXT"].split(";") : [""]
ENV["PATH"].split(File::PATH_SEPARATOR).each do |path|
exts.each { |ext|
exe = "#{path}/#{cmd}#{ext}"
return exe if File.executable? exe
}
end
return nil
end