Guest User

Untitled

a guest
Dec 31st, 2017
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. /**
  2. - Config sample :
  3. {
  4. "login": "xxx",
  5. "password": "xxx",
  6. "port": 22,
  7. "host": "miaow.com",
  8. "currentMask": "/var/www/*",
  9. "dest": "/var/www/",
  10. "build": "build/es5-bundled"
  11. }
  12. */
  13. const SSH = require('simple-ssh');
  14. const client = require('scp2');
  15. const fs = require('fs');
  16. const configPath = './config.json';
  17. const colors = require('colors');
  18. const prompt = require('prompt');
  19. const { exec } = require('child_process');
  20.  
  21. let config = JSON.parse(fs.readFileSync(configPath));
  22.  
  23. let ssh = new SSH({
  24. host: config.host,
  25. user: config.login,
  26. pass: config.password,
  27. port: config.port
  28. });
  29.  
  30. console.log("\nGoing to deploy : " + config.build.red + " in " + config.dest.green + " on " + config.host.green);
  31. console.log("\nAre you ready ?");
  32.  
  33. prompt.start();
  34. prompt.get(['y/n'], function (err, result) {
  35. if(result !== undefined && result['y/n'] == 'y'){
  36. deploy();
  37. } else {
  38. console.log("\nErf. :'(");
  39. return;
  40. }
  41. });
  42.  
  43. function deploy(){
  44. console.log("\nremove current build".red);
  45. ssh.exec('rm -rf '+config.currentMask, { out: function(stdout) {
  46. console.log("files removed".underline.red);
  47. } }).start();
  48.  
  49. console.log("\nsending new build".green);
  50.  
  51. client.scp(__dirname + "/../" + config.build, {
  52. host: config.host,
  53. username: config.login,
  54. password: config.password,
  55. path: config.dest,
  56. port: config.port
  57. }, function(err) {
  58. if(err === undefined){
  59. console.log(`\ndeploy done \\o/`.rainbow);
  60. exec('git tag -f deployed', (error, stdout, stderr) => {
  61. if (error) {
  62. throw error;
  63. }
  64. console.log(stdout)
  65. });
  66. exec('git push origin master -f --tags', (error, stdout, stderr) => {
  67. if (error) {
  68. throw error;
  69. }
  70. console.log(stdout)
  71. });
  72. } else {
  73. console.log(err);
  74. }
  75. });
  76. }
Add Comment
Please, Sign In to add comment