-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
36 lines (31 loc) · 1.06 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
require "rake"
require "sprockets"
require 'closure-compiler'
def self.sprocketize(path, source, destination = nil, strip_comments = true)
root_dir = File.expand_path(File.dirname(__FILE__))
src_dir = File.join(root_dir, 'src')
dist_dir = File.join(root_dir, 'js')
secretary = Sprockets::Secretary.new(
:root => File.join(root_dir, path),
:load_path => [src_dir],
:source_files => [source],
:strip_comments => strip_comments
)
destination = File.join(dist_dir, source) unless destination
secretary.concatenation.save_to(destination)
end
desc "Creates a distribution javascript file"
task :dist do
sprocketize("src", "script.js")
end
desc "Compiles the distribution javascript"
task :compile => [:dist] do
root_dir = File.expand_path(File.dirname(__FILE__))
script_file = File.join(root_dir, "js/script.js")
compiled = Closure::Compiler.new.compile(File.open(script_file, "r"))
File.unlink(script_file) if File.exist?(script_file)
f = File.new(script_file, "w")
f.write(compiled)
f.close()
end
task :default => [:compile]