-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
178 lines (144 loc) · 4.27 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
ENVIRONMENT = 'production'
require './boot'
require 'fileutils'
def config
CONFIG[ENVIRONMENT]
end
def all_remotes
Dir.entries(".git/refs/remotes").reject { |remote| remote =~ /^\.{1,2}$/ } # skip . and ..
end
BUILD_DIR = File.join(File.dirname(__FILE__), "assets")
Dir.glob('lib/tasks/*.rake').each { |r| import r }
directory BUILD_DIR
namespace :clean do
all_remotes.each do |remote|
desc "Fetch and reset assets to #{remote}'s gh-pages branch."
task remote.to_sym do
cd(BUILD_DIR) do
sh "git fetch #{remote}"
sh "git reset --hard #{remote}/gh-pages"
end
end
end
end
desc "remove all built assets"
task :clean do
mkdir_p BUILD_DIR
rm_rf Dir.glob(File.join(BUILD_DIR, '*'))
end
desc "compile all files into the assets directory"
task :compile => [:clean, BUILD_DIR] do
bundles = [ 'index.html', 'application.css', 'application.js', 'timezones.json' ]
bundles.each do |bundle|
assets = SprocketsApp.find_asset(bundle)
assets.write_to File.join(BUILD_DIR, bundle)
end
cp_r TZDATA_DIR, BUILD_DIR, :verbose => true
cp_r IMAGES_DIR, BUILD_DIR, :verbose => true
cp_r FONTS_DIR, BUILD_DIR, :verbose => true
if config['cname']
File.open("#{BUILD_DIR}/CNAME", 'w') { |f| f << config['cname'] }
end
end
task :not_dirty do
fail "Directory not clean" if /nothing to commit/ !~ `git status`
end
namespace :publish do
all_remotes.each do |remote|
remote_branch = "assets/.git/refs/remotes/#{remote}/gh-pages"
file remote_branch => BUILD_DIR do
repo_url = `git config --get remote.#{remote}.url`.strip
cd BUILD_DIR do
sh "git init"
sh "git remote add #{remote} #{repo_url}"
sh "git fetch #{remote}"
sh "git checkout gh-pages"
sh "git pull #{remote} gh-pages"
end
end
desc "Publish to Github Pages; remote=#{remote}."
task remote.to_sym => [:not_dirty, remote_branch, "clean:#{remote}", :clean, :compile] do
head = `git log --pretty="%h" -n1`.strip
message = "Site updated to #{head}"
File.open 'assets/index.html', 'a' do |file|
file << "<!-- #{head} -->"
end
cd BUILD_DIR do
sh 'git add --all'
if /nothing to commit/ =~ `git status`
puts "No changes to commit."
else
sh "git commit -m \"#{message}\""
end
sh "git push #{remote} gh-pages"
end
end
end
end
desc "Publish to Github Pages; remote=origin."
task :publish => :"publish:origin"
desc "Run tests with phantomjs"
task :test do
unless system("which phantomjs > /dev/null 2>&1")
abort "PhantomJS is not installed. Download from http://phantomjs.org"
end
with_test_server_running do
cmd = "phantomjs spec/run-jasmine.js \"http://localhost:9299/specs\""
if system(cmd)
puts "Tests Passed".green
else
puts "Tests Failed".red
exit(1)
end
end
end
def with_test_server_running
puts "Starting server"
`rackup --port 9299 --daemonize --pid test_server.pid`
sleep 3
yield
%x(kill -9 `cat test_server.pid` && rm test_server.pid)
end
task :default => :test
namespace :tz do
directory "vendor/tzdata"
desc <<-END
import a new version of the olsen database.
get the latest version from http://www.iana.org/time-zones.
extract it locally, then call this task.
rake tz:import FROM=path/to/new/tzdata
END
task :import => "vendor/tzdata" do
from = ENV["FROM"] && ROOT.join(ENV["FROM"])
to = ROOT.join("vendor", "tzdata")
unless from && File.exists?(from)
puts "you must include a FROM!\nrake tz:import FROM=path/to/new/tzdata"
puts "FROM=#{from}"
exit 1
end
Dir.foreach(from) do |file|
# files we care about have no file extension
# also skipping . and ..
next if file.index(".")
copy_without_comments(from.join(file), to.join(file))
end
end
def copy_without_comments(infile, outfile)
File.open(infile, "r:utf-8:ascii", :invalid => :replace, :replace => '') do |i|
puts "opening #{infile}"
File.open(outfile, "w") do |o|
done = false
until done
begin
l = i.readline
if l !~ /^#.*$/ && l != "\n"
o.write l
end
rescue EOFError
done = true
end
end
end
end
end
end