This adds moment to perfect date/time sorting with tabulator!

This commit is contained in:
Jonathan Rosenbaum
2017-10-30 03:01:55 +00:00
parent f15d312e5a
commit 4bb9b043ad
568 changed files with 166883 additions and 0 deletions
+78
View File
@@ -0,0 +1,78 @@
module.exports = function (grunt) {
grunt.registerTask('bump_version', function (version) {
if (!version || version.split('.').length !== 3) {
grunt.fail.fatal('malformed version. Use\n\n grunt bump_version:1.2.3');
}
grunt.config('string-replace.moment-js', {
files: {'src/moment.js': 'src/moment.js'},
options: {
replacements: [
{
pattern: /\/\/! version : .*/,
replacement: '//! version : ' + version
}, {
pattern: /moment\.version = '.*'/,
replacement: "moment.version = '" + version + "'"
}
]
}
});
grunt.config('string-replace.package-json', {
files: {'package.json': 'package.json'},
options: {
replacements: [
{
pattern: /"version": .*/,
replacement: '"version": "' + version + '",'
}
]
}
});
grunt.config('string-replace.component-json', {
files: {'component.json': 'component.json'},
options: {
replacements: [
{
pattern: /"version": .*/,
replacement: '"version": "' + version + '",'
}
]
}
});
grunt.config('string-replace.moment-js-nuspec', {
files: {'Moment.js.nuspec': 'Moment.js.nuspec'},
options: {
replacements: [
{
pattern: /<version>.*<\/version>/,
replacement: '<version>' + version + '</version>'
}
]
}
});
grunt.config('string-replace.meteor-package-js', {
files: {'meteor/package.js': 'meteor/package.js'},
options: {
replacements: [
{
pattern: /version: .*/,
replacement: 'version: \'' + version + '\','
}
]
}
});
grunt.task.run([
'string-replace:moment-js',
'string-replace:package-json',
'string-replace:component-json',
'string-replace:moment-js-nuspec',
'string-replace:meteor-package-js'
]);
});
};
+13
View File
@@ -0,0 +1,13 @@
module.exports = function (grunt) {
// Pull requests do not have secure variables enabled for security reasons.
// Use this task before launching travis-sauce-browser task, so it would
// exit early and won't try connecting to SauceLabs without credentials.
grunt.registerTask('check-sauce-creds', function () {
if (process.env.SAUCE_USERNAME === undefined) {
grunt.log.writeln('No sauce credentials found');
grunt.task.clearQueue();
} else {
grunt.log.writeln('Sauce credentials found');
}
});
};
+10
View File
@@ -0,0 +1,10 @@
module.exports = function (grunt) {
grunt.registerTask('component', function () {
var config = JSON.parse(grunt.file.read('component.json'));
config.files = grunt.file.expand('locale/*.js');
config.files.unshift('moment.js');
grunt.file.write('component.json', JSON.stringify(config, true, 2) + '\n');
});
};
+45
View File
@@ -0,0 +1,45 @@
module.exports = function (grunt) {
// To set up on mac:
// * brew install nuget # this fetches mono
// * go to nuget.org, login, click on username (top right), copy api-key
// from the bottom
// * grunt nugetkey --key=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
// * grunt nuget-publish
//
//
// If this fails you might need to follow:
//
// http://stackoverflow.com/questions/15181888/nuget-on-linux-error-getting-response-stream
//
// $ sudo mozroots --import --machine --sync
// $ sudo certmgr -ssl -m https://go.microsoft.com
// $ sudo certmgr -ssl -m https://nugetgallery.blob.core.windows.net
// $ sudo certmgr -ssl -m https://nuget.org
grunt.config('nugetpack', {
dist: {
src: 'Moment.js.nuspec',
dest: './'
}
});
grunt.registerTask('nugetkey_pre', function () {
grunt.option('key', process.env.NUGET_KEY);
grunt.option('source', 'https://www.nuget.org/api/v2/package');
});
grunt.registerTask('nugetkey_post', function () {
grunt.option('key', null);
grunt.option('source', null);
});
grunt.config('nugetpush', {
dist: {
src: 'Moment.js.*.nupkg'
}
});
grunt.config('clean.nuget', {
src: 'Moment.js.*.nupkg'
});
grunt.registerTask('nuget-publish', [
'nugetpack', 'nugetkey_pre', 'nugetkey', 'nugetkey_post', 'nugetpush', 'clean:nuget'
]);
};
+46
View File
@@ -0,0 +1,46 @@
module.exports = function (grunt) {
grunt.task.registerTask('qtest', 'run tests locally', function () {
var done = this.async();
var testrunner = require('qunit');
testrunner.options.log.assertions = false;
testrunner.options.log.tests = false;
testrunner.options.log.summary = false;
testrunner.options.log.testing = false;
testrunner.options.maxBlockDuration = 120000;
var tests;
if (grunt.option('only') != null) {
tests = grunt.file.expand.apply(null, grunt.option('only').split(',').map(function (file) {
if (file === 'moment') {
return 'build/umd/test/moment/*.js';
} else if (file === 'locale') {
return 'build/umd/test/locale/*.js';
} else {
return 'build/umd/test/' + file + '.js';
}
}));
} else {
tests = grunt.file.expand('build/umd/test/moment/*.js',
'build/umd/test/locale/*.js');
}
testrunner.run({
code: 'build/umd/moment.js',
tests: tests
}, function (err, report) {
if (err) {
console.log('woot', err, report);
done(err);
return;
}
err = null;
if (report.failed !== 0) {
err = new Error(report.failed + ' tests failed');
}
done(err);
});
});
};
+321
View File
@@ -0,0 +1,321 @@
module.exports = function (grunt) {
// var esperanto = require('esperanto');
var rollup = require('rollup').rollup;
// var babel = require('rollup-plugin-babel');
var path = require('path');
var Promise = require('es6-promise').Promise;
var TMP_DIR = 'build/tmp';
function moveComments(code, moveType) {
var comments = [], rest = [], skipId = -1;
code.split('\n').forEach(function (line, i) {
var isComment = false;
if (line.trim().slice(0, 3) === '//!') {
isComment = true;
}
if (isComment && moveType === 'main-only') {
if (i === skipId + 1 ||
line.trim() === '//! moment.js locale configuration') {
skipId = i;
// continue to next line
return;
}
}
if (isComment) {
comments.push(line.trim());
} else {
rest.push(line);
}
});
return comments.concat([''], rest).join('\n');
}
var headerCache = {};
function getHeaderByFile(headerFile) {
if (headerFile === 'none') {
return '';
}
if (!(headerFile in headerCache)) {
headerCache[headerFile] = grunt.file.read(headerFile);
}
return headerCache[headerFile];
}
function rollupBundle(opts) {
// entry, umdName, skipMoment
var rollupOpts = {
entry: opts.entry,
plugins: [
// babel({})
]
}, bundleOpts = {
format: 'umd',
moduleName: opts.umdName != null ? opts.umdName : 'not_used'
};
if (opts.skipMoment) {
// And this is what people call progress?
rollupOpts.external = [
'./moment',
'../moment',
'../../moment',
path.resolve('src/moment'),
path.resolve('build/tmp/moment')
];
bundleOpts.globals = {};
bundleOpts.globals[path.resolve('src/moment')] = 'moment';
bundleOpts.globals[path.resolve('build/tmp/moment')] = 'moment';
}
return rollup(rollupOpts).then(function (bundle) {
return bundle.generate(bundleOpts);
}).then(function (result) {
return result.code;
});
}
function transpile(opts) {
// base, entry, skipMoment, headerFile, skipLines, target
var umdName = opts.headerFile != null && opts.headerFile !== 'none' ? 'not_used' : opts.umdName,
headerFile = opts.headerFile ? opts.headerFile : 'templates/default.js',
header = getHeaderByFile(headerFile),
skipLines = opts.skipLines != null ? opts.skipLines : 5;
return rollupBundle({
entry: path.join(opts.base, opts.entry),
skipMoment: opts.skipMoment != null ? opts.skipMoment : false,
umdName: umdName
}).then(function (code) {
var fixed = header + code.split('\n').slice(skipLines).join('\n');
if (opts.moveComments) {
fixed = moveComments(fixed, opts.moveComments);
}
grunt.file.write(opts.target, fixed);
});
}
function transpileMany(opts) {
var batchSize = 50,
promise = Promise.resolve(null),
files = grunt.file.expand({cwd: opts.base}, opts.pattern),
i,
transpileOne = function (i) {
promise = promise.then(function () {
return Promise.all(files.slice(i, i + batchSize).map(function (file) {
return transpile({
base: opts.base,
entry: file,
headerFile: opts.headerFile,
skipMoment: opts.skipMoment,
skipLines: opts.skipLines,
moveComments: opts.moveComments,
target: path.join(opts.targetDir, file)
});
}));
});
};
for (i = 0; i < files.length; i += batchSize) {
transpileOne(i);
}
return promise;
}
function prepareTemp(base) {
var files = grunt.file.expand({cwd: base}, '**/*.js'),
tmpDir = TMP_DIR;
if (grunt.file.exists(tmpDir)) {
return;
}
files.forEach(function (file) {
grunt.file.copy(path.join(base, file), path.join(tmpDir, file));
});
}
function transpileCode(opts) {
var entry = opts.entry || path.basename(opts.target);
prepareTemp(opts.base);
grunt.file.write(path.join(TMP_DIR, entry), opts.code);
return transpile({
base: TMP_DIR,
entry: entry,
umdName: opts.umdName || 'not_used',
headerFile: opts.headerFile,
skipLines: opts.skipLines,
moveComments: opts.moveComments,
target: opts.target,
skipMoment: opts.skipMoment
});
}
function generateLocales(target, localeFiles, opts) {
var files = localeFiles,
code = [
'import moment from "./moment";',
'export default moment;'
].concat(files.map(function (file) {
var identifier = path.basename(file, '.js').replace('-', '_');
return 'import ' + identifier + ' from "./' + file + '";';
})).concat([
// Reset the language back to 'en', because every defineLocale
// also sets it.
'moment.locale(\'en\');'
]).join('\n');
return transpileCode({
base: 'src',
code: code,
target: target,
skipMoment: opts.skipMoment,
headerFile: opts.skipMoment === true ? 'templates/locale-header.js' : 'templates/default.js',
skipLines: opts.skipMoment === true ? 7 : 5
});
}
grunt.task.registerTask('transpile-raw', 'convert es6 to umd', function () {
var done = this.async();
transpile({
base: 'src',
entry: 'moment.js',
umdName: 'moment',
target: 'build/umd/moment.js',
skipLines: 5,
moveComments: true
}).then(function () {
grunt.log.ok('build/umd/moment.js');
}).then(function () {
return transpileMany({
base: 'src',
pattern: 'locale/*.js',
headerFile: 'templates/locale-header.js',
skipLines: 7,
moveComments: true,
targetDir: 'build/umd',
skipMoment: true
});
}).then(function () {
grunt.log.ok('build/umd/locale/*.js');
}).then(function () {
return transpileMany({
base: 'src',
pattern: 'test/moment/*.js',
headerFile: 'templates/test-header.js',
skipLines: 7,
moveComments: true,
targetDir: 'build/umd',
skipMoment: true
});
}).then(function () {
grunt.log.ok('build/umd/test/moment/*.js');
}).then(function () {
return transpileMany({
base: 'src',
pattern: 'test/locale/*.js',
headerFile: 'templates/test-header.js',
skipLines: 7,
moveComments: true,
targetDir: 'build/umd',
skipMoment: true
});
}).then(function () {
grunt.log.ok('build/umd/test/locale/*.js');
}).then(function () {
return generateLocales(
'build/umd/min/locales.js',
grunt.file.expand({cwd: 'src'}, 'locale/*.js'),
{skipMoment: true}
);
}).then(function () {
grunt.log.ok('build/umd/min/locales.js');
}).then(function () {
return generateLocales(
'build/umd/min/moment-with-locales.js',
grunt.file.expand({cwd: 'src'}, 'locale/*.js'),
{skipMoment: false}
);
}).then(function () {
grunt.log.ok('build/umd/min/moment-with-locales.js');
}).then(done, function (e) {
grunt.log.error('error transpiling', e);
done(e);
});
});
grunt.task.registerTask('transpile-custom-raw',
'build just custom language bundles',
function (locales) {
var done = this.async();
var localeFiles = locales.split(',').map(function (locale) {
var file = grunt.file.expand({cwd: 'src'}, 'locale/' + locale + '.js');
if (file.length !== 1) {
// we failed to find a locale
done(new Error('could not find locale: ' + locale));
done = null;
} else {
return file[0];
}
});
// There was an issue with a locale
if (done == null) {
return;
}
return generateLocales(
'build/umd/min/locales.custom.js',
localeFiles,
{skipMoment: true}
).then(function () {
grunt.log.ok('build/umd/min/locales.custom.js');
}).then(function () {
return generateLocales(
'build/umd/min/moment-with-locales.custom.js',
localeFiles,
{skipMoment: false});
}).then(function () {
grunt.log.ok('build/umd/min/moment-with-locales.custom.js');
}).then(function () {
var moment = require('../build/umd/min/moment-with-locales.custom.js');
if (moment.locales().filter(function (locale) {
return locale !== 'en';
}).length !== localeFiles.length) {
throw new Error(
'You probably specified locales requiring ' +
'parent locale, but didn\'t specify parent');
}
}).then(done, function (e) {
grunt.log.error('error transpiling-custom', e);
done(e);
});
});
grunt.config('clean.build', [
'build'
]);
grunt.config('concat.tests', {
src: 'build/umd/test/**/*.js',
dest: 'build/umd/min/tests.js'
});
grunt.task.registerTask('transpile',
'builds all es5 files, optinally creating custom locales',
function (locales) {
var tasks = [
'clean:build',
'transpile-raw',
'concat:tests'
];
if (locales) {
tasks.push('transpile-custom-raw:' + locales);
}
grunt.task.run(tasks);
});
};
+16
View File
@@ -0,0 +1,16 @@
module.exports = function (grunt) {
grunt.config('copy.index-files', {
expand: true,
cwd: 'build/umd/',
src: [
'moment.js',
'locale/*.js',
'min/locales.js',
'min/moment-with-locales.js',
'min/tests.js'
],
dest: '.'
});
grunt.registerTask('update-index', ['copy:index-files']);
};