Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log gulp error to Chart.js #5143

Merged
merged 13 commits into from Jan 13, 2018
14 changes: 13 additions & 1 deletion gulpfile.js
Expand Up @@ -20,6 +20,7 @@ var collapse = require('bundle-collapser/plugin');
var argv = require('yargs').argv
var path = require('path');
var package = require('./package.json');
var fs = require('fs');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] can we move var fs before var package since the later one is a local file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes
while i'm at it, is there any logic in the order for the non local dependencies ? alphabetical, date of addition ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No guideline for the order because some require() may need other ones. I'm used to gather related dependencies (e.g. gulp-*) and declare the package.json at the end.


var srcDir = './src/';
var outDir = './dist/';
Expand Down Expand Up @@ -78,10 +79,15 @@ function bowerTask() {
}

function buildTask() {

var bundled = browserify('./src/chart.js', { standalone: 'Chart' })
.plugin(collapse)
.bundle()
.on('error', function (err) {
util.log(util.colors.red('[Error]'), err.toString())
fs.writeFileSync(outDir+'Chart.bundle.js', 'console.error("Gulp: ' + err.toString() + '")');
fs.writeFileSync(outDir+'Chart.bundle.min.js', 'console.error("Gulp: ' + err.toString() + '")');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not alter Chart.bundle(.min)?.js, simply log the error to console.

this.emit('end');
})
.pipe(source('Chart.bundle.js'))
.pipe(insert.prepend(header))
.pipe(streamify(replace('{{ version }}', package.version)))
Expand All @@ -96,6 +102,12 @@ function buildTask() {
.ignore('moment')
.plugin(collapse)
.bundle()
.on('error', function (err) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we avoid code duplication by refactoring this method:

var errorHandler = function (err) {
   util.log(util.colors.red('[Error]'), err.toString());
   this.emit('end');
}
// ...

.bundle()
.on('error', errorHandler)
// ...
.on('error', errorHandler)

util.log(util.colors.red('[Error]'), err.toString())
fs.writeFileSync(outDir+'Chart.js', 'console.error("Gulp: ' + err.toString() + '")');
fs.writeFileSync(outDir+'Chart.min.js', 'console.error("Gulp: ' + err.toString() + '")');
this.emit('end');
})
.pipe(source('Chart.js'))
.pipe(insert.prepend(header))
.pipe(streamify(replace('{{ version }}', package.version)))
Expand Down