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

Commit c8fcf3b

Browse files
ksheedloIgorMinar
authored andcommitted
feat(minErr): Error stripping build step
1 parent 0c6fb66 commit c8fcf3b

File tree

4 files changed

+52
-3
lines changed

4 files changed

+52
-3
lines changed

Gruntfile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,6 @@ module.exports = function(grunt) {
191191
grunt.registerTask('minify', ['shell:bower','clean', 'build', 'minall']);
192192
grunt.registerTask('test:e2e', ['connect:testserver', 'test:end2end']);
193193
grunt.registerTask('webserver', ['connect:devserver']);
194-
grunt.registerTask('package', ['shell:bower','clean', 'buildall', 'minall', 'docs', 'copy', 'write', 'compress']);
194+
grunt.registerTask('package', ['shell:bower','clean', 'buildall', 'minall', 'collect-errors', 'docs', 'copy', 'write', 'compress']);
195195
grunt.registerTask('default', ['package']);
196196
};

bower.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"google-code-prettify": "1.0.0",
77
"components-font-awesome": "3.1.0",
88
"bootstrap": "https://raw.github.com/twitter/bootstrap/v2.0.2/docs/assets/bootstrap.zip",
9-
"closure-compiler": "https://closure-compiler.googlecode.com/files/compiler-20130603.zip"
9+
"closure-compiler": "https://closure-compiler.googlecode.com/files/compiler-20130603.zip",
10+
"ng-closure-runner": "https://raw.github.com/angular/ng-closure-runner/v0.1/assets/ng-closure-runner.zip"
1011
}
1112
}

lib/grunt/plugins.js

+4
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,8 @@ module.exports = function(grunt) {
5959
grunt.registerMultiTask('autotest', 'Run and watch the unit tests with Karma', function(){
6060
util.startKarma.call(util, this.data, false, this.async());
6161
});
62+
63+
grunt.registerTask('collect-errors', 'Combine stripped error files', function () {
64+
util.collectErrors();
65+
});
6266
};

lib/grunt/utils.js

+45-1
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,18 @@ module.exports = {
134134
var minFile = file.replace(/\.js$/, '.min.js');
135135
var mapFile = minFile + '.map';
136136
var mapFileName = mapFile.match(/[^\/]+$/)[0];
137+
var errorFileName = file.replace(/\.js$/, '-errors.json');
137138
shell.exec(
138139
'java ' +
139140
this.java32flags() + ' ' +
140-
'-jar components/closure-compiler/compiler.jar ' +
141+
'-cp ./components/closure-compiler/compiler.jar' +
142+
':./components/ng-closure-runner/ngcompiler.jar ' +
143+
'org.angularjs.closurerunner.NgClosureRunner ' +
141144
'--compilation_level SIMPLE_OPTIMIZATIONS ' +
142145
'--language_in ECMASCRIPT5_STRICT ' +
146+
'--minerr_pass ' +
147+
'--minerr_errors ' + errorFileName + ' ' +
148+
'--minerr_url \'http://docs.angularjs.org/minerr/\' ' +
143149
'--source_map_format=V3 ' +
144150
'--create_source_map ' + mapFile + ' ' +
145151
'--js ' + file + ' ' +
@@ -167,6 +173,44 @@ module.exports = {
167173
},
168174

169175

176+
//collects and combines error messages stripped out in minify step
177+
collectErrors: function () {
178+
var combined = {
179+
id: 'ng',
180+
generated: new Date().toString(),
181+
errors: {}
182+
};
183+
grunt.file.expand('build/*-errors.json').forEach(function (file) {
184+
var errors = grunt.file.readJSON(file),
185+
namespace;
186+
Object.keys(errors).forEach(function (prop) {
187+
if (typeof errors[prop] === 'object') {
188+
namespace = errors[prop];
189+
if (combined.errors[prop]) {
190+
Object.keys(namespace).forEach(function (code) {
191+
if (combined.errors[prop][code] && combined.errors[prop][code] !== namespace[code]) {
192+
grunt.warn('[collect-errors] Duplicate minErr codes don\'t match!');
193+
} else {
194+
combined.errors[prop][code] = namespace[code];
195+
}
196+
});
197+
} else {
198+
combined.errors[prop] = namespace;
199+
}
200+
} else {
201+
if (combined.errors[prop] && combined.errors[prop] !== errors[prop]) {
202+
grunt.warn('[collect-errors] Duplicate minErr codes don\'t match!');
203+
} else {
204+
combined.errors[prop] = errors[prop];
205+
}
206+
}
207+
});
208+
});
209+
grunt.file.write('build/errors.json', JSON.stringify(combined));
210+
grunt.file.expand('build/*-errors.json').forEach(grunt.file.delete);
211+
},
212+
213+
170214
//csp connect middleware
171215
csp: function(){
172216
return function(req, res, next){

0 commit comments

Comments
 (0)