-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathindex.js
More file actions
42 lines (33 loc) · 897 Bytes
/
index.js
File metadata and controls
42 lines (33 loc) · 897 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
var through = require("through2");
var gutil = require("gulp-util");
var cdnizer = require('cdnizer');
function pluginError(msg) {
return new gutil.PluginError("gulp-cdnizer", msg);
}
module.exports = function(opts) {
"use strict";
var cdnizerHandler = cdnizer(opts);
//noinspection JSUnusedLocalSymbols
function cdnizerStream(file, enc, callback) {
// Do nothing if no contents
if(file.isNull()) {
this.push(file);
return callback();
}
if(file.isStream()) {
this.emit("error", pluginError("Stream content is not supported"));
return callback();
}
// check if file.contents is a `Buffer`
if(file.isBuffer()) {
try {
file.contents = new Buffer(cdnizerHandler(String(file.contents)));
this.push(file);
} catch(error) {
this.emit("error", pluginError(error.toString()))
}
}
return callback();
}
return through.obj(cdnizerStream);
};