forked from emberjs/ember.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Assetfile
251 lines (212 loc) · 6.57 KB
/
Assetfile
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
Encoding.default_external = "UTF-8" if defined?(Encoding)
require "rake-pipeline-web-filters"
require "json"
require "uglifier"
require "execjs"
class EmberStripDebugMessagesFilter < Rake::Pipeline::Filter
def strip_debug(data)
# Strip debug code
data.gsub!(%r{^(\s)*Ember\.(assert|deprecate|warn)\((.*)\).*$}, "")
end
def add_localhost_warning(data)
data << "\n\n" + <<END
if (typeof location !== 'undefined' && (location.hostname === 'localhost' || location.hostname === '127.0.0.1')) {
console.warn("You are running a production build of Ember on localhost and won't receive detailed error messages. "+
"If you want full error messages please use the non-minified build provided on the Ember website.");
}
END
end
def generate_output(inputs, output)
inputs.each do |input|
result = File.read(input.fullpath)
strip_debug(result)
add_localhost_warning(result)
output.write result
end
end
end
class HandlebarsPrecompiler < Rake::Pipeline::Filter
class << self
def context
unless @context
contents = <<END
exports = {};
#{File.read("dist/ember-template-compiler.js")}
function precompileEmberHandlebars(string) {
return exports.precompile(string).toString();
}
END
@context = ExecJS.compile(contents)
end
@context
end
end
def precompile_templates(data)
# Precompile defaultTemplates
data.gsub!(%r{(defaultTemplate(?:\s*=|:)\s*)precompileTemplate\(['"](.*)['"]\)}) do
"#{$1}Ember.Handlebars.template(#{self.class.context.call("precompileEmberHandlebars", $2)})"
end
end
def generate_output(inputs, output)
inputs.each do |input|
result = File.read(input.fullpath)
precompile_templates(result)
output.write result
end
end
end
class EmberLicenseFilter < Rake::Pipeline::Filter
def license
@license ||= File.read("generators/license.js")
end
def generate_output(inputs, output)
inputs.each do |input|
file = File.read(input.fullpath)
output.write "#{license}\n\n#{file}"
end
end
end
class AddMicroLoader < Rake::Pipeline::Filter
LOADER = File.expand_path("../packages/loader/lib/main.js", __FILE__)
def initialize(options={}, &block)
super(&block)
@global = options[:global]
end
def generate_output(inputs, output)
output.write "(function() {\n" unless @global
output.write File.read(LOADER)
inputs.each do |input|
output.write input.read
end
output.write "\n})();\n" unless @global
end
def additional_dependencies(input)
[ LOADER ]
end
end
class JSHintRC < Rake::Pipeline::Filter
JSHINTRC = File.expand_path("../.jshintrc", __FILE__)
def jshintrc
@jshintrc ||= File.read(JSHINTRC)
end
def generate_output(inputs, output)
inputs.each do |input|
file = File.read(input.fullpath)
output.write "var JSHINTRC = #{jshintrc};\n\n#{file}"
end
end
def additional_dependencies(input)
[ JSHINTRC ]
end
end
class VersionInfo < Rake::Pipeline::Filter
def version_info
@version_info ||= begin
latest_tag = `git describe --tags`
last_commit = `git log -n 1 --format="%h (%ci)"`
out = "// Version: #{latest_tag}"
out << "// Last commit: #{last_commit}"
out
end
end
def generate_output(inputs, output)
inputs.each do |input|
file = File.read(input.fullpath)
output.write "#{version_info}\n\n#{file}"
end
end
end
class EmberStub < Rake::Pipeline::Filter
def generate_output(inputs, output)
inputs.each do |input|
file = File.read(input.fullpath)
out = "(function() {\nvar Ember = { assert: function() {} };\n"
out << file
out << "\nexports.precompile = Ember.Handlebars.precompile;"
out << "\n})()"
output.write out
end
end
end
distros = {
"runtime" => %w(ember-metal rsvp container ember-runtime),
"template-compiler" => %w(handlebars ember-handlebars-compiler),
"data-deps" => %w(ember-metal rsvp container ember-runtime ember-states),
"full" => %w(ember-metal rsvp container ember-runtime ember-views metamorph ember-handlebars-compiler ember-handlebars ember-routing ember-application ember-states),
"old-router" => %w(ember-metal rsvp container ember-runtime ember-views ember-states ember-viewstates metamorph ember-handlebars-compiler ember-handlebars ember-old-router )
}
output "dist"
input "packages" do
output "tests"
match "*/tests/**/*.js" do
minispade :rewrite_requires => true, :string => true, :module_id_generator => proc { |input|
id = input.path.dup
id.sub!(/\.js$/, '')
id.sub!(/\/main$/, '')
id.sub!('/tests', '/~tests')
id
}
concat "ember-tests.js"
end
match "ember-tests.js" do
filter JSHintRC
end
end
input "packages" do
match "*/lib/**/*.js" do
minispade :rewrite_requires => true, :string => true, :module_id_generator => proc { |input|
id = input.path.dup
id.sub!('/lib/', '/')
id.sub!(/\.js$/, '')
id.sub!(/\/main$/, '')
id
}
concat "ember-spade.js"
filter AddMicroLoader, :global => true
end
end
input "packages" do
match "*/lib/**/main.js" do
neuter(
:additional_dependencies => proc { |input|
Dir.glob(File.join(File.dirname(input.fullpath),'**','*.js'))
},
:path_transform => proc { |path, input|
package, path = path.split('/', 2)
current_package = input.path.split('/', 2)[0]
current_package == package && path ? File.join(package, "lib", "#{path}.js") : nil
},
:closure_wrap => true
) do |filename|
File.join("modules/", filename.gsub('/lib/main.js', '.js'))
end
end
end
distros.each do |name, modules|
name = name == "full" ? "ember" : "ember-#{name}"
input "dist/modules" do
module_paths = modules.map{|m| "#{m}.js" }
match "{#{module_paths.join(',')}}" do
concat(module_paths){ ["#{name}.js", "#{name}.prod.js"] }
filter HandlebarsPrecompiler
filter AddMicroLoader unless name == "ember-template-compiler"
end
# Add debug to the main distro
match "{#{name}.js,ember-debug.js}" do
filter VersionInfo
concat ["ember-debug.js"], "#{name}.js" unless name == "ember-template-compiler"
filter EmberStub if name == "ember-template-compiler"
end
# Strip dev code
match "#{name}.prod.js" do
filter(EmberStripDebugMessagesFilter) { ["#{name}.prod.js", "min/#{name}.js"] }
end
# Minify
match "min/#{name}.js" do
uglify{ "#{name}.min.js" }
filter VersionInfo
filter EmberLicenseFilter
end
end
end
# vim: filetype=ruby