@@ -64,6 +64,16 @@ task :default => [:compile, :test]
6464desc 'Init the build workspace'
6565task :init do
6666 FileUtils . mkdir ( BUILD_DIR ) unless File . directory? ( BUILD_DIR )
67+
68+ v = YAML ::load ( File . open ( 'version.yaml' ) )
69+ match = v [ 'version' ] . match ( /^([^-]*)(-snapshot)?$/ )
70+
71+ NG_VERSION = Struct . new ( :full , :major , :minor , :dot , :codename ) .
72+ new ( match [ 1 ] + ( match [ 2 ] ? ( '-' + %x(git rev-parse HEAD) [ 0 ..7 ] ) : '' ) ,
73+ match [ 1 ] . split ( '.' ) [ 0 ] ,
74+ match [ 1 ] . split ( '.' ) [ 1 ] ,
75+ match [ 1 ] . split ( '.' ) [ 2 ] ,
76+ v [ 'codename' ] )
6777end
6878
6979
@@ -188,9 +198,17 @@ task :compile => [:init, :compile_scenario, :compile_jstd_scenario_adapter, :gen
188198
189199 File . open ( path_to ( 'angular.js' ) , 'w' ) do |f |
190200 concat = 'cat ' + deps . flatten . join ( ' ' )
191- f . write ( %x{#{ concat } } .
201+
202+ content = %x{#{ concat } } .
203+ gsub ( '"NG_VERSION_FULL"' , NG_VERSION . full ) .
204+ gsub ( '"NG_VERSION_MAJOR"' , NG_VERSION . major ) .
205+ gsub ( '"NG_VERSION_MINOR"' , NG_VERSION . minor ) .
206+ gsub ( '"NG_VERSION_DOT"' , NG_VERSION . dot ) .
207+ gsub ( '"NG_VERSION_CODENAME"' , NG_VERSION . codename ) .
192208 gsub ( /^\s *['"]use strict['"];?\s *$/ , '' ) . # remove all file-specific strict mode flags
193- gsub ( /'USE STRICT'/ , "'use strict'" ) ) # rename the placeholder in angular.prefix
209+ gsub ( /'USE STRICT'/ , "'use strict'" ) # rename the placeholder in angular.prefix
210+
211+ f . write ( content )
194212 f . write ( gen_css ( 'css/angular.css' , true ) )
195213 end
196214
210228
211229desc 'Create angular distribution'
212230task :package => [ :clean , :compile , :docs ] do
213- v = YAML ::load ( File . open ( 'version.yaml' ) ) [ 'version' ]
214- match = v . match ( /^([^-]*)(-snapshot)?$/ )
215- version = match [ 1 ] + ( match [ 2 ] ? ( '-' + %x(git rev-parse HEAD) [ 0 ..7 ] ) : '' )
216-
217- tarball = "angular-#{ version } .tgz"
231+ tarball = "angular-#{ NG_VERSION . full } .tgz"
218232
219- pkg_dir = path_to ( "pkg/angular-#{ version } " )
233+ pkg_dir = path_to ( "pkg/angular-#{ NG_VERSION . full } " )
220234 FileUtils . rm_r ( path_to ( 'pkg' ) , :force => true )
221235 FileUtils . mkdir_p ( pkg_dir )
222236
@@ -228,35 +242,36 @@ task :package => [:clean, :compile, :docs] do
228242 path_to ( 'jstd-scenario-adapter.js' ) ,
229243 path_to ( 'jstd-scenario-adapter-config.js' ) ,
230244 ] . each do |src |
231- dest = src . gsub ( /^[^\/ ]+\/ / , '' ) . gsub ( /((\. min)?\. js)$/ , "-#{ version } \\ 1" )
245+ dest = src . gsub ( /^[^\/ ]+\/ / , '' ) . gsub ( /((\. min)?\. js)$/ , "-#{ NG_VERSION . full } \\ 1" )
232246 FileUtils . cp ( src , pkg_dir + '/' + dest )
233247 end
234248
235- FileUtils . cp_r path_to ( 'docs' ) , "#{ pkg_dir } /docs-#{ version } "
249+ FileUtils . cp_r path_to ( 'docs' ) , "#{ pkg_dir } /docs-#{ NG_VERSION . full } "
236250
237- File . open ( "#{ pkg_dir } /docs-#{ version } /index.html" , File ::RDWR ) do |f |
251+ File . open ( "#{ pkg_dir } /docs-#{ NG_VERSION . full } /index.html" , File ::RDWR ) do |f |
238252 text = f . read
239253 f . rewind
240- f . write text . sub ( 'angular.min.js' , "angular-#{ version } .min.js" )
254+ f . write text . sub ( 'angular.min.js' , "angular-#{ NG_VERSION . full } .min.js" )
241255 end
242256
243- File . open ( "#{ pkg_dir } /docs-#{ version } /docs-scenario.html" , File ::RDWR ) do |f |
257+ File . open ( "#{ pkg_dir } /docs-#{ NG_VERSION . full } /docs-scenario.html" , File ::RDWR ) do |f |
244258 text = f . read
245259 f . rewind
246- f . write text . sub ( 'angular-scenario.js' , "angular-scenario-#{ version } .js" )
260+ f . write text . sub ( 'angular-scenario.js' , "angular-scenario-#{ NG_VERSION . full } .js" )
247261 end
248262
249- File . open ( "#{ pkg_dir } /docs-#{ version } /appcache.manifest" , File ::RDWR ) do |f |
263+ File . open ( "#{ pkg_dir } /docs-#{ NG_VERSION . full } /appcache.manifest" , File ::RDWR ) do |f |
264+
250265 text = f . read
251266 f . rewind
252- f . write text . sub ( 'angular.min.js' , "angular-#{ version } .min.js" )
267+ f . write text . sub ( 'angular.min.js' , "angular-#{ NG_VERSION . full } .min.js" )
253268 end
254269
255270
256271 %x(tar -czf #{ path_to ( tarball ) } -C #{ path_to ( 'pkg' ) } .)
257272
258273 FileUtils . cp path_to ( tarball ) , pkg_dir
259- FileUtils . mv pkg_dir , path_to ( [ 'pkg' , version ] )
274+ FileUtils . mv pkg_dir , path_to ( [ 'pkg' , NG_VERSION . full ] )
260275
261276 puts "Package created: #{ path_to ( tarball ) } "
262277end
0 commit comments