forked from emberjs/ember.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAssetfile
152 lines (128 loc) · 3.69 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
require "rake-pipeline-web-filters"
require "json"
require "uglifier"
require "execjs"
class EmberProductionFilter < Rake::Pipeline::Filter
def js_context
# We're using Ember to build Ember! Inception!
unless @context
headless = File.read("lib/headless-ember.js")
ember = File.read("lib/ember.js")
@context = ExecJS.compile([headless, ember].join("\n"))
end
@context
end
def strip_debug(data)
# Strip debug code
data.gsub!(%r{^(\s)*Ember\.(assert|deprecate|warn)\((.*)\).*$}, "")
end
def precompile_templates(data)
# Precompile defaultTemplates
data.gsub!(%r{(defaultTemplate(?:\s*=|:)\s*)Ember\.Handlebars\.compile\(['"](.*)['"]\)}) do
"#{$1}Ember.Handlebars.template(#{js_context.call("precompileEmberHandlebars", $2)})"
end
end
def generate_output(inputs, output)
inputs.each do |input|
result = File.read(input.fullpath)
strip_debug(result)
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 JSHintRC < Rake::Pipeline::Filter
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
end
distros = {
:runtime => %w(ember-metal ember-runtime),
:full => %w(handlebars ember-metal ember-runtime ember-application ember-views ember-states ember-viewstates metamorph ember-handlebars)
}
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"
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"] }
end
# Add debug to the main distro
match "{#{name}.js,ember-debug.js}" do
concat ["ember-debug.js"], "#{name}.js"
end
# Strip dev code
match "#{name}.prod.js" do
filter(EmberProductionFilter) { ["#{name}.prod.js", "#{name}.min.js"] }
end
# Minify
match "#{name}.min.js" do
uglify{ "#{name}.min.js" }
filter EmberLicenseFilter
end
end
end
# vim: filetype=ruby