From c8fcf3b369dbe866815e18e0fa4d71f3e679bc5f Mon Sep 17 00:00:00 2001 From: Ken Sheedlo Date: Fri, 28 Jun 2013 16:47:10 -0700 Subject: feat(minErr): Error stripping build step --- lib/grunt/plugins.js | 4 ++++ lib/grunt/utils.js | 46 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/grunt/plugins.js b/lib/grunt/plugins.js index ca2d6ec6..aaf1e73e 100644 --- a/lib/grunt/plugins.js +++ b/lib/grunt/plugins.js @@ -59,4 +59,8 @@ module.exports = function(grunt) { grunt.registerMultiTask('autotest', 'Run and watch the unit tests with Karma', function(){ util.startKarma.call(util, this.data, false, this.async()); }); + + grunt.registerTask('collect-errors', 'Combine stripped error files', function () { + util.collectErrors(); + }); }; diff --git a/lib/grunt/utils.js b/lib/grunt/utils.js index 1696c226..09281b8a 100644 --- a/lib/grunt/utils.js +++ b/lib/grunt/utils.js @@ -134,12 +134,18 @@ module.exports = { var minFile = file.replace(/\.js$/, '.min.js'); var mapFile = minFile + '.map'; var mapFileName = mapFile.match(/[^\/]+$/)[0]; + var errorFileName = file.replace(/\.js$/, '-errors.json'); shell.exec( 'java ' + this.java32flags() + ' ' + - '-jar components/closure-compiler/compiler.jar ' + + '-cp ./components/closure-compiler/compiler.jar' + + ':./components/ng-closure-runner/ngcompiler.jar ' + + 'org.angularjs.closurerunner.NgClosureRunner ' + '--compilation_level SIMPLE_OPTIMIZATIONS ' + '--language_in ECMASCRIPT5_STRICT ' + + '--minerr_pass ' + + '--minerr_errors ' + errorFileName + ' ' + + '--minerr_url \'http://docs.angularjs.org/minerr/\' ' + '--source_map_format=V3 ' + '--create_source_map ' + mapFile + ' ' + '--js ' + file + ' ' + @@ -167,6 +173,44 @@ module.exports = { }, + //collects and combines error messages stripped out in minify step + collectErrors: function () { + var combined = { + id: 'ng', + generated: new Date().toString(), + errors: {} + }; + grunt.file.expand('build/*-errors.json').forEach(function (file) { + var errors = grunt.file.readJSON(file), + namespace; + Object.keys(errors).forEach(function (prop) { + if (typeof errors[prop] === 'object') { + namespace = errors[prop]; + if (combined.errors[prop]) { + Object.keys(namespace).forEach(function (code) { + if (combined.errors[prop][code] && combined.errors[prop][code] !== namespace[code]) { + grunt.warn('[collect-errors] Duplicate minErr codes don\'t match!'); + } else { + combined.errors[prop][code] = namespace[code]; + } + }); + } else { + combined.errors[prop] = namespace; + } + } else { + if (combined.errors[prop] && combined.errors[prop] !== errors[prop]) { + grunt.warn('[collect-errors] Duplicate minErr codes don\'t match!'); + } else { + combined.errors[prop] = errors[prop]; + } + } + }); + }); + grunt.file.write('build/errors.json', JSON.stringify(combined)); + grunt.file.expand('build/*-errors.json').forEach(grunt.file.delete); + }, + + //csp connect middleware csp: function(){ return function(req, res, next){ -- cgit v1.2.3