Skip to content

Commit

Permalink
Log gulp error to Chart.js (#5143)
Browse files Browse the repository at this point in the history
* Log errors and skip for buildTask

* Write gulp error to Chart.js
+ Add intentional error to core to check if travis fails

* Remove unused require

* Remove error + Proper require fs

* Fix newline

* Refactor

* Put back browser errors

* Use options

* Fix intentional error

* Use yargs + Refactor

* remove space

* Fefactor

* Use booleans
  • Loading branch information
loicbourgois authored and etimberg committed Jan 13, 2018
1 parent 37ec838 commit e585c75
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,17 @@ var browserify = require('browserify');
var source = require('vinyl-source-stream');
var merge = require('merge-stream');
var collapse = require('bundle-collapser/plugin');
var argv = require('yargs').argv
var yargs = require('yargs');
var path = require('path');
var fs = require('fs');
var package = require('./package.json');

var argv = yargs
.option('force-output', {default: false})
.option('silent-errors', {default: false})
.option('verbose', {default: false})
.argv

var srcDir = './src/';
var outDir = './dist/';

Expand All @@ -34,6 +41,10 @@ var header = "/*!\n" +
" * https://github.com/chartjs/Chart.js/blob/master/LICENSE.md\n" +
" */\n";

if (argv.verbose) {
util.log("Gulp running with options: " + JSON.stringify(argv, null, 2));
}

gulp.task('bower', bowerTask);
gulp.task('build', buildTask);
gulp.task('package', packageTask);
Expand Down Expand Up @@ -79,9 +90,25 @@ function bowerTask() {

function buildTask() {

var errorHandler = function (err) {
if(argv.forceOutput) {
var browserError = 'console.error("Gulp: ' + err.toString() + '")';
['Chart', 'Chart.min', 'Chart.bundle', 'Chart.bundle.min'].forEach(function(fileName) {
fs.writeFileSync(outDir+fileName+'.js', browserError);
});
}
if(argv.silentErrors) {
util.log(util.colors.red('[Error]'), err.toString());
this.emit('end');
} else {
throw err;
}
}

var bundled = browserify('./src/chart.js', { standalone: 'Chart' })
.plugin(collapse)
.bundle()
.on('error', errorHandler)
.pipe(source('Chart.bundle.js'))
.pipe(insert.prepend(header))
.pipe(streamify(replace('{{ version }}', package.version)))
Expand All @@ -96,6 +123,7 @@ function buildTask() {
.ignore('moment')
.plugin(collapse)
.bundle()
.on('error', errorHandler)
.pipe(source('Chart.js'))
.pipe(insert.prepend(header))
.pipe(streamify(replace('{{ version }}', package.version)))
Expand Down

0 comments on commit e585c75

Please sign in to comment.