Created
January 24, 2015 02:49
-
-
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)
This file contains 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
/* | |
* 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