Skip to content

Instantly share code, notes, and snippets.

@joona
Last active November 30, 2016 16:44
Show Gist options
  • Select an option

  • Save joona/dba8c85739a7062d8f60dcba50718d81 to your computer and use it in GitHub Desktop.

Select an option

Save joona/dba8c85739a7062d8f60dcba50718d81 to your computer and use it in GitHub Desktop.
const fs = require('fs');
const qs = require('querystring');
const buf = fs.readFileSync('.env').toString();
const env = qs.parse(buf, "\n");
function getHash(env) {
return new Promise((resolve, reject) => {
require('child_process').exec('git rev-parse HEAD', (err, hash) => {
if(err) return reject(err);
env.COMMIT_HASH = hash;
resolve(hash);
});
});
}
function dump() {
Object.keys(env).forEach(k => { if(!k || k.length < 1 || !env[k]) delete env[k]; });
fs.writeFileSync('.env', qs.stringify(env, "\n", "=", {
encodeURIComponent: function(x) { return x; }
}));
}
getHash(env)
.then(_ => {
dump();
})
.catch(err => {
console.error(err.stack);
process.exit(1);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment