From: Igor Lima Date: Tue, 19 Feb 2013 23:40:55 +0000 (-0300) Subject: fix minlang task X-Git-Tag: 2.1.0~55^2~3^2^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=71ae9647e2fd7b62337c20c99529aad003ce3050;p=thirdparty%2Fmoment.git fix minlang task --- diff --git a/Gruntfile.js b/Gruntfile.js index 8f8e4c125..ddd14a41c 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -8,12 +8,21 @@ module.exports = function (grunt) { 'min/moment.min.js' : ['moment.js'] }; + var minLangs = { + langs: { + src: ['min/langs.js'], + dest: 'min/langs.min.js' + } + }; + // all the lang files need to be added manually fs.readdirSync('./lang').forEach(function (path) { if (path.indexOf('.js') > -1) { var dest = 'min/lang/' + path, src = ['lang/' + path]; + minifiedFiles[dest] = src; + minLangs[path] = {src:src, dest:dest}; } }); @@ -31,12 +40,15 @@ module.exports = function (grunt) { dest: 'min/langs.js' } }, + minlang : minLangs, uglify : { my_target: { files: minifiedFiles }, options: { - mangle: true, + mangle: { + toplevel: true + }, squeeze: { dead_code: false }, diff --git a/tasks/minify-lang.js b/tasks/minify-lang.js index 76b65a016..d7b3803d6 100644 --- a/tasks/minify-lang.js +++ b/tasks/minify-lang.js @@ -6,6 +6,8 @@ var fs = require('fs'), module.exports = function (grunt) { + var helpers = require('grunt-lib-legacyhelpers').init(grunt); + var START = [ "(function(){", " function onload (moment) {", @@ -28,7 +30,7 @@ module.exports = function (grunt) { // UglifyJS does not support keeping the first line comments unless using the CLI. // This multi-task ensures that the first comments are kept. grunt.registerMultiTask('minlang', 'Minify lang files with UglifyJS.', function () { - var files = grunt.file.expandFiles(this.file.src), + var files = grunt.file.expand(this.data.src), min, code, comments, @@ -36,24 +38,24 @@ module.exports = function (grunt) { // Concat specified files. This should really be a single, pre-built (and // linted) file, but it supports any number of files. - code = grunt.helper('concat', files, {separator: this.data.separator}); + code = helpers.concat(files, {separator: this.data.separator}); // Add the first comments tok = uglifyjs.parser.tokenizer(code); min = showCopyright(tok().comments_before); // Add the minified source. - min += grunt.helper('uglify', wrapFile(code), grunt.config('uglify')); - grunt.file.write(this.file.dest, min); + min += uglifyjs(wrapFile(code), grunt.config('uglify')); + grunt.file.write(this.data.dest, min); // Fail task if errors were logged. if (this.errorCount) { return false; } // Otherwise, print a success message.... - grunt.log.writeln('File "' + this.file.dest + '" created.'); + grunt.log.writeln('File "' + this.data.dest + '" created.'); // ...and report some size information. - grunt.helper('min_max_info', min, code); + helpers.min_max_info(min, code); }); // Helper for the 'mincomment' multitask