Advertisement
Guest User

Untitled

a guest
Mar 4th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. var gulp = require('gulp');
  2. var plumber = require('gulp-plumber');
  3. var sftp = require('gulp-sftp');
  4.  
  5. var sftpInfo = function () {
  6. var info = {
  7. host: '172.0.0.1',
  8. port: '0',
  9. user: 'secter_user_login',
  10. pass: 'password',
  11. remotePath: '/place/remote/path/here',
  12. };
  13.  
  14. return info;
  15. }
  16.  
  17. var settingProject = {
  18. folder: 'relative/path/on/localhost/',
  19. }
  20.  
  21. var extractRelativePath = function (filePath) {
  22. // Remove file name at the end
  23. var folder = filePath.substring(0, filePath.lastIndexOf('/'));
  24. var splitedPath = folder.split(settingProject.folder);
  25. return splitedPath[1];
  26. }
  27.  
  28. var SFTPSettings = function(changedFile) {
  29. var newSettings = sftpInfo();
  30. var newRemotePath = newSettings.remotePath + '/' + extractRelativePath(changedFile);
  31. newSettings.remotePath = newRemotePath.replace('//', '/');
  32. return newSettings;
  33. }
  34.  
  35. gulp.task('upload', function () {
  36. return gulp.src(settingProject.folder + '/**/*')
  37. .pipe(plumber())
  38. .pipe(sftp(sftpInfo()));
  39. });
  40.  
  41. gulp.task('default', function () {
  42. var watcher = gulp.watch(settingProject.folder + '/**/*', function () {});
  43. var uploader = function(properties) {
  44. return gulp.src(properties.path)
  45. .pipe(plumber())
  46. .pipe(sftp(SFTPSettings(properties.path)));
  47. }
  48.  
  49. watcher.on('added', function (event) { return uploader(event); });
  50. watcher.on('change', function (event) { return uploader(event); });
  51. // The delete event will need implement in gulp-rsync. The gulp-sftp is working wrong with it.
  52. // watcher.on('deleted', function (event) { return uploader(event); });
  53. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement