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
|
# File 'lib/high_five/thor/tasks/deploy.rb', line 18
def deploy(target)
@environment = options[:environment]
@platform = target
@weinre_url = options[:weinre_url]
@copy_files = options[:"copy-files"]
@meta = {}
@config = base_config.build_platform_config(@platform).build_platform_config(@environment)
@config_root = File.join("config", "high_five")
self.source_paths << File.join(base_config.root, @config_root)
self.source_paths << File.join(base_config.root)
self.source_paths << File.join(File.dirname(__FILE__), '..', '..', 'generators')
@config.asset_paths.each do |asset_path|
self.source_paths << asset_path
end
raise "Please set config.destination" if @config.destination.nil?
self.destination_root = @config.destination
FileUtils.rm_rf(self.destination_root)
FileUtils.mkdir_p(self.destination_root)
say "Deploying app: <#{@platform}> <#{options[:environment]}>"
say "\t#{self.destination_root}"
say " -Weinre url: #{@weinre_url}" if @weinre_url
if @config.compass_dir
compass_dir = File.join(base_config.root, @config.compass_dir)
say "Precompiling compass styles from #{compass_dir}}"
pwd = Dir.pwd
Dir.chdir compass_dir
success = false
if @environment == "production"
success = system("compass compile --force --no-debug-info -e production")
else
success = system("compass compile --force --no-debug-info")
end
unless success
raise "Error compiling CSS, aborting build"
end
Dir.chdir pwd
end
platform_file = File.join(@config_root, "app-#{@platform}.js")
bundle = builder.find_asset platform_file
if bundle.nil?
p source_paths
error "#{@platform} is not a valid target. Please create #{platform_file}" and Process.exit
end
if (@environment == "production")
appjs = File.join(self.destination_root, "app.js")
@javascripts = ["app.js"]
output_js = nil
if @config.minify == :uglifier
say " uglify #{appjs}", :green
output_js = Uglifier.compile(bundle.to_s)
elsif @config.minify == :yui
say " minify #{appjs}", :green
output_js = YUI::JavaScriptCompressor.new.compress(bundle.to_s)
else
say " create #{appjs}", :green
output_js = bundle.to_s
end
File.open(appjs, "w") do |file|
file.write output_js
end
output_js = nil
else
@javascripts = []
bundle.dependencies.each do |asset|
next if asset.logical_path =~ /^config\/high_five/ copy_file asset.logical_path
@javascripts << asset.logical_path
end
end
@config.static_javascripts.each do |javascript|
if File.directory? javascript
directory javascript
@javascripts.unshift(*Dir[File.join(javascript,'**','*.js')])
else
copy_file javascript unless javascript =~ /^https?:\/\//
@javascripts.unshift javascript
end
end
@stylesheets = []
@config.sass_files.each do |sass_file|
asset_name = File.basename(sass_file, File.extname(sass_file))
css_file = File.join(self.destination_root, "stylesheets", "#{asset_name}.css")
say "Compiling #{sass_file} -> #{css_file}"
Sass.compile_file sass_file, css_file
@stylesheets.push css_file
copy_file css_file
end
@config.static_stylesheets.each do |stylesheet|
if File.directory? stylesheet
directory stylesheet
@stylesheets.unshift(*Dir[File.join(stylesheet,'**','*.css')])
else
copy_file stylesheet
@stylesheets.unshift stylesheet
end
end
@config.static_assets.each do |path, options|
asset = find_in_source_paths(path)
destination = path
if (options[:destination])
destination = File.join(self.destination_root, options[:destination])
end
if File.directory? asset
directory asset, destination
else
copy_file asset, destination
end
end
if (@config.manifest && @environment == 'production')
@manifest_attr = %Q(manifest="manifest.appcache") say " create manifest", :green
@manifest_cache = @config.static_assets.collect do |path, options|
if (File.directory?(path))
Dir.glob(path + "/**/*").reject {|x| File.directory?(x) }
else
path
end
end.flatten
@manifest_cache += @javascripts
@manifest_cache += @stylesheets
template "manifest.erb", File.join(self.destination_root, "manifest.appcache")
end
@high_five_javascript = @config.high_five_javascript
say "Generating index.html"
template File.join(@config_root, "index.html.erb"), File.join(self.destination_root, "index.html")
if (@environment == 'development' && !@config.dev_index.nil?)
say "Cloning to #{@config.dev_index}"
FileUtils.cp(File.join(self.destination_root, "index.html"), File.join(@config.root, @config.dev_index))
end
end
|