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

add not found handler to prevent gulp interrupt when partial not found #5

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ var es = require('event-stream');
var gutil = require('gulp-util');
var ejs = require('ejs');

var logPrefix = "[" + gutil.colors.blue("ejs") + "]";

var notFoundHandler = function(err, file, settings) {
var errorMessage = "partial '" + err.path + "' not found";
gutil.log(logPrefix, gutil.colors.red(errorMessage));
file.contents = new Buffer(errorMessage); // Output error message into file
file.path = gutil.replaceExtension(file.path, settings.ext);
return file;
}

module.exports = function (options, settings) {
settings = settings || {};
options = options || {};
Expand All @@ -15,6 +25,10 @@ module.exports = function (options, settings) {
file.contents = new Buffer(ejs.render(file.contents.toString(), options));
file.path = gutil.replaceExtension(file.path, settings.ext);
} catch (err) {
if(err.code === 'ENOENT') {
// Partial file not found, keep gulp and log error
return cb(null, notFoundHandler(err, file, settings));
}
return cb(new gutil.PluginError('gulp-ejs', err));
}
cb(null, file);
Expand Down