From: Tanner Linsley Date: Fri, 28 Aug 2015 22:58:23 +0000 (-0600) Subject: Organize Gulpfile, Integrate unit tests with Travis X-Git-Tag: 2.0.0-alpha4~38^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F1423%2Fhead;p=thirdparty%2FChart.js.git Organize Gulpfile, Integrate unit tests with Travis --- diff --git a/gulpfile.js b/gulpfile.js index 560c6b496..ba699af6b 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -24,19 +24,39 @@ var testDir = './test/'; */ var srcFiles = [ - './src/core/core.js', - './src/core/core.helpers.js', - './src/core/core.chart.js', - './src/core/core.element.js', - './src/core/**', - './src/controllers/**', - './src/scales/**', - './src/elements/**', - './src/charts/**', - './node_modules/color/dist/color.min.js' - ]; - -gulp.task('build', function() { + './src/core/core.js', + './src/core/core.helpers.js', + './src/core/core.chart.js', + './src/core/core.element.js', + './src/core/**', + './src/controllers/**', + './src/scales/**', + './src/elements/**', + './src/charts/**', + './node_modules/color/dist/color.min.js' +]; + + +gulp.task('build', buildTask); +gulp.task('watch', watchTask); +gulp.task('bump', bumpTask); +gulp.task('release', ['build'], releaseTask); +gulp.task('jshint', jshintTask); +gulp.task('test', ['jshint', 'validHTML', 'unittest']); +gulp.task('size', ['library-size', 'module-sizes']); +gulp.task('server', serverTask); +gulp.task('validHTML', validHTMLTask); +gulp.task('unittest', unittestTask); +gulp.task('unittestWatch', unittestWatchTask); +gulp.task('library-size', librarySizeTask); +gulp.task('module-sizes', moduleSizesTask); +gulp.task('_open', _openTask); +gulp.task('dev', ['server', 'default']); + +gulp.task('default', ['build', 'watch']); + + +function buildTask() { var isCustom = !!(util.env.types), outputDir = (isCustom) ? 'custom' : '.'; @@ -51,15 +71,14 @@ gulp.task('build', function() { .pipe(concat('Chart.min.js')) .pipe(gulp.dest(outputDir)); -}); +} /* * Usage : gulp bump * Prompts: Version increment to bump * Output: - New version number written into package.json & bower.json */ - -gulp.task('bump', function(complete) { +function bumpTask(complete) { util.log('Current version:', util.colors.cyan(package.version)); var choices = ['major', 'premajor', 'minor', 'preminor', 'patch', 'prepatch', 'prerelease'].map(function(versionType) { return versionType + ' (v' + semver.inc(package.version, versionType) + ')'; @@ -83,24 +102,39 @@ gulp.task('bump', function(complete) { complete(); }); -}); +} + -gulp.task('release', ['build'], function() { +function releaseTask() { exec('git tag -a v' + package.version); -}); +} + -gulp.task('jshint', function() { +function jshintTask() { return gulp.src(srcDir + '*.js') .pipe(jshint()) .pipe(jshint.reporter('default')); -}); +} -gulp.task('valid', function() { + +function validHTMLTask() { return gulp.src('samples/*.html') .pipe(htmlv()); -}); +} + + +function unittestTask() { + var files = srcFiles.slice(); + files.push(testDir + '*.js'); + + return gulp.src(files) + .pipe(karma({ + configFile: 'karma.conf.js', + action: 'run' + })); +} -gulp.task('unittest', function() { +function unittestWatchTask() { var files = srcFiles.slice(); files.push(testDir + '*.js'); @@ -109,16 +143,16 @@ gulp.task('unittest', function() { configFile: 'karma.conf.js', action: 'watch' })); -}); +} -gulp.task('library-size', function() { +function librarySizeTask() { return gulp.src('Chart.min.js') .pipe(size({ gzip: true })); -}); +} -gulp.task('module-sizes', function() { +function moduleSizesTask() { return gulp.src(srcDir + '*.js') .pipe(uglify({ preserveComments: 'some' @@ -127,28 +161,24 @@ gulp.task('module-sizes', function() { showFiles: true, gzip: true })); -}); +} -gulp.task('watch', function() { - gulp.watch('./src/**', ['build', 'unittest']); -}); -gulp.task('test', ['jshint', 'valid']); +function watchTask() { + gulp.watch('./src/**', ['build', 'unittest', 'unittestWatch']); +} -gulp.task('size', ['library-size', 'module-sizes']); -gulp.task('default', ['build', 'watch']); -gulp.task('server', function() { +function serverTask() { connect.server({ port: 8000 }); -}); +} // Convenience task for opening the project straight from the command line -gulp.task('_open', function() { + +function _openTask() { exec('open http://localhost:8000'); exec('subl .'); -}); - -gulp.task('dev', ['server', 'default']); +}