Skip to content

Instantly share code, notes, and snippets.

@m1m1s1ku
Last active December 26, 2017 16:59
Show Gist options
  • Save m1m1s1ku/bbded6ba61aa4971959451ebe410e9af to your computer and use it in GitHub Desktop.
Save m1m1s1ku/bbded6ba61aa4971959451ebe410e9af to your computer and use it in GitHub Desktop.
NodeDeploy
/**
- Config sample :
{
"login": "xxx",
"password": "xxx",
"port": 22,
"host": "miaow.com",
"currentMask": "/var/www/*",
"dest": "/var/www/",
"build": "build/es5-bundled"
}
*/
const SSH = require('simple-ssh');
const client = require('scp2');
const fs = require('fs');
const configPath = './config.json';
const colors = require('colors');
const prompt = require('prompt');
const { exec } = require('child_process');
let config = JSON.parse(fs.readFileSync(configPath));
let ssh = new SSH({
host: config.host,
user: config.login,
pass: config.password,
port: config.port
});
console.log("\nGoing to deploy : " + config.build.red + " in " + config.dest.green + " on " + config.host.green);
console.log("\nAre you ready ?");
prompt.start();
prompt.get(['y/n'], function (err, result) {
if(result !== undefined && result['y/n'] == 'y'){
deploy();
} else {
console.log("\nErf. :'(");
return;
}
});
function deploy(){
console.log("\nremove current build".red);
ssh.exec('rm -rf '+config.currentMask, { out: function(stdout) {
console.log("files removed".underline.red);
} }).start();
console.log("\nsending new build".green);
client.scp(__dirname + "/../" + config.build, {
host: config.host,
username: config.login,
password: config.password,
path: config.dest,
port: config.port
}, function(err) {
if(err === undefined){
console.log(`\ndeploy done \\o/`.rainbow);
exec('git tag -f deployed', (error, stdout, stderr) => {
if (error) {
throw error;
}
console.log(stdout)
});
exec('git push origin master -f --tags', (error, stdout, stderr) => {
if (error) {
throw error;
}
console.log(stdout)
});
} else {
console.log(err);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment