gulp-coffee
gulp-coffee copied to clipboard
Expose path information on failure
I would like to write an error handler that writes a small JS file when gulp-coffee fails. For example if a.coffee
has a syntax error, I want to create a.js
with:
throw new Error('Error compiling a.coffee: <syntaxerror.stack>');
For this, my gulp task needs access to the name of the JS file that gulp-coffee was trying to create.
This should get you what you need.
gulpfile.coffee
gulp = require 'gulp'
coffee = require 'gulp-coffee'
path = require 'path'
gulp.task 'compile', ->
coffeeStream = coffee().on 'error', (error) ->
{filename} = error
extension = path.extname error.filename
dirname = path.dirname filename
basename = path.basename error.filename, '.coffee'
target = path.join dirname, "#{basename}.js"
return gulp.src('src/**/*.coffee')
.pipe(coffeeStream)
.pipe(gulp.dest('lib'))
I think the problem here came from CS 1.6 -> 1.7
It used to be 'fileName' which is a semi-standard Error class attributed, and it changed to 'filename' which isn't. I'll see what I can do.