Rakefile
1.17 KB
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
require 'rubygems'
BUILD_DIRECTORY = 'build'
SRC_DIRECTORY = 'src'
desc "build the toast-min.js files for distribution"
task :default => :clean do
FileUtils.mkdir_p(BUILD_DIRECTORY)
compile_js
end
task :build => :default
desc "removes the build directory"
task :clean do
print_action('Removing existing build directory') do
FileUtils.rm_rf('build')
end
end
def compile_js()
require 'coffee-script'
require 'closure-compiler'
source = File.read(File.join(SRC_DIRECTORY, 'rivets.coffee'))
FileUtils.mkdir_p(BUILD_DIRECTORY)
output = File.join(BUILD_DIRECTORY, 'rivets.js')
minified_output = File.join(BUILD_DIRECTORY, 'rivets-min.js')
compiled = ''
print_action("Compiling CoffeeScript to '#{output}'") do
File.open(output, 'w+') do |file|
compiled = CoffeeScript.compile(source)
file.write(compiled)
end
end
print_action("Minifying Javascript to '#{minified_output}'") do
File.open(minified_output, 'w+') do |file|
file.write(Closure::Compiler.new.compress(compiled))
end
end
end
def print_action(action, &block)
print "#{action}... "
STDOUT.flush
if block.call()
puts 'done'
else
puts 'failed'
end
end