mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-16 23:30:23 +00:00
feat(angular.version): add angular.version
- placeholders are replaced with actual angular versions when doing rake compile
This commit is contained in:
parent
8fa066190a
commit
0782422d1f
4 changed files with 68 additions and 18 deletions
49
Rakefile
49
Rakefile
|
|
@ -64,6 +64,16 @@ task :default => [:compile, :test]
|
|||
desc 'Init the build workspace'
|
||||
task :init do
|
||||
FileUtils.mkdir(BUILD_DIR) unless File.directory?(BUILD_DIR)
|
||||
|
||||
v = YAML::load( File.open( 'version.yaml' ) )
|
||||
match = v['version'].match(/^([^-]*)(-snapshot)?$/)
|
||||
|
||||
NG_VERSION = Struct.new(:full, :major, :minor, :dot, :codename).
|
||||
new(match[1] + (match[2] ? ('-' + %x(git rev-parse HEAD)[0..7]) : ''),
|
||||
match[1].split('.')[0],
|
||||
match[1].split('.')[1],
|
||||
match[1].split('.')[2],
|
||||
v['codename'])
|
||||
end
|
||||
|
||||
|
||||
|
|
@ -188,9 +198,17 @@ task :compile => [:init, :compile_scenario, :compile_jstd_scenario_adapter, :gen
|
|||
|
||||
File.open(path_to('angular.js'), 'w') do |f|
|
||||
concat = 'cat ' + deps.flatten.join(' ')
|
||||
f.write(%x{#{concat}}.
|
||||
|
||||
content = %x{#{concat}}.
|
||||
gsub('"NG_VERSION_FULL"', NG_VERSION.full).
|
||||
gsub('"NG_VERSION_MAJOR"', NG_VERSION.major).
|
||||
gsub('"NG_VERSION_MINOR"', NG_VERSION.minor).
|
||||
gsub('"NG_VERSION_DOT"', NG_VERSION.dot).
|
||||
gsub('"NG_VERSION_CODENAME"', NG_VERSION.codename).
|
||||
gsub(/^\s*['"]use strict['"];?\s*$/, ''). # remove all file-specific strict mode flags
|
||||
gsub(/'USE STRICT'/, "'use strict'")) # rename the placeholder in angular.prefix
|
||||
gsub(/'USE STRICT'/, "'use strict'") # rename the placeholder in angular.prefix
|
||||
|
||||
f.write(content)
|
||||
f.write(gen_css('css/angular.css', true))
|
||||
end
|
||||
|
||||
|
|
@ -210,13 +228,9 @@ end
|
|||
|
||||
desc 'Create angular distribution'
|
||||
task :package => [:clean, :compile, :docs] do
|
||||
v = YAML::load( File.open( 'version.yaml' ) )['version']
|
||||
match = v.match(/^([^-]*)(-snapshot)?$/)
|
||||
version = match[1] + (match[2] ? ('-' + %x(git rev-parse HEAD)[0..7]) : '')
|
||||
tarball = "angular-#{NG_VERSION.full}.tgz"
|
||||
|
||||
tarball = "angular-#{version}.tgz"
|
||||
|
||||
pkg_dir = path_to("pkg/angular-#{version}")
|
||||
pkg_dir = path_to("pkg/angular-#{NG_VERSION.full}")
|
||||
FileUtils.rm_r(path_to('pkg'), :force => true)
|
||||
FileUtils.mkdir_p(pkg_dir)
|
||||
|
||||
|
|
@ -228,35 +242,36 @@ task :package => [:clean, :compile, :docs] do
|
|||
path_to('jstd-scenario-adapter.js'),
|
||||
path_to('jstd-scenario-adapter-config.js'),
|
||||
].each do |src|
|
||||
dest = src.gsub(/^[^\/]+\//, '').gsub(/((\.min)?\.js)$/, "-#{version}\\1")
|
||||
dest = src.gsub(/^[^\/]+\//, '').gsub(/((\.min)?\.js)$/, "-#{NG_VERSION.full}\\1")
|
||||
FileUtils.cp(src, pkg_dir + '/' + dest)
|
||||
end
|
||||
|
||||
FileUtils.cp_r path_to('docs'), "#{pkg_dir}/docs-#{version}"
|
||||
FileUtils.cp_r path_to('docs'), "#{pkg_dir}/docs-#{NG_VERSION.full}"
|
||||
|
||||
File.open("#{pkg_dir}/docs-#{version}/index.html", File::RDWR) do |f|
|
||||
File.open("#{pkg_dir}/docs-#{NG_VERSION.full}/index.html", File::RDWR) do |f|
|
||||
text = f.read
|
||||
f.rewind
|
||||
f.write text.sub('angular.min.js', "angular-#{version}.min.js")
|
||||
f.write text.sub('angular.min.js', "angular-#{NG_VERSION.full}.min.js")
|
||||
end
|
||||
|
||||
File.open("#{pkg_dir}/docs-#{version}/docs-scenario.html", File::RDWR) do |f|
|
||||
File.open("#{pkg_dir}/docs-#{NG_VERSION.full}/docs-scenario.html", File::RDWR) do |f|
|
||||
text = f.read
|
||||
f.rewind
|
||||
f.write text.sub('angular-scenario.js', "angular-scenario-#{version}.js")
|
||||
f.write text.sub('angular-scenario.js', "angular-scenario-#{NG_VERSION.full}.js")
|
||||
end
|
||||
|
||||
File.open("#{pkg_dir}/docs-#{version}/appcache.manifest", File::RDWR) do |f|
|
||||
File.open("#{pkg_dir}/docs-#{NG_VERSION.full}/appcache.manifest", File::RDWR) do |f|
|
||||
|
||||
text = f.read
|
||||
f.rewind
|
||||
f.write text.sub('angular.min.js', "angular-#{version}.min.js")
|
||||
f.write text.sub('angular.min.js', "angular-#{NG_VERSION.full}.min.js")
|
||||
end
|
||||
|
||||
|
||||
%x(tar -czf #{path_to(tarball)} -C #{path_to('pkg')} .)
|
||||
|
||||
FileUtils.cp path_to(tarball), pkg_dir
|
||||
FileUtils.mv pkg_dir, path_to(['pkg', version])
|
||||
FileUtils.mv pkg_dir, path_to(['pkg', NG_VERSION.full])
|
||||
|
||||
puts "Package created: #{path_to(tarball)}"
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1004,3 +1004,25 @@ function assertArg(arg, name, reason) {
|
|||
function assertArgFn(arg, name) {
|
||||
assertArg(isFunction(arg, name, 'not a function'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @ngdoc property
|
||||
* @name angular.version
|
||||
* @description
|
||||
* Object which contains information about the current AngularJS version. The object has following
|
||||
* properties:
|
||||
*
|
||||
* - `full` – `{string}` – full version string, e.g. "0.9.18"
|
||||
* - `major` – `{number}` – major version number, e.g. 0
|
||||
* - `minor` – `{number}` – minor version number, e.g. 9
|
||||
* - `dot` – `{number}` – dot version number, e.g. 18
|
||||
* - `codeName` – `{string}` – code name of the release, e.g. "jiggling-armfat"
|
||||
*/
|
||||
var version = {
|
||||
full: '"NG_VERSION_FULL"', // all of these placeholder strings will be replaced by rake's
|
||||
major: "NG_VERSION_MAJOR", // compile task
|
||||
minor: "NG_VERSION_MINOR",
|
||||
dot: "NG_VERSION_DOT",
|
||||
codeName: '"NG_VERSION_CODENAME"'
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ angularService('$browser', function($log){
|
|||
return browserSingleton;
|
||||
}, {$inject:['$log']});
|
||||
|
||||
|
||||
extend(angular, {
|
||||
// disabled for now until we agree on public name
|
||||
//'annotate': annotate,
|
||||
|
|
@ -41,7 +42,8 @@ extend(angular, {
|
|||
'isFunction': isFunction,
|
||||
'isObject': isObject,
|
||||
'isNumber': isNumber,
|
||||
'isArray': isArray
|
||||
'isArray': isArray,
|
||||
'version': version
|
||||
});
|
||||
|
||||
//try to bind to jquery now so that one can write angular.element().read()
|
||||
|
|
|
|||
|
|
@ -625,4 +625,15 @@ describe('angular', function(){
|
|||
});
|
||||
});
|
||||
|
||||
|
||||
describe('version', function() {
|
||||
it('version should have full/major/minor/dot/codeName properties', function() {
|
||||
expect(version).toBeDefined();
|
||||
expect(version.full).toBe('"NG_VERSION_FULL"');
|
||||
expect(version.major).toBe("NG_VERSION_MAJOR");
|
||||
expect(version.minor).toBe("NG_VERSION_MINOR");
|
||||
expect(version.dot).toBe("NG_VERSION_DOT");
|
||||
expect(version.codeName).toBe('"NG_VERSION_CODENAME"');
|
||||
});
|
||||
})
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue