-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathRakefile
49 lines (38 loc) · 1.37 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
require 'rubygems'
require 'bundler/setup'
require 'yaml'
$:.push(File.expand_path('../lib', __FILE__))
environment = (ENV["ENVIRONMENT"] || 'development').to_sym
CONFIG = YAML.load_file('./config/config.yml')[environment]
VERSION = ENV['VERSION'] || raise("provide a version number")
Rake.application.options.trace = true
desc 'Bundle and minify source files.'
task :build => ["build/panda-uploader.min.js"]
ALL_JS_FILES = FileList['src/**/*.js']
directory "./build"
directory "./dist"
directory "./dist/#{VERSION}"
directory "./dist/#{VERSION}/assets"
directory "vendor"
file "build/panda-uploader.min.js" => ["vendor/plovr.jar", *ALL_JS_FILES] do |file|
sh('java -jar vendor/plovr.jar build config.min.js')
end
file "vendor/plovr.jar" => "vendor" do
sh "curl http://plovr.googlecode.com/files/plovr-eba786b34df9.jar -o vendor/plovr.jar"
end
task :bundle => ["./dist/#{VERSION}", :build] do
bundle_js ["licence.js", "build/panda-uploader.min.js"], :to => "./dist/#{VERSION}/panda-uploader.min.js"
sh("mkdir -p ./dist/#{VERSION}/assets/")
sh("cp src/assets/* ./dist/#{VERSION}/assets/")
end
task :serve do
sh('java -jar vendor/plovr.jar serve config.min.js')
end
def bundle_js(files, options={})
js=files.map {|f|
File.read(f)
}.join("\n")
js.gsub!(/<VERSION>/, VERSION)
js.gsub!(/<CDN_HOST>/, CONFIG[:js][:host])
File.open(options[:to], "w") {|f| f.puts js }
end