Advertisement
Guest User

Untitled

a guest
Jun 14th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. 'use strict';
  2.  
  3. /**
  4. * Simple deployment script.
  5. *
  6. * Run it through:
  7. * $ npm run deploy
  8. *
  9. * Note that the script will add all files to remote server without doing diffs
  10. * or anything. It behaves pretty much like rsync.
  11. *
  12. * It accepts file ignoring through wildcards, which might come in handy:
  13. * $ npm run deploy -- -i '*.jpg' # Do not deploy .jpg files
  14. **/
  15.  
  16. const argv = require('yargs').alias('i', 'ignore').argv;
  17. const figures = require('figures');
  18. const chalk = require('chalk');
  19. const logUpdate = require('log-update');
  20. const FTPDeploy = require('ftp-deploy');
  21. const deployer = new FTPDeploy();
  22. const options = require('../options.json');
  23. const ignore = argv.ignore ? argv.ignore.split(',') : [];
  24.  
  25. let settings = {
  26. username: options.credentials.username,
  27. password: options.credentials.password,
  28. host: options.host,
  29. port: 21,
  30. localRoot: options.localFolder,
  31. remoteRoot: options.remoteFolder,
  32. continueOnError: true,
  33. exclude: ['.git', '.keep', '.DS_Store'].concat(ignore)
  34. };
  35.  
  36. let log = {};
  37. let interval = 0;
  38. let hasStarted = false;
  39.  
  40. // Start deployment
  41. const start = () => {
  42. hasStarted = true;
  43.  
  44. prompt('Deploy started');
  45.  
  46. // Freezes `stdout` and update log with deploy information
  47. interval = setInterval(() => {
  48. logUpdate(`${chalk.green(figures.pointer)} Uploaded ${chalk.bold(log.transferredFileCount)} of ${chalk.bold(log.totalFileCount)} files (${log.percentComplete}% complete)
  49. ${chalk.underline(log.filename)}`);
  50. }, 250);
  51. };
  52.  
  53. // Helper to prompt a fancy message to `stdout`
  54. const prompt = message => {
  55. console.log(`${chalk.green(figures.pointer)} ${message}`);
  56. };
  57.  
  58. prompt('Connecting to server...');
  59.  
  60. deployer.deploy(settings, error => {
  61. // Failure
  62. if(error) throw error;
  63.  
  64. // Success
  65. clearInterval(interval);
  66. prompt(`Successfully deployed ${figures.tick}`);
  67. });
  68.  
  69. deployer.on('uploading', data => {
  70. if(!hasStarted) start();
  71.  
  72. // Save data to a local variable so we can easily use it w/ logUpdate
  73. log = data;
  74. });
  75.  
  76. // Notifies bad upload
  77. deployer.on('upload-error', data => {
  78. console.error(`${chalk.red(figures.warning)} Problem uploading file "${data.filename}"`);
  79. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement