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 insert = require('gulp-insert'),
11 inquirer = require('inquirer'),
12 semver = require('semver'),
13 exec = require('child_process').exec,
15 package = require('./package.json'),
16 bower = require('./bower.json'),
17 karma = require('gulp-karma'),
18 browserify = require('browserify'),
19 streamify = require('gulp-streamify'),
20 source = require('vinyl-source-stream'),
21 merge = require('merge-stream');
23 var srcDir = './src/';
24 var outDir = './dist/';
25 var testDir = './test/';
29 * http://chartjs.org/\n\
30 * Version: {{ version }}\n\
32 * Copyright 2016 Nick Downie\n\
33 * Released under the MIT license\n\
34 * https://github.com/chartjs/Chart.js/blob/master/LICENSE.md\n\
38 './node_modules/moment/min/moment.min.js',
42 './test/mockContext.js',
45 // Disable tests which need to be rewritten based on changes introduced by
46 // the following changes: https://github.com/chartjs/Chart.js/pull/2346
47 '!./test/core.layoutService.tests.js',
48 '!./test/defaultConfig.tests.js',
51 gulp.task('build', buildTask);
52 gulp.task('coverage', coverageTask);
53 gulp.task('watch', watchTask);
54 gulp.task('bump', bumpTask);
55 gulp.task('release', ['build'], releaseTask);
56 gulp.task('jshint', jshintTask);
57 gulp.task('test', ['jshint', 'validHTML', 'unittest']);
58 gulp.task('size', ['library-size', 'module-sizes']);
59 gulp.task('server', serverTask);
60 gulp.task('validHTML', validHTMLTask);
61 gulp.task('unittest', unittestTask);
62 gulp.task('unittestWatch', unittestWatchTask);
63 gulp.task('library-size', librarySizeTask);
64 gulp.task('module-sizes', moduleSizesTask);
65 gulp.task('_open', _openTask);
66 gulp.task('dev', ['server', 'default']);
68 gulp.task('default', ['build', 'watch']);
71 function buildTask() {
73 var bundled = browserify('./src/chart.js')
75 .pipe(source('Chart.bundle.js'))
76 .pipe(insert.prepend(header))
77 .pipe(streamify(replace('{{ version }}', package.version)))
78 .pipe(gulp.dest(outDir))
79 .pipe(streamify(uglify()))
80 .pipe(insert.prepend(header))
81 .pipe(streamify(replace('{{ version }}', package.version)))
82 .pipe(streamify(concat('Chart.bundle.min.js')))
83 .pipe(gulp.dest(outDir));
85 var nonBundled = browserify('./src/chart.js')
88 .pipe(source('Chart.js'))
89 .pipe(insert.prepend(header))
90 .pipe(streamify(replace('{{ version }}', package.version)))
91 .pipe(gulp.dest(outDir))
92 .pipe(streamify(uglify()))
93 .pipe(insert.prepend(header))
94 .pipe(streamify(replace('{{ version }}', package.version)))
95 .pipe(streamify(concat('Chart.min.js')))
96 .pipe(gulp.dest(outDir));
98 return merge(bundled, nonBundled);
104 * Prompts: Version increment to bump
105 * Output: - New version number written into package.json & bower.json
107 function bumpTask(complete) {
108 util.log('Current version:', util.colors.cyan(package.version));
109 var choices = ['major', 'premajor', 'minor', 'preminor', 'patch', 'prepatch', 'prerelease'].map(function(versionType) {
110 return versionType + ' (v' + semver.inc(package.version, versionType) + ')';
115 message: 'What version update would you like?',
118 var increment = res.version.split(' ')[0],
119 newVersion = semver.inc(package.version, increment),
120 oldVersion = package.version;
122 // Set the new versions into the bower/package object
123 package.version = newVersion;
124 bower.version = newVersion;
126 // Write these to their own files, then build the output
127 fs.writeFileSync('package.json', JSON.stringify(package, null, 2));
128 fs.writeFileSync('bower.json', JSON.stringify(bower, null, 2));
130 var oldCDN = 'https://cdnjs.cloudflare.com/ajax/libs/Chart.js/'+oldVersion+'/Chart.min.js',
131 newCDN = 'https://cdnjs.cloudflare.com/ajax/libs/Chart.js/'+newVersion+'/Chart.min.js';
133 gulp.src(['./README.md'])
134 .pipe(replace(oldCDN, newCDN))
135 .pipe(gulp.dest('./'));
142 function releaseTask() {
143 exec('git tag -a v' + package.version);
147 function jshintTask() {
148 return gulp.src(srcDir + '**/*.js')
149 .pipe(jshint('config.jshintrc'))
150 .pipe(jshint.reporter('jshint-stylish'))
151 .pipe(jshint.reporter('fail'));
155 function validHTMLTask() {
156 return gulp.src('samples/*.html')
161 function unittestTask() {
162 var files = ['./src/**/*.js'];
163 Array.prototype.unshift.apply(files, preTestFiles);
164 Array.prototype.push.apply(files, testFiles);
166 return gulp.src(files)
168 configFile: 'karma.conf.ci.js',
173 function unittestWatchTask() {
174 var files = ['./src/**/*.js'];
175 Array.prototype.unshift.apply(files, preTestFiles);
176 Array.prototype.push.apply(files, testFiles);
178 return gulp.src(files)
180 configFile: 'karma.conf.js',
185 function coverageTask() {
186 var files = ['./src/**/*.js'];
187 Array.prototype.unshift.apply(files, preTestFiles);
188 Array.prototype.push.apply(files, testFiles);
190 return gulp.src(files)
192 configFile: 'karma.coverage.conf.js',
197 function librarySizeTask() {
198 return gulp.src('dist/Chart.bundle.min.js')
204 function moduleSizesTask() {
205 return gulp.src(srcDir + '**/*.js')
207 preserveComments: 'some'
215 function watchTask() {
217 return gulp.watch('./src/**', ['build', 'unittest', 'unittestWatch']);
219 return gulp.watch('./src/**', ['build']);
222 function serverTask() {
228 // Convenience task for opening the project straight from the command line
230 function _openTask() {
231 exec('open http://localhost:8000');