forked from emberjs/ember.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
201 lines (153 loc) · 5.79 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
require File.expand_path("../vendor/bundler/setup", __FILE__)
require "erb"
require "uglifier"
require "sproutcore"
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 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
# Set up the intermediate and output directories for the interim build process
SproutCore::Compiler.intermediate = "tmp/intermediate"
SproutCore::Compiler.output = "tmp/static"
# Create a compile task for a SproutCore package. This task will compute
# dependencies and output a single JS file for a package.
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
## TASKS ##
# Create sproutcore:package tasks for each of the SproutCore packages
namespace :sproutcore do
%w(metal runtime handlebars views).each do |package|
task package => compile_package_task("sproutcore-#{package}")
end
end
# Create a handlebars task
task :handlebars => compile_package_task("handlebars")
# Create a metamorph task
task :metamorph => compile_package_task("metamorph")
# Create a build task that depends on all of the package dependencies
task :build => ["sproutcore:metal", "sproutcore:runtime", "sproutcore:handlebars", "sproutcore:views", :handlebars, :metamorph]
# Strip out require lines from sproutcore.js. For the interim, requires are
# precomputed by the compiler so they are no longer necessary at runtime.
file "dist/sproutcore.js" => :build do
puts "Generating sproutcore.js"
mkdir_p "dist"
File.open("dist/sproutcore.js", "w") do |file|
file.puts strip_require("tmp/static/handlebars.js")
file.puts strip_require("tmp/static/sproutcore-metal.js")
file.puts strip_require("tmp/static/sproutcore-runtime.js")
file.puts strip_require("tmp/static/sproutcore-views.js")
file.puts strip_require("tmp/static/metamorph.js")
file.puts strip_require("tmp/static/sproutcore-handlebars.js")
end
end
# Minify dist/sproutcore.js to dist/sproutcore.min.js
file "dist/sproutcore.min.js" => "dist/sproutcore.js" do
puts "Generating sproutcore.min.js"
File.open("dist/sproutcore.prod.js", "w") do |file|
file.puts strip_sc_assert("dist/sproutcore.js")
end
File.open("dist/sproutcore.min.js", "w") do |file|
file.puts uglify("dist/sproutcore.prod.js")
end
rm "dist/sproutcore.prod.js"
end
SC_VERSION = File.read("VERSION")
desc "bump the version to the specified version"
task :bump_version, :version do |t, args|
version = args[:version]
File.open("VERSION", "w") { |file| file.write version }
# Bump the version of subcomponents required by the "umbrella" sproutcore
# package.
contents = File.read("packages/sproutcore/package.json")
contents.gsub! %r{"sproutcore-(\w+)": .*$} do
%{"sproutcore-#{$1}": "#{version}"}
end
File.open("packages/sproutcore/package.json", "w") do |file|
file.write contents
end
# Bump the version of each component package
Dir["packages/sproutcore*/package.json", "package.json"].each do |package|
contents = File.read(package)
contents.gsub! %r{"version": .*$}, %{"version": "#{version}",}
contents.gsub! %r{"(sproutcore-?\w*)": [^\n\{,]*(,?)$} do
%{"#{$1}": "#{version}"#{$2}}
end
File.open(package, "w") { |file| file.write contents }
end
sh %{git add VERSION package.json packages/**/package.json}
sh %{git commit -m "Bump version to #{version}"}
end
## STARTER KIT ##
namespace :starter_kit do
sproutcore_output = "tmp/starter-kit/js/libs/sproutcore-#{SC_VERSION}.js"
sproutcore_min_output = "tmp/starter-kit/js/libs/sproutcore-#{SC_VERSION}.min.js"
task :pull => "tmp/starter-kit" do
Dir.chdir("tmp/starter-kit") do
sh "git pull origin master"
end
end
task :clean => :pull do
Dir.chdir("tmp/starter-kit") do
rm_rf Dir["js/libs/sproutcore*.js"]
end
end
task "dist/starter-kit.#{SC_VERSION}.zip" => ["tmp/starter-kit/index.html"] do
mkdir_p "dist"
Dir.chdir("tmp") do
sh %{zip -r ../dist/starter-kit.#{SC_VERSION}.zip starter-kit -x "starter-kit/.git/*"}
end
end
file sproutcore_output => [:clean, "tmp/starter-kit", "dist/sproutcore.js"] do
sh "cp dist/sproutcore.js #{sproutcore_output}"
end
file sproutcore_min_output => [:clean, "tmp/starter-kit", "dist/sproutcore.min.js"] do
sh "cp dist/sproutcore.min.js #{sproutcore_min_output}"
end
file "tmp/starter-kit" do
mkdir_p "tmp"
Dir.chdir("tmp") do
sh "git clone git://github.com/sproutcore/starter-kit.git"
end
end
file "tmp/starter-kit/index.html" => [sproutcore_output, sproutcore_min_output] do
index = File.read("tmp/starter-kit/index.html")
index.gsub! %r{<script src="js/libs/sproutcore-\d\.\d.*</script>},
%{<script src="js/libs/sproutcore-#{SC_VERSION}.min.js"></script>}
File.open("tmp/starter-kit/index.html", "w") { |f| f.write index }
end
task :index => "tmp/starter-kit/index.html"
desc "Build the SproutCore starter kit"
task :build => "dist/starter-kit.#{SC_VERSION}.zip"
end
desc "Build SproutCore"
task :dist => ["dist/sproutcore.min.js"]
desc "Clean build artifacts from previous builds"
task :clean do
sh "rm -rf tmp && rm -rf dist"
end
task :default => :dist