module.exports = function (grunt) {
- grunt.task.registerTask("qtest", "run tests locally", function () {
-
+ grunt.task.registerTask('qtest', 'run tests locally', function () {
var done = this.async();
- var testrunner = require("qunit");
+ var testrunner = require('qunit');
testrunner.options.log.assertions = false;
testrunner.options.log.tests = false;
testrunner.options.maxBlockDuration = 10000;
testrunner.run({
- code: "build/umd/moment.js",
- tests: grunt.file.expand("build/umd/test/moment/*.js",
- "build/umd/test/locale/*.js"),
- }, function(err, report) {
+ code: 'build/umd/moment.js',
+ tests: grunt.file.expand('build/umd/test/moment/*.js',
+ 'build/umd/test/locale/*.js')
+ }, function (err, report) {
if (err) {
console.log('woot', err, report);
done(err);
}
err = null;
if (report.failed !== 0) {
- err = new Error(report.failed + " tests failed");
+ err = new Error(report.failed + ' tests failed');
}
done(err);
});
-
});
};
var esperanto = require('esperanto');
var path = require('path');
var Promise = require('es6-promise').Promise;
- var TMP_DIR = "build/tmp";
+ var TMP_DIR = 'build/tmp';
function moveComments(code) {
var comments = [], rest = [];
}
function transpile(opts) {
- grunt.log.writeln("transpile", opts);
+ grunt.log.writeln('transpile', opts);
// base, entry, skip, headerFile, skipLines, target
- var umdName = opts.headerFile ? "not_used" : opts.umdName,
+ var umdName = opts.headerFile ? 'not_used' : opts.umdName,
header = opts.headerFile ? getHeaderByFile(opts.headerFile) : '',
skipLines = opts.skipLines ? opts.skipLines : 0;
return esperanto.bundle({
base: opts.base,
entry: opts.entry,
- skip: opts.skip || [],
- }).then(function(bundle) {
+ skip: opts.skip || []
+ }).then(function (bundle) {
var umd = bundle.toUmd({name: umdName}),
fixed = header + umd.code.split('\n').slice(skipLines).join('\n');
if (opts.moveComments) {
files = grunt.file.expand({cwd: opts.base}, opts.pattern),
i,
transpileOne = function (i) {
- promise = promise.then(function() {
- grunt.log.writeln("transpiling from", opts.pattern, i);
- return Promise.all(files.slice(i, i + batchSize).map(function(file) {
- grunt.log.writeln("transpiling", file);
+ promise = promise.then(function () {
+ grunt.log.writeln('transpiling from', opts.pattern, i);
+ return Promise.all(files.slice(i, i + batchSize).map(function (file) {
+ grunt.log.writeln('transpiling', file);
return transpile({
base: opts.base,
entry: file,
skip: opts.skip,
skipLines: opts.skipLines,
moveComments: opts.moveComments,
- target: path.join(opts.targetDir, file),
+ target: path.join(opts.targetDir, file)
});
}));
});
}
function prepareTemp(base) {
- var files = grunt.file.expand({cwd: base}, "**/*.js"),
+ var files = grunt.file.expand({cwd: base}, '**/*.js'),
tmpDir = TMP_DIR;
- grunt.log.writeln("preparint temp", base);
+ grunt.log.writeln('preparint temp', base);
if (grunt.file.exists(tmpDir)) {
return;
}
return transpile({
base: TMP_DIR,
entry: entry,
- umdName: opts.umdName || "not_used",
+ umdName: opts.umdName || 'not_used',
headerFile: opts.headerFile,
skipLines: opts.skipLines,
moveComments: opts.moveComments,
target: opts.target,
- skip: opts.skip,
+ skip: opts.skip
});
}
grunt.task.registerTask('transpile', 'convert es6 to umd', function () {
var done = this.async();
- grunt.log.writeln("cleaning up build");
- grunt.file.delete("build");
+ grunt.log.writeln('cleaning up build');
+ grunt.file.delete('build');
transpile({
base: 'src',
umdName: 'moment',
target: 'build/umd/moment.js',
moveComments: true
- }).then(function() {
+ }).then(function () {
return transpileMany({
base: 'src',
- pattern: "locale/*.js",
+ pattern: 'locale/*.js',
headerFile: 'templates/locale-header.js',
skipLines: 5,
moveComments: true,
targetDir: 'build/umd',
skip: ['moment']
});
- }).then(function() {
+ }).then(function () {
return transpileMany({
base: 'src',
- pattern: "test/moment/*.js",
+ pattern: 'test/moment/*.js',
headerFile: 'templates/test-header.js',
skipLines: 5,
moveComments: true,
}).then(function () {
return transpileMany({
base: 'src',
- pattern: "test/locale/*.js",
- headerFile: "templates/test-header.js",
+ pattern: 'test/locale/*.js',
+ headerFile: 'templates/test-header.js',
skipLines: 5,
moveComments: true,
- targetDir: "build/umd",
+ targetDir: 'build/umd',
skip: ['moment']
});
}).then(function () {
- var files = grunt.file.expand({cwd: "src"}, "locale/*.js"),
+ var files = grunt.file.expand({cwd: 'src'}, 'locale/*.js'),
code = files.map(function (file) {
var identifier = path.basename(file, '.js').replace('-', '_');
return 'import ' + identifier + ' from "./' + file + '";';
- }).join("\n");
+ }).join('\n');
return transpileCode({
base: 'src',
code: code,
target: 'build/umd/min/locales.js',
skip: ['moment'],
headerFile: 'templates/locale-header.js',
- skipLines: 5,
+ skipLines: 5
});
- }).then(function() {
- var files = grunt.file.expand({cwd: "src"}, "locale/*.js"),
+ }).then(function () {
+ var files = grunt.file.expand({cwd: 'src'}, 'locale/*.js'),
importCode = files.map(function (file) {
var identifier = path.basename(file, '.js').replace('-', '_');
var fileNoExt = file.replace('.js', '');
return 'import ' + identifier + ' from "./' + fileNoExt + '";';
- }).join("\n"),
+ }).join('\n'),
code = 'import * as moment_export from "./moment";\n\n' +
importCode + '\n\n' +
'export default moment_export;';
base: 'src',
code: code,
umdName: 'moment',
- target: 'build/umd/min/moment-with-locales.js',
- }).then(function() {
+ target: 'build/umd/min/moment-with-locales.js'
+ }).then(function () {
var code = grunt.file.read('build/umd/min/moment-with-locales.js');
code = code.replace(' var moment = {\n get default () { return moment__default; }\n };', '');
code = code.replace('var moment_with_locales = moment', 'var moment_with_locales = moment__default');
grunt.file.write('build/umd/min/moment-with-locales.js', code);
});
- }).then(done, function(e) {
- grunt.log.error("error transpiling", e);
+ }).then(done, function (e) {
+ grunt.log.error('error transpiling', e);
done(e);
});
});
if (err != null) {
throw err;
}
- iterator(i+1);
+ iterator(i + 1);
});
}(0));
});
}
callback(null, content.split(/\r\n|\r|\n/)
// remove empty and commented lines
- .filter(function (line) { return line && !/^#/.test(line); })
+ .filter(function (line) {
+ return line && !/^#/.test(line);
+ })
// country code TAB coordinates TAB timezone
- .map(function (line) { return line.split('\t')[2]; }));
+ .map(function (line) {
+ return line.split('\t')[2];
+ }));
});
}
grunt.log.ok('Running tests in zone ' + zone);
grunt.util.spawn({
cmd: 'grunt',
- opts: { env: {
- 'PATH': process.env.PATH,
- 'TZ': zone
- } },
+ 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); })
+ .filter(function (line) {
+ return /^(>>|Warning:|$)/.test(line);
+ })
+ .map(function (line) {
+ return (line.substr(0, 3) === '>> ' ? line.substr(3) : line);
+ })
.join('\n'));
}
next();