Skip to content

Commit a4fea38

Browse files
committed
chore(Rakefile): various build script changes
- restructure rake tasks this splits up the concatination and minification into two tasks so that we can just build angular.js quickly without wasting time with minification which is often not needed when just debugging some issue on 3rd party site. - use symlinks when creating final zip file - switch from btar to zip - get rid of version numbers from filenames - rewrite version numbers in all index files Closes angular#1226
1 parent 300c5c0 commit a4fea38

File tree

1 file changed

+42
-84
lines changed

1 file changed

+42
-84
lines changed

Rakefile

+42-84
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
require 'yaml'
22
include FileUtils
33

4+
5+
## High level flow of the build:
6+
##
7+
## clean -> init -> concat -> minify -> package
8+
##
9+
10+
411
content = File.open('angularFiles.js', 'r') {|f| f.read }
512
files = eval(content.gsub(/\};(\s|\S)*/, '}').
613
gsub(/angularFiles = /, '').
@@ -36,8 +43,8 @@ task :clean do
3643
end
3744

3845

39-
desc 'Compile Scenario'
40-
task :compile_scenario => :init do
46+
desc 'Concat Scenario'
47+
task :concat_scenario => :init do
4148

4249
concat_file('angular-scenario.js', [
4350
'lib/jquery/jquery.js',
@@ -48,8 +55,9 @@ task :compile_scenario => :init do
4855
], gen_css('css/angular.css') + "\n" + gen_css('css/angular-scenario.css'))
4956
end
5057

51-
desc 'Compile JSTD Scenario Adapter'
52-
task :compile_jstd_scenario_adapter => :init do
58+
59+
desc 'Concat JSTD Scenario Adapter'
60+
task :concat_jstd_scenario_adapter => :init do
5361

5462
concat_file('jstd-scenario-adapter.js', [
5563
'src/ngScenario/jstd-scenario-adapter/angular.prefix',
@@ -67,9 +75,9 @@ task :compile_jstd_scenario_adapter => :init do
6775
end
6876

6977

70-
desc 'Compile JavaScript'
71-
task :compile => [:init, :compile_scenario, :compile_jstd_scenario_adapter] do
7278

79+
desc 'Concat AngularJS files'
80+
task :concat => :init do
7381
concat_file('angular.js', [
7482
'src/angular.prefix',
7583
files['angularSrc'],
@@ -99,14 +107,24 @@ task :compile => [:init, :compile_scenario, :compile_jstd_scenario_adapter] do
99107

100108
FileUtils.cp 'src/ngMock/angular-mocks.js', path_to('angular-mocks.js')
101109

102-
closure_compile('angular.js')
103-
closure_compile('angular-cookies.js')
104-
closure_compile('angular-loader.js')
105-
closure_compile('angular-resource.js')
106-
closure_compile('angular-sanitize.js')
107-
closure_compile('angular-bootstrap.js')
108-
closure_compile('angular-bootstrap-prettify.js')
110+
rewrite_file(path_to('angular-mocks.js')) do |content|
111+
content.sub!('"NG_VERSION_FULL"', NG_VERSION.full)
112+
end
113+
end
109114

115+
116+
desc 'Minify JavaScript'
117+
task :minify => [:init, :concat, :concat_scenario, :concat_jstd_scenario_adapter] do
118+
[ 'angular.js',
119+
'angular-cookies.js',
120+
'angular-loader.js',
121+
'angular-resource.js',
122+
'angular-sanitize.js',
123+
'angular-bootstrap.js',
124+
'angular-bootstrap-prettify.js'
125+
].each do |file|
126+
closure_compile(file)
127+
end
110128
end
111129

112130

@@ -132,78 +150,18 @@ end
132150

133151

134152
desc 'Create angular distribution'
135-
task :package => [:clean, :compile, :docs] do
136-
tarball = "angular-#{NG_VERSION.full}.tgz"
137-
138-
pkg_dir = path_to("pkg/angular-#{NG_VERSION.full}")
139-
FileUtils.rm_r(path_to('pkg'), :force => true)
140-
FileUtils.mkdir_p(pkg_dir)
141-
142-
[ path_to('angular.js'),
143-
path_to('angular.min.js'),
144-
path_to('angular-loader.js'),
145-
path_to('angular-loader.min.js'),
146-
path_to('angular-bootstrap.js'),
147-
path_to('angular-bootstrap.min.js'),
148-
path_to('angular-bootstrap-prettify.js'),
149-
path_to('angular-bootstrap-prettify.min.js'),
150-
path_to('angular-mocks.js'),
151-
path_to('angular-cookies.js'),
152-
path_to('angular-cookies.min.js'),
153-
path_to('angular-resource.js'),
154-
path_to('angular-resource.min.js'),
155-
path_to('angular-sanitize.js'),
156-
path_to('angular-sanitize.min.js'),
157-
path_to('angular-scenario.js'),
158-
path_to('jstd-scenario-adapter.js'),
159-
path_to('jstd-scenario-adapter-config.js'),
160-
].each do |src|
161-
dest = src.gsub(/^.*\//, '').gsub(/((\.min)?\.js)$/, "-#{NG_VERSION.full}\\1")
162-
FileUtils.cp(src, pkg_dir + '/' + dest)
163-
end
164-
165-
FileUtils.cp_r path_to('i18n'), "#{pkg_dir}/i18n-#{NG_VERSION.full}"
166-
FileUtils.cp_r path_to('docs'), "#{pkg_dir}/docs-#{NG_VERSION.full}"
167-
168-
rewrite_file("#{pkg_dir}/angular-mocks-#{NG_VERSION.full}.js") do |content|
169-
content.sub!('"NG_VERSION_FULL"', NG_VERSION.full)
170-
end
171-
172-
173-
[ "#{pkg_dir}/docs-#{NG_VERSION.full}/index.html",
174-
"#{pkg_dir}/docs-#{NG_VERSION.full}/index-jq.html",
175-
"#{pkg_dir}/docs-#{NG_VERSION.full}/index-nocache.html",
176-
"#{pkg_dir}/docs-#{NG_VERSION.full}/index-jq-nocache.html",
177-
"#{pkg_dir}/docs-#{NG_VERSION.full}/index-debug.html",
178-
"#{pkg_dir}/docs-#{NG_VERSION.full}/index-jq-debug.html"
179-
].each do |src|
180-
rewrite_file(src) do |content|
181-
content.gsub!(/'angular(.*)\.js/, '\'angular\1-' + NG_VERSION.full + '.js')
182-
end
183-
end
184-
185-
186-
rewrite_file("#{pkg_dir}/docs-#{NG_VERSION.full}/docs-scenario.html") do |content|
187-
content.sub!('angular-scenario.js', "angular-scenario-#{NG_VERSION.full}.js")
188-
end
189-
190-
191-
[ "#{pkg_dir}/docs-#{NG_VERSION.full}/appcache.manifest",
192-
"#{pkg_dir}/docs-#{NG_VERSION.full}/appcache-offline.manifest"
193-
].each do |src|
194-
rewrite_file(src) do |content|
195-
content.sub!('../angular.min.js', "angular-#{NG_VERSION.full}.min.js").
196-
sub!('/build/docs/', "/#{NG_VERSION.full}/docs-#{NG_VERSION.full}/")
197-
end
198-
end
199-
153+
task :package => [:clean, :minify, :docs] do
154+
zip_dir = "angular-#{NG_VERSION.full}"
155+
zip_file = "#{zip_dir}.zip"
200156

201-
%x(tar -czf #{path_to(tarball)} -C #{path_to('pkg')} .)
157+
FileUtils.ln_s BUILD_DIR, zip_dir
158+
%x(zip -r #{zip_file} .)
159+
FileUtils.rm zip_dir
202160

203-
FileUtils.cp path_to(tarball), pkg_dir
204-
FileUtils.mv pkg_dir, path_to(['pkg', NG_VERSION.full])
161+
FileUtils.mv zip_file, path_to(zip_file)
162+
FileUtils.ln_s '../', path_to(NG_VERSION.full)
205163

206-
puts "Package created: #{path_to(tarball)}"
164+
puts "Package created: #{path_to(zip_file)}"
207165
end
208166

209167

@@ -284,7 +242,7 @@ end
284242

285243

286244
def closure_compile(filename)
287-
puts "Compiling #{filename} ..."
245+
puts "Minifying #{filename} ..."
288246

289247
min_path = path_to(filename.gsub(/\.js$/, '.min.js'))
290248

@@ -302,7 +260,7 @@ end
302260

303261

304262
def concat_file(filename, deps, footer='')
305-
puts "Building #{filename} ..."
263+
puts "Creating #{filename} ..."
306264
File.open(path_to(filename), 'w') do |f|
307265
concat = 'cat ' + deps.flatten.join(' ')
308266

0 commit comments

Comments
 (0)