Created
February 13, 2019 11:02
-
-
Save mrhammadasif/7d2278f6bdaa74a326b61b1fc142ec2b to your computer and use it in GitHub Desktop.
gulp plugin for .env files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const through = require("through2") | |
function changeEnvToDev(val) { | |
return through.obj(function(file, encoding, callback) { | |
if (file.isNull()) return callback(null, file) | |
if (file.isStream()) { | |
//file.contents = file.contents.pipe(... | |
//return callback(null, file); | |
this.emit("error", new Error("Streams not supported!")) | |
} else if (file.isBuffer()) { | |
let fc = file.contents.toString().split("\n") | |
fc[fc.findIndex(f => f.startsWith("NODE_ENV"))] = `NODE_ENV=${val}` | |
file.contents = new Buffer(String(fc.join("\n"))) | |
return callback(null, file) | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment