-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
37 lines (27 loc) · 861 Bytes
/
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
'use strict';
var through = require('through2');
var PluginError = require("plugin-error");
var envifyReplace = require('loose-envify/replace');
var PLUGIN_NAME = 'gulp-envify';
function gulpEnvify(rootEnv) {
var envs = [rootEnv || process.env];
var stream = through.obj(function(file, enc, cb) {
if (file.isNull()) {
return cb(null, file);
}
if (file.isStream()) {
this.emit('error', new PluginError(PLUGIN_NAME, 'Streams are not supported!'));
return cb();
}
if (file.isBuffer()) {
file.contents = new Buffer(envifyReplace(file.contents.toString(), envs));
}
// make sure the file goes through the next gulp plugin
this.push(file);
// tell the stream engine that we are done with this file
cb();
});
// returning the file stream
return stream;
}
module.exports = gulpEnvify;