module.exports = function (grunt) {
- var embedOption = grunt.option('embedLocales'),
- embedLocaleDest = embedOption ?
- 'min/moment-with-customlocales.js' :
- 'min/moment-with-locales.js',
- embedLocaleSrc = 'locale/*.js';
-
- if (embedOption && embedOption.match(/,/)) {
- embedLocaleSrc = 'locale/{' + embedOption + '}.js';
- }
- else if (embedOption) {
- embedLocaleSrc = 'locale/' + embedOption + '.js';
- }
-
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
- concat : {
- locales: {
- src: 'locale/*.js',
- dest: 'min/locales.js'
- },
- tests: {
- src: [
- 'test/browser-prefix.js',
- 'test/moment/*.js',
- 'test/locale/*.js',
- 'test/browser-suffix.js'
- ],
- dest: 'min/tests.js'
- }
- },
env : {
sauceLabs : (grunt.file.exists('.sauce-labs.creds') ?
grunt.file.readJSON('.sauce-labs.creds') : {})
},
karma : {
options: {
- frameworks: ['nodeunit'],
+ frameworks: ['qunit'],
files: [
- 'min/moment-with-locales.js',
- 'min/tests.js',
- 'test/browser.js'
+ 'build/umd/min/moment-with-locales.js',
+ 'build/umd/min/tests.js'
],
sauceLabs: {
startConnect: true,
]
}
},
-
uglify : {
main: {
files: {
'min/moment.min.js' : 'moment.js'
}
},
- customlocales: {
- files: {
- 'min/moment-with-customlocales.min.js' : 'min/moment-with-customlocales.js'
- }
- },
options: {
mangle: true,
compress: {
preserveComments: 'some'
}
},
- nodeunit : {
- all : ['test/moment/**/*.js', 'test/locale/**/*.js']
- },
jshint: {
all: [
'Gruntfile.js',
watch : {
test : {
files : [
- 'moment.js',
- 'locale/*.js',
- 'test/**/*.js'
+ 'src/**/*.js',
],
- tasks: ['nodeunit']
+ tasks: ['test']
},
jshint : {
files : '<%= jshint.all %>',
tasks: ['jshint']
}
},
- embedLocales: {
- moment: 'moment.js',
- dest: embedLocaleDest,
- targetLocales: embedLocaleSrc
- },
benchmark: {
all: {
src: ['benchmarks/*.js']
// test tasks
grunt.registerTask('test', ['test:node']);
grunt.registerTask('test:node', ['transpile', 'qtest']);
- grunt.registerTask('test:server', ['concat', 'embedLocales', 'karma:server']);
- grunt.registerTask('test:browser', ['concat', 'embedLocales', 'karma:chrome', 'karma:firefox']);
- grunt.registerTask('test:sauce-browser', ['concat', 'embedLocales', 'env:sauceLabs', 'karma:sauce']);
- grunt.registerTask('test:travis-sauce-browser', ['concat', 'embedLocales', 'karma:sauce']);
+ grunt.registerTask('test:server', ['transpile', 'karma:server']);
+ grunt.registerTask('test:browser', ['transpile', 'karma:chrome', 'karma:firefox']);
+ grunt.registerTask('test:sauce-browser', ['transpile', 'env:sauceLabs', 'karma:sauce']);
+ grunt.registerTask('test:travis-sauce-browser', ['transpile', 'karma:sauce']);
grunt.registerTask('test:meteor', ['exec:meteor-init', 'exec:meteor-test', 'exec:meteor-cleanup']);
// travis build task
// Task to be run when releasing a new version
grunt.registerTask('release', [
- 'jshint', 'nodeunit', 'concat', 'embedLocales',
- 'component', 'uglify:main'
+ 'default',
+ 'update-index',
+ 'component',
+ 'uglify:main'
]);
};
"broccoli-uglify-js": "^0.1.3",
"es6-promise": "latest",
"grunt": "latest",
- "nodeunit": "latest",
"benchmark": "latest",
"grunt-contrib-clean": "latest",
+ "grunt-contrib-concat": "latest",
"grunt-contrib-copy": "latest",
"grunt-contrib-jshint": "latest",
- "grunt-contrib-nodeunit": "latest",
- "grunt-contrib-concat": "latest",
"grunt-contrib-uglify": "latest",
"grunt-contrib-watch": "latest",
"grunt-env": "latest",
"karma": "latest",
"karma-chrome-launcher": "latest",
"karma-firefox-launcher": "latest",
- "karma-nodeunit": "latest",
+ "karma-qunit": "latest",
"karma-sauce-launcher": "latest",
"qunit": "^0.7.5",
"qunit-cli": "^0.1.4",
}
assert.equal(m.calendar(), m.format('[下]ddd凌晨12点整'), 'Today + ' + i + ' days beginning of day');
}
+ assert.equal(42, 42, "at least one assert");
});
test('calendar last week', function (assert) {
}
assert.equal(m.calendar(), m.format('[上]ddd凌晨12点整'), 'Monday - ' + i + ' days next week');
}
- // ensure at least one assertion is run
- assert.equal(42, 42);
+ assert.equal(42, 42, "at least one assert");
});
test('calendar all else', function (assert) {
test('diff across DST', function (assert) {
var dst = dstForYear(2012), a, b, daysInMonth;
if (!dst) {
+ assert.equal(42, 42, "at least one assertion");
return;
}
var Promise = require('es6-promise').Promise;
var TMP_DIR = 'build/tmp';
+ grunt.config('concat.tests', {
+ src: 'build/umd/test/**/*.js',
+ dest: 'build/umd/min/tests.js'
+ });
+
function moveComments(code) {
var comments = [], rest = [];
code.split('\n').forEach(function (line) {
});
}
- grunt.task.registerTask('transpile', 'convert es6 to umd', function () {
+ grunt.task.registerTask('transpile-raw', 'convert es6 to umd', function () {
var done = this.async();
grunt.log.writeln('cleaning up build');
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 = {\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);
});
done(e);
});
});
+
+ grunt.registerTask('transpile', ['transpile-raw', 'concat:tests']);
};
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('../../moment')) :
- typeof define === 'function' && define.amd && define(['../../moment'], factory);
+ typeof define === 'function' && define.amd ? define(['../../moment'], factory) :
+ factory(global.moment)
}(this, function (moment) { 'use strict';