-
Notifications
You must be signed in to change notification settings - Fork 3
/
Rakefile
79 lines (61 loc) · 1.91 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
require "bundler/setup"
require "erb"
require "uglifier"
require "sproutcore"
LICENSE = File.read("generators/license.js")
module SproutCore
module Compiler
class Entry
def body
"\n(function(exports) {\n#{@raw_body}\n})({});\n"
end
end
end
end
def strip_require(file)
result = File.read(file)
result.gsub!(%r{^\s*require\(['"]([^'"])*['"]\);?\s*$}, "")
result
end
def strip_sc_assert(file)
result = File.read(file)
result.gsub!(%r{^(\s)+sc_assert\((.*)\).*$}, "")
result
end
def uglify(file)
uglified = Uglifier.compile(File.read(file))
"#{LICENSE}\n#{uglified}"
end
SproutCore::Compiler.output = "tmp/static"
SproutCore::Compiler.intermediate = "tmp/static"
def compile_utils_task
SproutCore::Compiler.intermediate = "tmp/sproutcore-utils"
js_tasks = SproutCore::Compiler::Preprocessors::JavaScriptTask.with_input "lib/**/*.js", "."
SproutCore::Compiler::CombineTask.with_tasks js_tasks, "#{SproutCore::Compiler.intermediate}/sproutcore-utils"
end
task :compile_utils_task => compile_utils_task
task :build => [:compile_utils_task]
file "dist/sproutcore-utils.js" => :build do
puts "Generating sproutcore-utils.js"
mkdir_p "dist"
File.open("dist/sproutcore-utils.js", "w") do |file|
file.puts strip_require("tmp/static/sproutcore-utils.js")
end
end
# Minify dist/sproutcore-utils.js to dist/sproutcore-utils.min.js
file "dist/sproutcore-utils.min.js" => "dist/sproutcore-utils.js" do
puts "Generating sproutcore-utils.min.js"
File.open("dist/sproutcore-utils.prod.js", "w") do |file|
file.puts strip_sc_assert("dist/sproutcore-utils.js")
end
File.open("dist/sproutcore-utils.min.js", "w") do |file|
file.puts uglify("dist/sproutcore-utils.prod.js")
end
rm "dist/sproutcore-utils.prod.js"
end
desc "Build SproutCore Utilities"
task :dist => ["dist/sproutcore-utils.min.js"]
task :clean do
sh "rm -rf tmp && rm -rf dist"
end
task :default => :dist