Skip to content

Instantly share code, notes, and snippets.

@dshook
Last active August 29, 2015 14:15
Show Gist options
  • Save dshook/ec1ed0789705e0aabb84 to your computer and use it in GitHub Desktop.
Save dshook/ec1ed0789705e0aabb84 to your computer and use it in GitHub Desktop.
Deploy Ghost Script
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