Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
chore(Rakefile): get ready for modules
Browse files Browse the repository at this point in the history
  • Loading branch information
mhevery committed Mar 28, 2012
1 parent 2430f52 commit 8218c4b
Show file tree
Hide file tree
Showing 12 changed files with 172 additions and 121 deletions.
116 changes: 50 additions & 66 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ require 'yaml'
include FileUtils

content = File.open('angularFiles.js', 'r') {|f| f.read }
files = eval(content.gsub(/\};(\s|\S)*/, '}').gsub(/angularFiles = /, '').gsub(/:/, '=>'));
files = eval(content.gsub(/\};(\s|\S)*/, '}').gsub(/angularFiles = /, '').gsub(/:/, '=>').gsub(/\/\//, '#'));

BUILD_DIR = 'build'

Expand Down Expand Up @@ -34,38 +34,24 @@ end

desc 'Compile Scenario'
task :compile_scenario => :init do

deps = [
concatFile('angular-scenario.js', [
'lib/jquery/jquery.js',
'src/ngScenario/angular.prefix',
files['angularSrc'],
files['angularScenario'],
'src/ngScenario/angular.suffix',
]

concat = 'cat ' + deps.flatten.join(' ')

File.open(path_to('angular-scenario.js'), 'w') do |f|
f.write(%x{#{concat}}.gsub('"NG_VERSION_FULL"', NG_VERSION.full))
f.write(gen_css('css/angular.css') + "\n")
f.write(gen_css('css/angular-scenario.css'))
end
], gen_css('css/angular.css') + "\n" + gen_css('css/angular-scenario.css'))
end

desc 'Compile JSTD Scenario Adapter'
task :compile_jstd_scenario_adapter => :init do

deps = [
concatFile('jstd-scenario-adapter.js', [
'src/ngScenario/jstd-scenario-adapter/angular.prefix',
'src/ngScenario/jstd-scenario-adapter/Adapter.js',
'src/ngScenario/jstd-scenario-adapter/angular.suffix',
]

concat = 'cat ' + deps.flatten.join(' ')

File.open(path_to('jstd-scenario-adapter.js'), 'w') do |f|
f.write(%x{#{concat}}.gsub('"NG_VERSION_FULL"', NG_VERSION.full))
end
])

# TODO(vojta) use jstd configuration when implemented
# (instead of including jstd-adapter-config.js)
Expand All @@ -80,55 +66,24 @@ end
desc 'Compile JavaScript'
task :compile => [:init, :compile_scenario, :compile_jstd_scenario_adapter] do

deps = [
'src/angular.prefix',
files['angularSrc'],
'src/angular.suffix',
]

File.open(path_to('angular.js'), 'w') do |f|
concat = 'cat ' + deps.flatten.join(' ')

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

f.write(content)
f.write(gen_css('css/angular.css', true))
end

%x(java -jar lib/closure-compiler/compiler.jar \
--compilation_level SIMPLE_OPTIMIZATIONS \
--language_in ECMASCRIPT5_STRICT \
--js #{path_to('angular.js')} \
--js_output_file #{path_to('angular.min.js')})
concatFile('angular.js', [
'src/angular.prefix',
files['angularSrc'],
'src/angular.suffix',
], gen_css('css/angular.css', true))

FileUtils.cp_r 'src/ngLocale', path_to('i18n')

File.open(path_to('angular-loader.js'), 'w') do |f|
concat = 'cat ' + [
concatFile('angular-loader.js', [
'src/loader.prefix',
'src/loader.js',
'src/loader.suffix'].flatten.join(' ')

content = %x{#{concat}}.
gsub('"NG_VERSION_FULL"', NG_VERSION.full).
gsub(/^\s*['"]use strict['"];?\s*$/, '') # remove all file-specific strict mode flags

f.write(content)
end

%x(java -jar lib/closure-compiler/compiler.jar \
--compilation_level SIMPLE_OPTIMIZATIONS \
--language_in ECMASCRIPT5_STRICT \
--js #{path_to('angular-loader.js')} \
--js_output_file #{path_to('angular-loader.min.js')})
'src/loader.suffix'])

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


closureCompile('angular.js')
closureCompile('angular-loader.js')

end

Expand All @@ -153,11 +108,11 @@ task :package => [:clean, :compile, :docs] do
FileUtils.rm_r(path_to('pkg'), :force => true)
FileUtils.mkdir_p(pkg_dir)

['src/ngMock/angular-mocks.js',
path_to('angular.js'),
path_to('angular-loader.js'),
[ path_to('angular.js'),
path_to('angular.min.js'),
path_to('angular-loader.js'),
path_to('angular-loader.min.js'),
path_to('angular-mocks.js'),
path_to('angular-scenario.js'),
path_to('jstd-scenario-adapter.js'),
path_to('jstd-scenario-adapter-config.js'),
Expand Down Expand Up @@ -336,3 +291,32 @@ end
def path_to(filename)
return File.join(BUILD_DIR, *filename)
end

def closureCompile(filename)
puts "Compiling #{filename} ..."
%x(java -jar lib/closure-compiler/compiler.jar \
--compilation_level SIMPLE_OPTIMIZATIONS \
--language_in ECMASCRIPT5_STRICT \
--js #{path_to(filename)} \
--js_output_file #{path_to(filename.gsub(/\.js$/, '.min.js'))})
end

def concatFile(filename, deps, footer='')
puts "Building #{filename} ..."
File.open(path_to(filename), 'w') do |f|
concat = 'cat ' + deps.flatten.join(' ')

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

f.write(content)
f.write(footer)
end
end

88 changes: 50 additions & 38 deletions angularFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ angularFiles = {
'src/ng/directive/style.js'
],

'angularSrcModules': [
'src/ngMock/angular-mocks.js'
],

'angularScenario': [
'src/ngScenario/Scenario.js',
'src/ngScenario/Application.js',
Expand All @@ -83,20 +87,9 @@ angularFiles = {
'src/ngScenario/output/Object.js'
],

'jstd': [
'lib/jasmine/jasmine.js',
'lib/jasmine-jstd-adapter/JasmineAdapter.js',
'lib/jquery/jquery.js',
'test/jquery_remove.js',
'@angularSrc',
'example/personalLog/*.js',
'angularTest': [
'test/testabilityPatch.js',
'test/matchers.js',
'src/ngScenario/Scenario.js',
'src/ngScenario/output/*.js',
'src/ngScenario/jstd-scenario-adapter/*.js',
'src/ngScenario/*.js',
'src/ngMock/angular-mocks.js',
'test/ngScenario/*.js',
'test/ngScenario/output/*.js',
'test/ngScenario/jstd-scenario-adapter/*.js',
Expand All @@ -105,7 +98,21 @@ angularFiles = {
'test/ng/*.js',
'test/ng/directive/*.js',
'test/ng/filter/*.js',
'test/ngMock/*.js',
'test/ngMock/*.js'
],

'jstd': [
'lib/jasmine/jasmine.js',
'lib/jasmine-jstd-adapter/JasmineAdapter.js',
'lib/jquery/jquery.js',
'test/jquery_remove.js',
'@angularSrc',
'src/publishExternalApis.js',
'@angularSrcModules',
'@angularScenario',
'src/ngScenario/jstd-scenario-adapter/Adapter.js',
'@angularTest',
'example/personalLog/*.js',
'example/personalLog/test/*.js'
],

Expand All @@ -122,19 +129,20 @@ angularFiles = {
'build/docs/docs-scenario.js'
],

'jstdMocks': [
"jstdModules": [
'lib/jasmine/jasmine.js',
'lib/jasmine-jstd-adapter/JasmineAdapter.js',
'build/angular.js',
'src/ngMock/angular-mocks.js',
'test/matchers.js',
'test/ngMock/angular-mocksSpec.js'
'test/ngMock/*.js',
],

'jstdPerf': [
'lib/jasmine/jasmine.js',
'lib/jasmine-jstd-adapter/JasmineAdapter.js',
'angularSrc',
'@angularSrc',
'@angularSrcModules',
'src/ngMock/angular-mocks.js',
'perf/data/*.js',
'perf/testUtils.js',
Expand All @@ -152,23 +160,12 @@ angularFiles = {
'lib/jquery/jquery.js',
'test/jquery_alias.js',
'@angularSrc',
'src/publishExternalApis.js',
'@angularSrcModules',
'@angularScenario',
'src/ngScenario/jstd-scenario-adapter/Adapter.js',
'@angularTest',
'example/personalLog/*.js',
'test/testabilityPatch.js',
'test/matchers.js',
'src/ngScenario/Scenario.js',
'src/ngScenario/output/*.js',
'src/ngScenario/jstd-scenario-adapter/*.js',
'src/ngScenario/*.js',
'src/ngMock/angular-mocks.js',
'test/ngScenario/*.js',
'test/ngScenario/output/*.js',
'test/ngScenario/jstd-scenario-adapter/*.js',
'test/*.js',
'test/auto/*.js',
'test/ng/*.js',
'test/ng/directive/*.js',
'test/ng/filter/*.js',
'test/ngMock/*.js',
'example/personalLog/test/*.js'
],

Expand All @@ -181,15 +178,30 @@ angularFiles = {

// Execute only in slim-jim
if (typeof JASMINE_ADAPTER !== 'undefined') {
// SlimJim config
// Testacular config
var mergedFiles = [];
angularFiles.jstd.forEach(function(file) {
// replace @ref
var match = file.match(/^\@(.*)/);
if (match) {
var deps = angularFiles[match[1]];
if (!deps) {
console.log('No dependency:' + file)
}
mergedFiles = mergedFiles.concat(deps);
} else {
mergedFiles.push(file);
}
});

files = [JASMINE, JASMINE_ADAPTER];
angularFiles.jstd.forEach(function(pattern) {
// replace angular source
if (pattern === '@angularSrc') files = files.concat(angularFiles.angularSrc);
// ignore jstd and jasmine files
else if (!/jstd|jasmine/.test(pattern)) files.push(pattern);

mergedFiles.forEach(function(file){
if (/jstd|jasmine/.test(file)) return;
files.push(file);
});


exclude = angularFiles.jstdExclude;

autoWatch = true;
Expand Down
6 changes: 4 additions & 2 deletions gen_jstd_configs.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fs.readFile('angularFiles.js', function(err, data) {
fs.writeFile('./jsTestDriver.conf', prefix + combine(angularFiles.jstd,
angularFiles.jstdExclude));

fs.writeFile('./jsTestDriver-mocks.conf', prefix + combine(angularFiles.jstdMocks));
fs.writeFile('./jsTestDriver-modules.conf', prefix + combine(angularFiles.jstdModules));

fs.writeFile('./jsTestDriver-scenario.conf', prefixScenario +
combine(angularFiles.jstdScenario) +
Expand All @@ -40,6 +40,8 @@ function combine(load, exclude) {
if (exclude) fileList += ('\n\nexclude:\n- ' + exclude.join('\n- '));

//Replace placeholders for src list before returning
return fileList.replace(/@angularSrc/g, angularSrc);
return fileList.replace(/@(.*)/g, function(all, alias) {
return angularFiles[alias].join('\n- ');
});
}

1 change: 0 additions & 1 deletion src/AngularPublic.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ function publishExternalAPI(angular){
$location: $LocationProvider,
$log: $LogProvider,
$parse: $ParseProvider,
$resource: $ResourceProvider,
$route: $RouteProvider,
$routeParams: $RouteParamsProvider,
$rootScope: $RootScopeProvider,
Expand Down
2 changes: 1 addition & 1 deletion src/ng/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ function $HttpProvider() {
* For unit testing applications that use `$http` service, see
* {@link angular.module.ngMock.$httpBackend $httpBackend mock}.
*
* For a higher level of abstraction, please check out the {@link angular.module.ng.$resource
* For a higher level of abstraction, please check out the {@link angular.module.ngResource.$resource
* $resource} service.
*
* The $http API is based on the {@link angular.module.ng.$q deferred/promise APIs} exposed by
Expand Down
2 changes: 1 addition & 1 deletion src/ng/httpBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var XHR = window.XMLHttpRequest || function() {
* XMLHttpRequest object or JSONP and deals with browser incompatibilities.
*
* You should never need to use this service directly, instead use the higher-level abstractions:
* {@link angular.module.ng.$http $http} or {@link angular.module.ng.$resource $resource}.
* {@link angular.module.ng.$http $http} or {@link angular.module.ngResource.$resource $resource}.
*
* During testing this implementation is swapped with {@link angular.module.ngMock.$httpBackend mock
* $httpBackend} which can be trained with responses.
Expand Down
Loading

0 comments on commit 8218c4b

Please sign in to comment.