Skip to content

Commit 0782422

Browse files
Di PengIgorMinar
authored andcommitted
feat(angular.version): add angular.version
- placeholders are replaced with actual angular versions when doing rake compile
1 parent 8fa0661 commit 0782422

File tree

4 files changed

+68
-18
lines changed

4 files changed

+68
-18
lines changed

Rakefile

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@ task :default => [:compile, :test]
6464
desc 'Init the build workspace'
6565
task :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'])
6777
end
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

@@ -210,13 +228,9 @@ end
210228

211229
desc 'Create angular distribution'
212230
task :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)}"
262277
end

src/Angular.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,3 +1004,25 @@ function assertArg(arg, name, reason) {
10041004
function assertArgFn(arg, name) {
10051005
assertArg(isFunction(arg, name, 'not a function'));
10061006
}
1007+
1008+
1009+
/**
1010+
* @ngdoc property
1011+
* @name angular.version
1012+
* @description
1013+
* Object which contains information about the current AngularJS version. The object has following
1014+
* properties:
1015+
*
1016+
* - `full` – `{string}` – full version string, e.g. "0.9.18"
1017+
* - `major` – `{number}` – major version number, e.g. 0
1018+
* - `minor` – `{number}` – minor version number, e.g. 9
1019+
* - `dot` – `{number}` – dot version number, e.g. 18
1020+
* - `codeName` – `{string}` – code name of the release, e.g. "jiggling-armfat"
1021+
*/
1022+
var version = {
1023+
full: '"NG_VERSION_FULL"', // all of these placeholder strings will be replaced by rake's
1024+
major: "NG_VERSION_MAJOR", // compile task
1025+
minor: "NG_VERSION_MINOR",
1026+
dot: "NG_VERSION_DOT",
1027+
codeName: '"NG_VERSION_CODENAME"'
1028+
}

src/AngularPublic.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ angularService('$browser', function($log){
1919
return browserSingleton;
2020
}, {$inject:['$log']});
2121

22+
2223
extend(angular, {
2324
// disabled for now until we agree on public name
2425
//'annotate': annotate,
@@ -41,7 +42,8 @@ extend(angular, {
4142
'isFunction': isFunction,
4243
'isObject': isObject,
4344
'isNumber': isNumber,
44-
'isArray': isArray
45+
'isArray': isArray,
46+
'version': version
4547
});
4648

4749
//try to bind to jquery now so that one can write angular.element().read()

test/AngularSpec.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,4 +625,15 @@ describe('angular', function(){
625625
});
626626
});
627627

628+
629+
describe('version', function() {
630+
it('version should have full/major/minor/dot/codeName properties', function() {
631+
expect(version).toBeDefined();
632+
expect(version.full).toBe('"NG_VERSION_FULL"');
633+
expect(version.major).toBe("NG_VERSION_MAJOR");
634+
expect(version.minor).toBe("NG_VERSION_MINOR");
635+
expect(version.dot).toBe("NG_VERSION_DOT");
636+
expect(version.codeName).toBe('"NG_VERSION_CODENAME"');
637+
});
638+
})
628639
});

0 commit comments

Comments
 (0)