-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
52 lines (39 loc) · 1.21 KB
/
index.js
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
43
44
45
46
47
48
49
50
51
52
var through = require("through2"),
gutil = require("gulp-util"),
path = require('path');
module.exports = function (param) {
"use strict";
// if necessary check for required param(s), e.g. options hash, etc.
if (!param) {
throw new gutil.PluginError("gulp-sync-env", "No param supplied");
}
// see "Writing a plugin"
// https://github.com/gulpjs/gulp/blob/master/docs/writing-a-plugin/README.md
function syncEnv(file, enc, callback) {
/*jshint validthis:true*/
// Do nothing if no contents
if (file.isNull()) {
this.push(file);
return callback();
}
if (file.isStream()) {
// http://nodejs.org/api/stream.html
// http://nodejs.org/api/child_process.html
// https://github.com/dominictarr/event-stream
// accepting streams is optional
this.emit("error",
new gutil.PluginError("gulp-sync-env", "Stream content is not supported"));
return callback();
}
// check if file.contents is a `Buffer`
if (file.isBuffer()) {
// manipulate buffer in some way
// http://nodejs.org/api/buffer.html
file.contents = new Buffer(String(file.contents).replace(/=[^\n]*/g, '=null'));
file.path = param;
this.push(file);
}
return callback();
}
return through.obj(syncEnv);
};