Skip to content

Instantly share code, notes, and snippets.

@mrhammadasif
Created February 13, 2019 11:02
Show Gist options
  • Save mrhammadasif/7d2278f6bdaa74a326b61b1fc142ec2b to your computer and use it in GitHub Desktop.
Save mrhammadasif/7d2278f6bdaa74a326b61b1fc142ec2b to your computer and use it in GitHub Desktop.
gulp plugin for .env files
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