From: Tim Wood Date: Tue, 5 Apr 2016 15:44:27 +0000 (-0500) Subject: Remove old unused grunt tasks X-Git-Tag: 2.13.0~27^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8a4857e85d9eb0b394f10948a26c2a719b7c207d;p=thirdparty%2Fmoment.git Remove old unused grunt tasks This removes the following grunt tasks. ``` grunt size grunt history grunt embedLocales grunt zones ``` These are all out of date and no longer used. --- diff --git a/tasks/embed_locales.js b/tasks/embed_locales.js deleted file mode 100644 index 5027af10c..000000000 --- a/tasks/embed_locales.js +++ /dev/null @@ -1,47 +0,0 @@ - -module.exports = function (grunt) { - grunt.registerTask('embedLocales', function () { - var config = grunt.config('embedLocales'); - - var files = grunt.file.expand(config.targetLocales); - var embeddedContents = determineEmbeddedContent(files); - - var momentContents = grunt.file.read(config.moment); - var modifiedContents = momentContents.replace('/* EMBED_LOCALES */', function () { - // If we don't do this, $ symbols in locale files may get interpreted in - // the regex replacement - return embeddedContents; - }); - - grunt.file.write(config.dest, modifiedContents); - }); - - var languageReset = 'moment.locale(\'en\');'; - - function determineEmbeddedContent(files) { - var embeddedContent = ''; - files.forEach(function (file) { - embeddedContent += transformFile(file); - }); - embeddedContent += '\n ' + languageReset + '\n'; - return embeddedContent; - } - - var reTransform = /function \(factory\) \{[^]*\}(?=\(function \(moment\) \{)/gm; - var replaceWith = - 'function (factory) {\n' + - ' factory(moment);\n' + - '}'; - - function transformFile(file) { - var fileContents = grunt.file.read(file); - - if (!fileContents.match(reTransform)) { - grunt.warn('Warning: all locale files must use the common UMD wrapper pattern. Failed locale file: ' + file); - return ''; - } - - return fileContents.replace(reTransform, replaceWith); - } -}; - diff --git a/tasks/history.js b/tasks/history.js deleted file mode 100644 index 85e83338f..000000000 --- a/tasks/history.js +++ /dev/null @@ -1,123 +0,0 @@ -var https = require('https'), - zlib = require('zlib'), - path = require('path'), - fs = require('fs'); - -var count = 0; -var resolved = 0; - -var outputs = []; - -var done; - -function check() { - if (resolved === count) { - normalize(); - display(); - } -} - -function makeBar(length) { - var i = ''; - while (i.length < length) { - i += '='; - } - return i; -} - -function normalize() { - var i, - max = 0, - max2 = 0; - for (i = 0; i < count; i++) { - max = Math.max(max, outputs[i].gzip); - max2 = Math.max(max2, outputs[i].original); - } - for (i = 0; i < count; i++) { - outputs[i].bargraph = makeBar((outputs[i].gzip / max) * 80); - outputs[i].bargraph2 = makeBar((outputs[i].original / max2) * 80); - } -} - -function display() { - var i; - for (i = 0; i < count; i++) { - console.log(outputs[i].version + ' ' + outputs[i].gzip + ' ' + outputs[i].original); - console.log('gzip ' + outputs[i].bargraph); - console.log('orig ' + outputs[i].bargraph2); - } - done(); -} - -function getSizeAtVersion(version, path) { - var data = '', - op = {}, - - req = https.request({ - host: 'raw.github.com', - port: 443, - path: '/timrwood/moment/' + version + path - }, function (res) { - res.setEncoding('utf8'); - res.on('data', function (chunk) { - data += chunk; - }); - res.on('end', function (e) { - zlib.gzip(data, function (error, result) { - op.version = version; - op.gzip = result.length; - op.original = data.length; - resolved++; - check(); - }); - }); - }); - - req.on('error', function (e) { - console.log('problem with request: ' + e.message); - }); - req.end(); - count++; - outputs.push(op); -} - -function getRemote() { - var oldVersions = '1.0.1 1.1.0 1.1.1 1.1.2 1.2.0 1.3.0 1.4.0'.split(' '), - newVersions = '1.5.0 1.5.1 1.6.0 1.6.1 1.7.0 1.7.1'.split(' '), - i; - - for (i = 0; i < oldVersions.length; i++) { - getSizeAtVersion(oldVersions[i], '/moment.min.js'); - } - for (i = 0; i < newVersions.length; i++) { - getSizeAtVersion(newVersions[i], '/min/moment.min.js'); - } -} - -function getLocal() { - count++; - var op = {}; - outputs.push(op); - fs.readFile(path.normalize(__dirname + '/../min/moment.min.js'), 'utf8', function (err, data) { - if (err) { - throw err; - } - zlib.gzip(data, function (error, result) { - op.version = '.next'; - op.gzip = result.length; - op.original = data.length; - resolved++; - check(); - }); - }); -} - - - -module.exports = function (grunt) { - grunt.registerTask('history', 'Check the codebase filesize over different releases.', function () { - done = this.async(); - getRemote(); - getLocal(); - }); -}; diff --git a/tasks/size.js b/tasks/size.js deleted file mode 100644 index 2ab380e9f..000000000 --- a/tasks/size.js +++ /dev/null @@ -1,59 +0,0 @@ -var https = require('https'), - zlib = require('zlib'), - path = require('path'), - fs = require('fs'); - -var stable = '1.7.1', - done; - -function getVersion(path, cb) { - var data = '', - req = https.request({ - host: 'raw.github.com', - port: 443, - path: '/timrwood/moment/' + path - }, function (res) { - res.setEncoding('utf8'); - res.on('data', function (chunk) { - data += chunk; - }); - res.on('end', function (e) { - zlib.gzip(data, function (error, result) { - cb(data.length, result.length); - }); - }); - }); - req.on('error', function (e) { - console.log('problem with request: ' + e.message); - }); - req.end(); -} - -function printDiffs(stableLen, stableGzip, currentLen, currentGzip) { - var diff = currentLen - stableLen, - gzipDiff = currentGzip - stableGzip; - - console.log('Filesize difference from current branch to ' + stable); - console.log(stable + ' ' + stableLen + ' / ' + stableGzip); - console.log('curr ' + currentLen + ' / ' + currentGzip); - console.log('diff ' + (diff > 0 ? '+' : '') + diff); - console.log('gzip ' + (gzipDiff > 0 ? '+' : '') + gzipDiff); -} - - -module.exports = function (grunt) { - grunt.registerTask('size', 'Check the codebase filesize against the latest stable version.', function () { - done = this.async(); - fs.readFile(path.normalize(__dirname + '/../min/moment.min.js'), 'utf8', function (err, data) { - if (err) { - throw err; - } - zlib.gzip(data, function (error, result) { - getVersion(stable + '/min/moment.min.js', function (stableLength, stableGzipLength) { - printDiffs(stableLength, stableGzipLength, data.length, result.length); - done(); - }); - }); - }); - }); -}; diff --git a/tasks/zones.js b/tasks/zones.js deleted file mode 100644 index 7aa88b1f6..000000000 --- a/tasks/zones.js +++ /dev/null @@ -1,70 +0,0 @@ -var fs = require('fs'); - - -module.exports = function (grunt) { - var ZONE_TAB = '/usr/share/zoneinfo/zone.tab'; - - grunt.registerTask('zones', 'Run the unit tests in different timezones.', function () { - var done = this.async(); - - getAllTimezones(function (err, zones) { - if (err != null) { - throw err; - } - (function iterator(i) { - if (i >= zones.length) { - return done(); - } - runTestsInZone(zones[i], function (err) { - if (err != null) { - throw err; - } - iterator(i + 1); - }); - }(0)); - }); - }); - - function getAllTimezones (callback) { - fs.readFile(ZONE_TAB, 'ascii', function (err, content) { - if (err != null) { - callback(err); - } - callback(null, content.split(/\r\n|\r|\n/) - // remove empty and commented lines - .filter(function (line) { - return line && !/^#/.test(line); - }) - // country code TAB coordinates TAB timezone - .map(function (line) { - return line.split('\t')[2]; - })); - }); - } - - function runTestsInZone (zone, next) { - grunt.log.ok('Running tests in zone ' + zone); - grunt.util.spawn({ - cmd: 'grunt', - opts: { - env: { - 'PATH': process.env.PATH, - 'TZ': zone - } - }, - args: ['--no-color', 'nodeunit'] - }, function (err, result, code) { - if (code !== 0) { - grunt.log.error(result.stdout.split(/\r\n|\r|\n/) - .filter(function (line) { - return /^(>>|Warning:|$)/.test(line); - }) - .map(function (line) { - return (line.substr(0, 3) === '>> ' ? line.substr(3) : line); - }) - .join('\n')); - } - next(); - }); - } -};