I'm trying to automate a process I go through every time I test my apps and sites on the server. I'm currently running on nodejitsu. When I've tested something and it works on my local machine, the next thing I do is...
- Open my package.json file
- Delete the domains field and change the name and subdomain to staging. (It might also make sense to change the version number)
- Then I
jitsu deploy
- Confirm any prompts (like approve an increment of the version number)
- Once the app starts I check out how my apps working on the server, make changes and so on
After I'm done, and my apps ready to go I undo my changes in my package.json file. I'd like to automate this process. I had the idea of doing so with a tiny node.js file. Here it is so far...
/*
* Use this file to deploy an app to the staging server on nodejitsu
*/
var bash = require('child_process').spawn('bash');
var colors = require('colors');
var fs = require('fs');
// stdout setup
bash.stdout.on('data', function (data) {
console.log('stdout: ' + data);
});
bash.stdout.on('error', function (err) {
console.log('stdout error: '.red, err);
});
// on bash exit
bash.on('exit', function (code) {
console.log('Exiting... ', code);
});
// grab package.json
var package = '';
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', 'rename-me-before-deploying.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;
bash.stdin.write('jitsu deploy\n'); // Deploy to staging app on nodejitsu.
setTimeout(function () { // this needs to be replaced
bash.stdin.write('yes\n');
}, 5000);
console.log("All done : )");
// bash.stdin.end(); // close out
});
});
I have a few issues here. I'm pretty sure all I need to know to complete it, is the event that fires when nodejitsu prompts me to increment the version number prompt: Is this ok?: (yes)
so that I can confirm, if that happens, and the event that fires when the whole process finishes so that I can revert the changes to my package.json file, leaving my app deployed to a staging environment and my files essentially untouched.