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

Commit 8218c4b

Browse files
committed
chore(Rakefile): get ready for modules
1 parent 2430f52 commit 8218c4b

12 files changed

+172
-121
lines changed

Rakefile

+50-66
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ require 'yaml'
22
include FileUtils
33

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

77
BUILD_DIR = 'build'
88

@@ -34,38 +34,24 @@ end
3434

3535
desc 'Compile Scenario'
3636
task :compile_scenario => :init do
37-
38-
deps = [
37+
38+
concatFile('angular-scenario.js', [
3939
'lib/jquery/jquery.js',
4040
'src/ngScenario/angular.prefix',
4141
files['angularSrc'],
4242
files['angularScenario'],
4343
'src/ngScenario/angular.suffix',
44-
]
45-
46-
concat = 'cat ' + deps.flatten.join(' ')
47-
48-
File.open(path_to('angular-scenario.js'), 'w') do |f|
49-
f.write(%x{#{concat}}.gsub('"NG_VERSION_FULL"', NG_VERSION.full))
50-
f.write(gen_css('css/angular.css') + "\n")
51-
f.write(gen_css('css/angular-scenario.css'))
52-
end
44+
], gen_css('css/angular.css') + "\n" + gen_css('css/angular-scenario.css'))
5345
end
5446

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

58-
deps = [
50+
concatFile('jstd-scenario-adapter.js', [
5951
'src/ngScenario/jstd-scenario-adapter/angular.prefix',
6052
'src/ngScenario/jstd-scenario-adapter/Adapter.js',
6153
'src/ngScenario/jstd-scenario-adapter/angular.suffix',
62-
]
63-
64-
concat = 'cat ' + deps.flatten.join(' ')
65-
66-
File.open(path_to('jstd-scenario-adapter.js'), 'w') do |f|
67-
f.write(%x{#{concat}}.gsub('"NG_VERSION_FULL"', NG_VERSION.full))
68-
end
54+
])
6955

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

83-
deps = [
84-
'src/angular.prefix',
85-
files['angularSrc'],
86-
'src/angular.suffix',
87-
]
88-
89-
File.open(path_to('angular.js'), 'w') do |f|
90-
concat = 'cat ' + deps.flatten.join(' ')
91-
92-
content = %x{#{concat}}.
93-
gsub('"NG_VERSION_FULL"', NG_VERSION.full).
94-
gsub('"NG_VERSION_MAJOR"', NG_VERSION.major).
95-
gsub('"NG_VERSION_MINOR"', NG_VERSION.minor).
96-
gsub('"NG_VERSION_DOT"', NG_VERSION.dot).
97-
gsub('"NG_VERSION_CODENAME"', NG_VERSION.codename).
98-
gsub(/^\s*['"]use strict['"];?\s*$/, ''). # remove all file-specific strict mode flags
99-
gsub(/'USE STRICT'/, "'use strict'") # rename the placeholder in angular.prefix
100-
101-
f.write(content)
102-
f.write(gen_css('css/angular.css', true))
103-
end
104-
105-
%x(java -jar lib/closure-compiler/compiler.jar \
106-
--compilation_level SIMPLE_OPTIMIZATIONS \
107-
--language_in ECMASCRIPT5_STRICT \
108-
--js #{path_to('angular.js')} \
109-
--js_output_file #{path_to('angular.min.js')})
69+
concatFile('angular.js', [
70+
'src/angular.prefix',
71+
files['angularSrc'],
72+
'src/angular.suffix',
73+
], gen_css('css/angular.css', true))
11074

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

113-
File.open(path_to('angular-loader.js'), 'w') do |f|
114-
concat = 'cat ' + [
77+
concatFile('angular-loader.js', [
11578
'src/loader.prefix',
11679
'src/loader.js',
117-
'src/loader.suffix'].flatten.join(' ')
118-
119-
content = %x{#{concat}}.
120-
gsub('"NG_VERSION_FULL"', NG_VERSION.full).
121-
gsub(/^\s*['"]use strict['"];?\s*$/, '') # remove all file-specific strict mode flags
122-
123-
f.write(content)
124-
end
125-
126-
%x(java -jar lib/closure-compiler/compiler.jar \
127-
--compilation_level SIMPLE_OPTIMIZATIONS \
128-
--language_in ECMASCRIPT5_STRICT \
129-
--js #{path_to('angular-loader.js')} \
130-
--js_output_file #{path_to('angular-loader.min.js')})
80+
'src/loader.suffix'])
81+
82+
FileUtils.cp 'src/ngMock/angular-mocks.js', path_to('angular-mocks.js')
13183

84+
85+
closureCompile('angular.js')
86+
closureCompile('angular-loader.js')
13287

13388
end
13489

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

156-
['src/ngMock/angular-mocks.js',
157-
path_to('angular.js'),
158-
path_to('angular-loader.js'),
111+
[ path_to('angular.js'),
159112
path_to('angular.min.js'),
113+
path_to('angular-loader.js'),
160114
path_to('angular-loader.min.js'),
115+
path_to('angular-mocks.js'),
161116
path_to('angular-scenario.js'),
162117
path_to('jstd-scenario-adapter.js'),
163118
path_to('jstd-scenario-adapter-config.js'),
@@ -336,3 +291,32 @@ end
336291
def path_to(filename)
337292
return File.join(BUILD_DIR, *filename)
338293
end
294+
295+
def closureCompile(filename)
296+
puts "Compiling #{filename} ..."
297+
%x(java -jar lib/closure-compiler/compiler.jar \
298+
--compilation_level SIMPLE_OPTIMIZATIONS \
299+
--language_in ECMASCRIPT5_STRICT \
300+
--js #{path_to(filename)} \
301+
--js_output_file #{path_to(filename.gsub(/\.js$/, '.min.js'))})
302+
end
303+
304+
def concatFile(filename, deps, footer='')
305+
puts "Building #{filename} ..."
306+
File.open(path_to(filename), 'w') do |f|
307+
concat = 'cat ' + deps.flatten.join(' ')
308+
309+
content = %x{#{concat}}.
310+
gsub('"NG_VERSION_FULL"', NG_VERSION.full).
311+
gsub('"NG_VERSION_MAJOR"', NG_VERSION.major).
312+
gsub('"NG_VERSION_MINOR"', NG_VERSION.minor).
313+
gsub('"NG_VERSION_DOT"', NG_VERSION.dot).
314+
gsub('"NG_VERSION_CODENAME"', NG_VERSION.codename).
315+
gsub(/^\s*['"]use strict['"];?\s*$/, ''). # remove all file-specific strict mode flags
316+
gsub(/'USE STRICT'/, "'use strict'") # rename the placeholder in angular.prefix
317+
318+
f.write(content)
319+
f.write(footer)
320+
end
321+
end
322+

angularFiles.js

+50-38
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ angularFiles = {
6666
'src/ng/directive/style.js'
6767
],
6868

69+
'angularSrcModules': [
70+
'src/ngMock/angular-mocks.js'
71+
],
72+
6973
'angularScenario': [
7074
'src/ngScenario/Scenario.js',
7175
'src/ngScenario/Application.js',
@@ -83,20 +87,9 @@ angularFiles = {
8387
'src/ngScenario/output/Object.js'
8488
],
8589

86-
'jstd': [
87-
'lib/jasmine/jasmine.js',
88-
'lib/jasmine-jstd-adapter/JasmineAdapter.js',
89-
'lib/jquery/jquery.js',
90-
'test/jquery_remove.js',
91-
'@angularSrc',
92-
'example/personalLog/*.js',
90+
'angularTest': [
9391
'test/testabilityPatch.js',
9492
'test/matchers.js',
95-
'src/ngScenario/Scenario.js',
96-
'src/ngScenario/output/*.js',
97-
'src/ngScenario/jstd-scenario-adapter/*.js',
98-
'src/ngScenario/*.js',
99-
'src/ngMock/angular-mocks.js',
10093
'test/ngScenario/*.js',
10194
'test/ngScenario/output/*.js',
10295
'test/ngScenario/jstd-scenario-adapter/*.js',
@@ -105,7 +98,21 @@ angularFiles = {
10598
'test/ng/*.js',
10699
'test/ng/directive/*.js',
107100
'test/ng/filter/*.js',
108-
'test/ngMock/*.js',
101+
'test/ngMock/*.js'
102+
],
103+
104+
'jstd': [
105+
'lib/jasmine/jasmine.js',
106+
'lib/jasmine-jstd-adapter/JasmineAdapter.js',
107+
'lib/jquery/jquery.js',
108+
'test/jquery_remove.js',
109+
'@angularSrc',
110+
'src/publishExternalApis.js',
111+
'@angularSrcModules',
112+
'@angularScenario',
113+
'src/ngScenario/jstd-scenario-adapter/Adapter.js',
114+
'@angularTest',
115+
'example/personalLog/*.js',
109116
'example/personalLog/test/*.js'
110117
],
111118

@@ -122,19 +129,20 @@ angularFiles = {
122129
'build/docs/docs-scenario.js'
123130
],
124131

125-
'jstdMocks': [
132+
"jstdModules": [
126133
'lib/jasmine/jasmine.js',
127134
'lib/jasmine-jstd-adapter/JasmineAdapter.js',
128135
'build/angular.js',
129136
'src/ngMock/angular-mocks.js',
130137
'test/matchers.js',
131-
'test/ngMock/angular-mocksSpec.js'
138+
'test/ngMock/*.js',
132139
],
133140

134141
'jstdPerf': [
135142
'lib/jasmine/jasmine.js',
136143
'lib/jasmine-jstd-adapter/JasmineAdapter.js',
137-
'angularSrc',
144+
'@angularSrc',
145+
'@angularSrcModules',
138146
'src/ngMock/angular-mocks.js',
139147
'perf/data/*.js',
140148
'perf/testUtils.js',
@@ -152,23 +160,12 @@ angularFiles = {
152160
'lib/jquery/jquery.js',
153161
'test/jquery_alias.js',
154162
'@angularSrc',
163+
'src/publishExternalApis.js',
164+
'@angularSrcModules',
165+
'@angularScenario',
166+
'src/ngScenario/jstd-scenario-adapter/Adapter.js',
167+
'@angularTest',
155168
'example/personalLog/*.js',
156-
'test/testabilityPatch.js',
157-
'test/matchers.js',
158-
'src/ngScenario/Scenario.js',
159-
'src/ngScenario/output/*.js',
160-
'src/ngScenario/jstd-scenario-adapter/*.js',
161-
'src/ngScenario/*.js',
162-
'src/ngMock/angular-mocks.js',
163-
'test/ngScenario/*.js',
164-
'test/ngScenario/output/*.js',
165-
'test/ngScenario/jstd-scenario-adapter/*.js',
166-
'test/*.js',
167-
'test/auto/*.js',
168-
'test/ng/*.js',
169-
'test/ng/directive/*.js',
170-
'test/ng/filter/*.js',
171-
'test/ngMock/*.js',
172169
'example/personalLog/test/*.js'
173170
],
174171

@@ -181,15 +178,30 @@ angularFiles = {
181178

182179
// Execute only in slim-jim
183180
if (typeof JASMINE_ADAPTER !== 'undefined') {
184-
// SlimJim config
181+
// Testacular config
182+
var mergedFiles = [];
183+
angularFiles.jstd.forEach(function(file) {
184+
// replace @ref
185+
var match = file.match(/^\@(.*)/);
186+
if (match) {
187+
var deps = angularFiles[match[1]];
188+
if (!deps) {
189+
console.log('No dependency:' + file)
190+
}
191+
mergedFiles = mergedFiles.concat(deps);
192+
} else {
193+
mergedFiles.push(file);
194+
}
195+
});
196+
185197
files = [JASMINE, JASMINE_ADAPTER];
186-
angularFiles.jstd.forEach(function(pattern) {
187-
// replace angular source
188-
if (pattern === '@angularSrc') files = files.concat(angularFiles.angularSrc);
189-
// ignore jstd and jasmine files
190-
else if (!/jstd|jasmine/.test(pattern)) files.push(pattern);
198+
199+
mergedFiles.forEach(function(file){
200+
if (/jstd|jasmine/.test(file)) return;
201+
files.push(file);
191202
});
192203

204+
193205
exclude = angularFiles.jstdExclude;
194206

195207
autoWatch = true;

gen_jstd_configs.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fs.readFile('angularFiles.js', function(err, data) {
1616
fs.writeFile('./jsTestDriver.conf', prefix + combine(angularFiles.jstd,
1717
angularFiles.jstdExclude));
1818

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

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

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

src/AngularPublic.js

-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ function publishExternalAPI(angular){
122122
$location: $LocationProvider,
123123
$log: $LogProvider,
124124
$parse: $ParseProvider,
125-
$resource: $ResourceProvider,
126125
$route: $RouteProvider,
127126
$routeParams: $RouteParamsProvider,
128127
$rootScope: $RootScopeProvider,

src/ng/http.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ function $HttpProvider() {
152152
* For unit testing applications that use `$http` service, see
153153
* {@link angular.module.ngMock.$httpBackend $httpBackend mock}.
154154
*
155-
* For a higher level of abstraction, please check out the {@link angular.module.ng.$resource
155+
* For a higher level of abstraction, please check out the {@link angular.module.ngResource.$resource
156156
* $resource} service.
157157
*
158158
* The $http API is based on the {@link angular.module.ng.$q deferred/promise APIs} exposed by

src/ng/httpBackend.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ var XHR = window.XMLHttpRequest || function() {
1818
* XMLHttpRequest object or JSONP and deals with browser incompatibilities.
1919
*
2020
* You should never need to use this service directly, instead use the higher-level abstractions:
21-
* {@link angular.module.ng.$http $http} or {@link angular.module.ng.$resource $resource}.
21+
* {@link angular.module.ng.$http $http} or {@link angular.module.ngResource.$resource $resource}.
2222
*
2323
* During testing this implementation is swapped with {@link angular.module.ngMock.$httpBackend mock
2424
* $httpBackend} which can be trained with responses.

0 commit comments

Comments
 (0)