Add frontend assets and plugin bundles
Add the legacy frontend themes, scripts, and plugin assets required by the main SPOTA interfaces.
This commit is contained in:
9
assets/plugins/moment/tasks/component.js
Normal file
9
assets/plugins/moment/tasks/component.js
Normal file
@@ -0,0 +1,9 @@
|
||||
module.exports = function (grunt) {
|
||||
grunt.registerTask('component', function () {
|
||||
var config = JSON.parse(grunt.file.read('component.json'));
|
||||
config.files = grunt.file.expand('lang/*.js');
|
||||
config.files.unshift('moment.js');
|
||||
|
||||
grunt.file.write('component.json', JSON.stringify(config, true, 2));
|
||||
});
|
||||
}
|
||||
49
assets/plugins/moment/tasks/embed_languages.js
Normal file
49
assets/plugins/moment/tasks/embed_languages.js
Normal file
@@ -0,0 +1,49 @@
|
||||
|
||||
module.exports = function (grunt) {
|
||||
|
||||
grunt.registerTask('embed_languages', function () {
|
||||
var config = grunt.config('embed_languages');
|
||||
|
||||
var files = grunt.file.expand(config.targetLangs);
|
||||
var embeddedContents = determineEmbeddedContent(files);
|
||||
|
||||
var momentContents = grunt.file.read(config.moment);
|
||||
var modifiedContents = momentContents.replace('/* EMBED_LANGUAGES */', function () {
|
||||
// If we don't do this, $ symbols in lang files may get interpreted in
|
||||
// the regex replacement
|
||||
return embeddedContents;
|
||||
});
|
||||
|
||||
grunt.file.write(config.dest, modifiedContents);
|
||||
});
|
||||
|
||||
var languageReset = 'moment.lang(\'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 language files must use the common UMD wrapper pattern. Failed language file: ' + file);
|
||||
return '';
|
||||
}
|
||||
|
||||
return fileContents.replace(reTransform, replaceWith);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
123
assets/plugins/moment/tasks/history.js
Normal file
123
assets/plugins/moment/tasks/history.js
Normal file
@@ -0,0 +1,123 @@
|
||||
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 old_versions = '1.0.1 1.1.0 1.1.1 1.1.2 1.2.0 1.3.0 1.4.0'.split(' '),
|
||||
new_versions = '1.5.0 1.5.1 1.6.0 1.6.1 1.7.0 1.7.1'.split(' '),
|
||||
i;
|
||||
|
||||
for (i = 0; i < old_versions.length; i++) {
|
||||
getSizeAtVersion(old_versions[i], '/moment.min.js');
|
||||
}
|
||||
for (i = 0; i < new_versions.length; i++) {
|
||||
getSizeAtVersion(new_versions[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();
|
||||
});
|
||||
};
|
||||
60
assets/plugins/moment/tasks/size.js
Normal file
60
assets/plugins/moment/tasks/size.js
Normal file
@@ -0,0 +1,60 @@
|
||||
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();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
60
assets/plugins/moment/tasks/zones.js
Normal file
60
assets/plugins/moment/tasks/zones.js
Normal file
@@ -0,0 +1,60 @@
|
||||
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();
|
||||
});
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user