-
Notifications
You must be signed in to change notification settings - Fork 32
/
Rakefile
42 lines (36 loc) · 1.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
desc "Release a new csonv.js version"
task :release, :version do |task, args|
if (args[:version] || "").strip.empty?
puts "usage: rake release[version]"
exit
end
timestamp = Time.now
javascript = File.open("src/csonv.js").readlines.collect do |line|
line.gsub(/\{(version|year|date)\}/) do |matched|
case matched
when "{version}"
args[:version]
when "{year}"
timestamp.year.to_s
when "{date}"
timestamp.strftime("%Y-%m-%d %H:%M:%S +0100 (%a, %d %B %Y)")
end
end
end
# Define variables
releases_dir = "releases"
release_dir = "#{releases_dir}/#{args[:version]}"
latest_dir = "#{releases_dir}/latest"
# Create directories
FileUtils.rm_r(release_dir) if File.exists?(release_dir)
FileUtils.mkdir_p(release_dir)
# Create files
FileUtils.cp("README.textile", "#{release_dir}/README.textile")
File.open("#{release_dir}/csonv.js", "w").puts(javascript)
File.open("VERSION", "w").puts(args[:version])
# Compress release using YUI compressor
IO.popen "java -jar lib/yuicompressor-2.4.2.jar -v #{release_dir}/csonv.js -o #{release_dir}/csonv.min.js"
# Update latest release dir
FileUtils.rm_r(latest_dir) if File.exists?(latest_dir)
FileUtils.cp_r("#{release_dir}/.", latest_dir)
end