1
1
require 'yaml'
2
2
include FileUtils
3
3
4
+
5
+ ## High level flow of the build:
6
+ ##
7
+ ## clean -> init -> concat -> minify -> package
8
+ ##
9
+
10
+
4
11
content = File . open ( 'angularFiles.js' , 'r' ) { |f | f . read }
5
12
files = eval ( content . gsub ( /\} ;(\s |\S )*/ , '}' ) .
6
13
gsub ( /angularFiles = / , '' ) .
@@ -36,8 +43,8 @@ task :clean do
36
43
end
37
44
38
45
39
- desc 'Compile Scenario'
40
- task :compile_scenario => :init do
46
+ desc 'Concat Scenario'
47
+ task :concat_scenario => :init do
41
48
42
49
concat_file ( 'angular-scenario.js' , [
43
50
'lib/jquery/jquery.js' ,
@@ -48,8 +55,9 @@ task :compile_scenario => :init do
48
55
] , gen_css ( 'css/angular.css' ) + "\n " + gen_css ( 'css/angular-scenario.css' ) )
49
56
end
50
57
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
53
61
54
62
concat_file ( 'jstd-scenario-adapter.js' , [
55
63
'src/ngScenario/jstd-scenario-adapter/angular.prefix' ,
@@ -67,9 +75,9 @@ task :compile_jstd_scenario_adapter => :init do
67
75
end
68
76
69
77
70
- desc 'Compile JavaScript'
71
- task :compile => [ :init , :compile_scenario , :compile_jstd_scenario_adapter ] do
72
78
79
+ desc 'Concat AngularJS files'
80
+ task :concat => :init do
73
81
concat_file ( 'angular.js' , [
74
82
'src/angular.prefix' ,
75
83
files [ 'angularSrc' ] ,
@@ -99,14 +107,24 @@ task :compile => [:init, :compile_scenario, :compile_jstd_scenario_adapter] do
99
107
100
108
FileUtils . cp 'src/ngMock/angular-mocks.js' , path_to ( 'angular-mocks.js' )
101
109
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
109
114
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
110
128
end
111
129
112
130
@@ -132,78 +150,18 @@ end
132
150
133
151
134
152
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"
200
156
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
202
160
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 )
205
163
206
- puts "Package created: #{ path_to ( tarball ) } "
164
+ puts "Package created: #{ path_to ( zip_file ) } "
207
165
end
208
166
209
167
284
242
285
243
286
244
def closure_compile ( filename )
287
- puts "Compiling #{ filename } ..."
245
+ puts "Minifying #{ filename } ..."
288
246
289
247
min_path = path_to ( filename . gsub ( /\. js$/ , '.min.js' ) )
290
248
302
260
303
261
304
262
def concat_file ( filename , deps , footer = '' )
305
- puts "Building #{ filename } ..."
263
+ puts "Creating #{ filename } ..."
306
264
File . open ( path_to ( filename ) , 'w' ) do |f |
307
265
concat = 'cat ' + deps . flatten . join ( ' ' )
308
266
0 commit comments