-
Notifications
You must be signed in to change notification settings - Fork 5
/
Rakefile
110 lines (76 loc) · 1.99 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
require 'rake'
require 'rake/clean'
LIBRARY =
`pwd`.split('/').last.strip
LICENSE_URI =
"http://github.com/jmettraux/#{LIBRARY}/LICENSE.txt"
COMPRESSOR =
%w[ yui-compressor yuicompressor ].find { |com| `which #{com}`.strip != '' }
raise(
"did not find yui-compressor (or yuicompressor) on this system"
) unless COMPRESSOR
#
# tasks
#CLEAN.include('pkg')
# no cleaning for now
task :default => [ :clean ]
desc %q{
packages/minifies the js files to pkg/
}
task :package => :clean do
version = File.read(
"js/#{LIBRARY}.js"
).match(
/ var VERSION *= *['"]([^'"]+)/
)[1]
sha = `git log -1 --format="%H"`.strip[0, 7]
sh 'mkdir -p pkg'
js_count = Dir['js/*.js'].length
# don't create -all- files if there is only 1 js file
FileUtils.rm_f("pkg/#{LIBRARY}-all-#{version}.js")
Dir['js/*.js'].each do |path|
fname = File.basename(path, '.js')
FileUtils.cp(path, "pkg/#{fname}-#{version}.js")
sh(
COMPRESSOR + ' ' +
path + ' ' +
"-o pkg/#{fname}-#{version}.min.js")
File.open("pkg/#{LIBRARY}-all-#{version}.js", 'ab') do |f|
f.puts(File.read(path))
end if js_count > 1
end
sh(
COMPRESSOR + ' ' +
"pkg/#{LIBRARY}-all-#{version}.js " +
"-o pkg/#{LIBRARY}-all-#{version}.min.js"
) if js_count > 1
Dir['pkg/*.min.js'].each do |path|
fname = File.basename(path)
header = "/* #{fname} | MIT license: #{LICENSE_URI} */\n"
s = header + File.read(path)
File.open(path, 'wb') { |f| f.print(s) }
end
footer = "\n/* compressed from commit #{sha} */\n"
Dir['pkg/*.js'].each { |path| File.open(path, 'ab') { |f| f.puts(footer) } }
sh(
"mkdir -p pkg/css-#{version}; cp css/* pkg/css-#{version}/"
) if File.exist?('css')
end
desc %q{
alias for 'package'
}
task :pkg => :package
desc %q{
alias for 'package'
}
task :p => :package
desc %q{
serve the current dir over HTTP for testing
}
task :serve do
sh 'python -m SimpleHTTPServer 1234'
end
desc %q{
alias for 'serve'
}
task :s => :serve