Advertisement
Guest User

Untitled

a guest
Sep 30th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. var gulp = require('gulp'),
  2. gutil = require('gulp-util'),
  3. vftp = require('vinyl-ftp');
  4.  
  5. var fconfig {
  6. host: "127.0.0.1",
  7. port: "21",
  8. user: "root",
  9. password: "top-secret-tacos",
  10. simultaneous_connections: 5,
  11. local_path: ".",
  12. remote_path: "/my_path/as_seen/in_ftp/",
  13. globs: {
  14. "/assets/src/**/*.*css",
  15. "/assets/src/**/*.js",
  16. "/assets/dist/**/*"
  17. }
  18. };
  19.  
  20. function getFtpConnection() {
  21. return vftp.create({
  22. host: fconfig.host,
  23. port: fconfig.port,
  24. user: fconfig.user,
  25. password: fconfig.pass,
  26. parallel: fconfig.simultaneous_connections,
  27. log: gutil.log
  28. });
  29. }
  30. gulp.task('deploy', function() {
  31. var conn = getFtpConnection();
  32. return gulp.src(fconfig.globs, { base: fconfig.local_path, buffer: false })
  33. .pipe( conn.newer( fconfig.remote_root ) ) // only upload newer files
  34. .pipe( conn.dest( fconfig.remote_root ) )
  35. ;
  36. });
  37. gulp.task('deploy-watch', function() {
  38. var conn = getFtpConnection();
  39.  
  40. gulp.watch(fconfig.globs)
  41. .on('change', function(event) {
  42. console.log('Changes detected! Uploading file "' + event.path + '", ' + event.type);
  43.  
  44. return gulp.src( [event.path], { base: fconfig.local_path, buffer: false } )
  45. .pipe( conn.newer( fconfig.remote_root ) ) // only upload newer files
  46. .pipe( conn.dest( fconfig.remote_root ) )
  47. ;
  48. });
  49. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement