gulp-browser/dist/gulpbrowser.browserify.js

47 lines
6.1 KiB
JavaScript
Raw Normal View History

"use strict";
2016-02-26 16:57:53 +00:00
/// <reference path="./typings/main.d.ts" />
var plugins = require("./gulpbrowser.plugins");
2016-05-13 18:04:41 +00:00
var browserify = function (transforms) {
2016-05-13 18:20:07 +00:00
if (transforms === void 0) { transforms = []; }
2016-05-13 18:04:41 +00:00
if (!Array.isArray(transforms)) {
transforms = [transforms];
}
var forEach = function (file, enc, cb) {
2016-02-26 16:57:53 +00:00
var bundleCallback = function (err, bufferedContent) {
if (Buffer.isBuffer(bufferedContent)) {
file.contents = bufferedContent;
}
else {
plugins.beautylog.error("gulp-browser: .browserify() " + err.message);
cb(new Error(err.message), file);
return;
2016-02-26 16:57:53 +00:00
}
cb(null, file);
};
if (file.contents.length > 0) {
2016-05-13 18:04:41 +00:00
var browserified_1 = plugins.browserify(file, { basedir: file.base });
transforms.forEach(function (transform) {
if (typeof transform === 'function') {
browserified_1.transform(transform);
}
else {
browserified_1.transform(transform.transform, transform.options);
}
});
browserified_1.bundle(bundleCallback);
}
else {
plugins.beautylog.warn("gulp-browser: .browserify() file.contents appears to be empty");
cb(null, file);
}
;
};
var 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();
2016-02-26 16:57:53 +00:00
};
module.exports = browserify;
2016-05-13 18:20:07 +00:00
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImd1bHBicm93c2VyLmJyb3dzZXJpZnkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDRDQUE0QztBQUM1QyxJQUFPLE9BQU8sV0FBVyx1QkFBdUIsQ0FBQyxDQUFDO0FBR2xELElBQUksVUFBVSxHQUFJLFVBQVMsVUFBZTtJQUFmLDBCQUFlLEdBQWYsZUFBZTtJQUV0QyxFQUFFLENBQUMsQ0FBQyxDQU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gKHRyYW5zZm9ybSkge1xuICAgICAgICAgICAgICAgIGlmICh0eXBlb2YgdHJhbnNmb3JtID09PSAnZnVuY3Rpb24nKSB7XG4gICAgICAgICAgICAgICAgICAgIGJyb3dzZXJpZmllZC50cmFuc2Zvcm0odHJhbnNmb3JtKTtcbiAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICBicm93c2VyaWZpZWQudHJhbnNmb3JtKHRyYW5zZm9ybS50cmFuc2Zvcm0sIHRyYW5zZm9ybS5vcHRpb25zKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9KTtcblxuICAgICAgICAgICAgYnJvd3NlcmlmaWVkLmJ1bmRsZShidW5kbGVDYWxsYmFjayk7XG4gICAgICAgIH0gZWxzZSB7XG4gICAgICAgICAgICBwbHVnaW5zLmJlYXV0eWxvZy53YXJuKFwiZ3VscC1icm93c2VyOiAuYnJvd3NlcmlmeSgpIGZpbGUuY29udGVudHMg