-
Notifications
You must be signed in to change notification settings - Fork 3
/
Rakefile
71 lines (52 loc) · 1.64 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
require "bundler/setup"
require "sproutcore"
require "erb"
require "uglifier"
LICENSE = File.read("generators/license.js")
## Some SproutCore modules expect an exports object to exist. Until bpm exists,
## just mock this out for now.
module SproutCore
module Compiler
class Entry
def body
"\n(function(exports) {\n#{@raw_body}\n})({});\n"
end
end
end
end
## HELPERS ##
def strip_require(file)
result = File.read(file)
result.gsub!(%r{^\s*require\(['"]([^'"])*['"]\);?\s*$}, "")
result
end
def uglify(file)
uglified = Uglifier.compile(File.read(file))
"#{LICENSE}\n#{uglified}"
end
SproutCore::Compiler.intermediate = "tmp/intermediate"
SproutCore::Compiler.output = "tmp/static"
def compile_package_task(package)
js_tasks = SproutCore::Compiler::Preprocessors::JavaScriptTask.with_input "packages/#{package}/lib/**/*.js", "."
SproutCore::Compiler::CombineTask.with_tasks js_tasks, "#{SproutCore::Compiler.intermediate}/#{package}"
end
namespace :sproutcore do
task :ui => compile_package_task("sproutcore-ui")
end
task :build => ["sproutcore:ui"]
file "dist/sproutcore-ui.js" => :build do
puts "Generating sproutcore-ui.js"
mkdir_p "dist"
File.open("dist/sproutcore-ui.js", "w") do |file|
file.puts strip_require("tmp/static/sproutcore-ui.js")
end
end
# Minify dist/sproutcore-ui.js to dist/sproutcore-ui.min.js
file "dist/sproutcore-ui.min.js" => "dist/sproutcore-ui.js" do
puts "Generating sproutcore-ui.min.js"
File.open("dist/sproutcore-ui.min.js", "w") do |file|
file.puts uglify("dist/sproutcore-ui.js")
end
end
SC_VERSION = "2.0"
task :default => ["dist/sproutcore-ui.min.js"]