Skip to content

Instantly share code, notes, and snippets.

@wamoyo
Created January 24, 2015 02:49
Show Gist options
  • Save wamoyo/dca0c3ea938d0ef0e2c8 to your computer and use it in GitHub Desktop.
Save wamoyo/dca0c3ea938d0ef0e2c8 to your computer and use it in GitHub Desktop.
A quick way to stage and application to nodejitsu (doesn't yet copy environment variables)
/*
* Use this file to deploy an app to the staging server on nodejitsu.
*/
var fs = require('fs');
var package = '';
var bash = require('child_process');
var jitsu;
// Save a backup of package.json, alter the current one, deploy to nodejitsu,
// and upon successful deploy, restore the package.json to it's original form.
fs.readFile('package.json', {encoding: 'utf-8'}, function (err, data) { // grab the package.json file contents
if (err) throw err;
package = JSON.parse(data);
fs.rename('package.json', 'production-package.json'); // rename the package.json file
package.name = 'stajing'; // alter json
package.subdomain = 'stajing'; // alter json
package.domains = []; // alter json
fs.writeFile('package.json', JSON.stringify(package, null, 2), function(err) { // write the new package to package.json
if (err) throw err;
// Do `jitsu deploy` now with the new package.json.
jitsu = bash.spawn('jitsu', ['deploy'], { // Spawn Bash instance to deploy to staging drone.
cwd: process.cwd(),
stdio: 'inherit'
});
// If `jitsu deploy` yields an error...
jitsu.on('error', function (code, signal) {
if(error) {
console.log("Some kind of Bash Error: ", code, signal);
return bash.disconnect();
}
});
// If `jitsu deploy` exits successfully...
jitsu.on('exit', function (code, signal) {
if (code === 0) {
fs.unlink('package.json', function (err) {
if (err) throw err;
fs.rename('production-package.json', 'package.json');
return console.log("App staged successfully : )");
});
} else {
return console.log("Didn't finish successfully : (", code, signal);
}
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment