Last active
August 29, 2015 14:15
-
-
Save dshook/ec1ed0789705e0aabb84 to your computer and use it in GitHub Desktop.
Deploy Ghost Script
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
var shell = Promise.promisifyAll(require('shelljs')); | |
module.exports = function deploy(req, res){ | |
shell.execAsync('git remote update') | |
.then(function(output){ | |
res.write(output.toString()); | |
}) | |
.then(function(){ | |
return shell.execAsync('git status -uno'); | |
}) | |
.then(function(output){ | |
res.write(output.toString()); | |
if(output.indexOf('behind') > -1){ | |
return shell.execAsync('npm install') | |
.then(function(){ | |
return shell.execAsync('git reset --hard origin/HEAD'); | |
}) | |
.then(function(){ | |
return shell.execAsync('pm2 restart ghost'); | |
}) | |
.then(function(){ | |
res.write('Deployed'); | |
}); | |
} | |
}) | |
.catch(function(e){ | |
res.write(e.toString()); | |
}).then(function(){ | |
res.end(); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment