1 var gulp = require('gulp'),
2 concat = require('gulp-concat'),
3 uglify = require('gulp-uglify'),
4 util = require('gulp-util'),
5 jshint = require('gulp-jshint'),
6 size = require('gulp-size'),
7 connect = require('gulp-connect'),
8 replace = require('gulp-replace'),
9 htmlv = require('gulp-html-validator'),
10 inquirer = require('inquirer'),
11 semver = require('semver'),
12 exec = require('child_process').exec,
14 package = require('./package.json'),
15 bower = require('./bower.json');
17 var srcDir = './src/';
19 * Usage : gulp build --types=Bar,Line,Doughnut
20 * Output: - A built Chart.js file with Core and types Bar, Line and Doughnut concatenated together
21 * - A minified version of this code, in Chart.min.js
24 gulp.task('build', function(){
26 // Default to all of the chart types, with Chart.Core first
27 var srcFiles = [FileName('Core')],
28 isCustom = !!(util.env.types),
29 outputDir = (isCustom) ? 'custom' : '.';
31 util.env.types.split(',').forEach(function(type){ return srcFiles.push(FileName(type));});
34 // Seems gulp-concat remove duplicates - nice!
35 // So we can use this to sort out dependency order - aka include Core first!
36 srcFiles.push(srcDir+'*');
39 return gulp.src(srcFiles)
40 .pipe(concat('Chart.js'))
41 .pipe(replace('{{ version }}', package.version))
42 .pipe(gulp.dest(outputDir))
43 .pipe(uglify({preserveComments:'some'}))
44 .pipe(concat('Chart.min.js'))
45 .pipe(gulp.dest(outputDir));
47 function FileName(moduleName){
48 return srcDir+'Chart.'+moduleName+'.js';
54 * Prompts: Version increment to bump
55 * Output: - New version number written into package.json & bower.json
58 gulp.task('bump', function(complete){
59 util.log('Current version:', util.colors.cyan(package.version));
60 var choices = ['major', 'premajor', 'minor', 'preminor', 'patch', 'prepatch', 'prerelease'].map(function(versionType){
61 return versionType + ' (v' + semver.inc(package.version, versionType) + ')';
66 message: 'What version update would you like?',
69 var increment = res.version.split(' ')[0],
70 newVersion = semver.inc(package.version, increment);
72 // Set the new versions into the bower/package object
73 package.version = newVersion;
74 bower.version = newVersion;
76 // Write these to their own files, then build the output
77 fs.writeFileSync('package.json', JSON.stringify(package, null, 2));
78 fs.writeFileSync('bower.json', JSON.stringify(bower, null, 2));
84 gulp.task('release', ['build'], function(){
85 exec('git tag -a v' + package.version);
88 gulp.task('jshint', function(){
89 return gulp.src(srcDir + '*.js')
91 .pipe(jshint.reporter('default'));
94 gulp.task('valid', function(){
95 return gulp.src('samples/*.html')
99 gulp.task('library-size', function(){
100 return gulp.src('Chart.min.js')
106 gulp.task('module-sizes', function(){
107 return gulp.src(srcDir + '*.js')
108 .pipe(uglify({preserveComments:'some'}))
115 gulp.task('watch', function(){
116 gulp.watch('./src/*', ['build']);
119 gulp.task('test', ['jshint', 'valid']);
121 gulp.task('size', ['library-size', 'module-sizes']);
123 gulp.task('default', ['build', 'watch']);
125 gulp.task('server', function(){
131 // Convenience task for opening the project straight from the command line
132 gulp.task('_open', function(){
133 exec('open http://localhost:8000');
137 gulp.task('dev', ['server', 'default']);