Skip to content

Instantly share code, notes, and snippets.

@nook-scheel
Created December 2, 2014 21:57
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save nook-scheel/d1982aa37ffea6cedf74 to your computer and use it in GitHub Desktop.
Heroku write config vars
/*!
* Module dependencies.
*/
var Heroku = require('heroku-client')
, _ = require('lodash')
, async = require('async')
, fs = require('fs')
, path = require('path')
, envfile = require('envfile')
, argv = require('optimist').argv
, heroku = new Heroku({ token: process.env.HEROKU_API_TOKEN });
var local_config_filename = argv.e || argv.env || '.env'
, app = argv.app || argv.a
, overwrite = argv.o || argv.overwrite && true || false;
if (!app)
throw Error('Specify which app to use with --app APP.');
async.auto({
read_remote_config: read_local_config,
read_local_config: read_local_config,
merge_config: ['read_remote_config','read_local_config', merge_config],
write_remote_config: ['merge_config', write_remote_config]
}, function (err, results) {
console.log(err, results, overwrite);
});
function write_remote_config(done, results) {
heroku.patch('/apps/' + app + '/config-vars', results.merge_config, done);
}
function merge_config(done, results) {
done(null, _.extend(results.read_remote_config, results.read_local_config));
};
function read_remote_config(done) {
heroku.get('/apps/' + app + '/config-vars', done);
}
function read_local_config(done) {
fs.readFile(path.join(__dirname, local_config_filename), function (err, config) {
if (err) return done(err);
envfile.parse(config, done);
})
}
{
"name": "config",
"version": "0.0.1",
"description": "",
"main": "index.js",
"dependencies": {
"async": "^0.9.0",
"envfile": "^1.0.0",
"heroku-client": "^1.9.0",
"lodash": "^2.4.1",
"optimist": "^0.6.1"
},
"devDependencies": {},
"scripts": {
"start": "node index.js"
},
"repository": {
"type": "git",
"url": "git@bitbucket.org:hobout/config.git"
},
"author": "NooK Scheel <nook@live.ru>",
"license": "ISC"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment