now handling empty files alright and handling errors better. fixes #48
This commit is contained in:
@ -1,18 +1,36 @@
|
||||
/// <reference path="./typings/main.d.ts" />
|
||||
import plugins = require("./gulpbrowser.plugins");
|
||||
|
||||
|
||||
let browserify = function() {
|
||||
return plugins.through.obj((file, enc, cb) => { //this is the through object that gets returned by gulpBrowser.browserify();
|
||||
var bundleCallback = function(err, bufferedContent) {
|
||||
if (Buffer.isBuffer(bufferedContent)){
|
||||
file.contents = bufferedContent;
|
||||
} else {
|
||||
plugins.beautylog.error("gulp-browser: .browserify() " + err.message);
|
||||
}
|
||||
cb(null,file);
|
||||
};
|
||||
|
||||
let forEach = function(file, enc, cb){ // do this with every chunk (file in gulp terms)
|
||||
|
||||
let bundleCallback = function(err, bufferedContent) { // our bundle callback for when browserify is finished
|
||||
if (Buffer.isBuffer(bufferedContent)){
|
||||
file.contents = bufferedContent;
|
||||
} else {
|
||||
plugins.beautylog.error("gulp-browser: .browserify() " + err.message);
|
||||
cb(new Error(err.message),file);
|
||||
return;
|
||||
}
|
||||
cb(null,file);
|
||||
};
|
||||
|
||||
if(file.contents.length > 0){
|
||||
plugins.browserify(file, { basedir: file.base })
|
||||
.bundle(bundleCallback)
|
||||
});
|
||||
.bundle(bundleCallback);
|
||||
} else {
|
||||
plugins.beautylog.warn("gulp-browser: .browserify() file.contents appears to be empty");
|
||||
cb(null,file);
|
||||
};
|
||||
}
|
||||
|
||||
let atEnd = function(cb){
|
||||
cb();
|
||||
} // no need to clean up after ourselves
|
||||
|
||||
return plugins.through.obj(forEach,atEnd); // this is the through object that gets returned by gulpBrowser.browserify();
|
||||
};
|
||||
|
||||
export = browserify;
|
@ -1,10 +1,5 @@
|
||||
/// <reference path="./typings/main.d.ts" />
|
||||
var plugins = {
|
||||
beautylog: require("beautylog"),
|
||||
through: require("through2"),
|
||||
gutil: require("gulp-util"),
|
||||
path: require("path"),
|
||||
browserify: require("browserify")
|
||||
};
|
||||
|
||||
export = plugins;
|
||||
export let beautylog = require("beautylog");
|
||||
export let through = require("through2");
|
||||
export let path = require("path");
|
||||
export let browserify = require("browserify");
|
||||
|
Reference in New Issue
Block a user