forked from quirkey/sammy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
124 lines (105 loc) · 3.3 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
desc 'Pulls the current version from lib/sammy.js'
task :version do
f = File.read('lib/sammy.js')
@version = f.match(/Sammy.VERSION \= \'([\d\w\.]+)\'/)[1]
puts "VERSION: " + @version
end
desc 'Uses the yui-compressor to minify lib/sammy.js'
task :minify => :version do
yui_path = ENV['YUI_PATH'] || '~/Sites/yui/yuicompressor-2.4.2.jar'
java_path = ENV['JAVA_PATH'] || '/usr/bin/java'
puts "Minify-ing"
# compress each file
Dir['lib/**/*.js'].each do |path|
if path =~ /\.min\.js$/
File.unlink(path)
next
end
path.gsub!('lib','')
dir = 'lib/min'
min_path = File.join(dir, path.gsub(/\.js$/, "-#{@version}.min.js"))
latest_min_path = File.join(dir, path.gsub(/\.js$/, "-latest.min.js"))
`#{java_path} -jar #{yui_path} -o #{min_path} lib/#{path}`
minified = File.read(min_path)
prefix = []
prefix << "// -- Sammy.js -- #{path}"
prefix << "// http://sammyjs.org"
prefix << "// Version: #{@version}"
prefix << "// Built: #{Time.now}"
File.open(min_path, 'w') do |f|
f << prefix.join("\n") << "\n"
f << minified
end
FileUtils.copy(min_path, latest_min_path)
end
end
# Modified from peterc: http://gist.github.com/113226
desc "Automatically run something when code is changed"
task :autotest do
require 'find'
files = {}
test_path = ENV['TEST'] || File.join(File.dirname(__FILE__), 'test', 'index.html')
loop do
changed = false
Find.find(File.dirname(__FILE__)) do |file|
next unless file =~ /\.js$/
ctime = File.ctime(file).to_i
if ctime != files[file]
files[file] = ctime
changed = true
end
end
if changed
puts "Running #{test_path} at #{Time.now}"
system "open #{test_path}"
puts "\nWaiting for a *.js change"
end
sleep 1
end
end
desc 'launch the test file in the browser'
task :test do
system "open #{File.join(File.dirname(__FILE__), 'test', 'index.html')}"
end
desc 'copy files into the site branch'
task :copy_test_and_examples do
sh "mkdir -p site/examples site/test site/lib site/vendor"
sh "cp -r examples/* site/examples/"
sh "cp -r test/* site/test/"
sh "cp -r lib/* site/lib/"
sh "cp -r vendor/* site/vendor/"
end
desc 'update the current version # in the pages'
task :update_version => :version do
Dir['site/**/*.*'].each do |file|
File.open(file, 'r+') do |f|
contents = f.read
contents.gsub!(/current_version\: ([\w\d\.]+)/, "current_version: #{@version}")
f.truncate(0)
f.rewind
f << contents
end
end
end
desc 'Tag with the current version'
task :tag => :version do
sh "git add ."
sh "git commit -a -m'Pushing version #{@version}'"
sh "git tag v#{@version}"
sh "git push --tags"
end
task :release => [:minify, :tag, :site]
task :push_site do
sh "cd site && git add ."
sh "cd site && git commit -am 'Updated Site via Rake'"
sh "cd site && git push upstream gh-pages"
end
desc 'Build the site'
task :build_site => [:copy_test_and_examples, :update_version]
desc 'Build the site, then push it to github'
task :site => [:build_site, :push_site]
desc 'Generate the docs for the current version to DIR'
task :docs => :version do
@version = ENV['VERSION'] if ENV['VERSION']
sh "ruby vendor/jsdoc/jsdoc.rb #{ENV['DIR']} #{@version} lib/ lib/plugins/"
end