Last active
November 30, 2016 16:44
-
-
Save joona/dba8c85739a7062d8f60dcba50718d81 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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