Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var gulp = require('gulp');
- var plumber = require('gulp-plumber');
- var sftp = require('gulp-sftp');
- var sftpInfo = function () {
- var info = {
- host: '172.0.0.1',
- port: '0',
- user: 'secter_user_login',
- pass: 'password',
- remotePath: '/place/remote/path/here',
- };
- return info;
- }
- var settingProject = {
- folder: 'relative/path/on/localhost/',
- }
- var extractRelativePath = function (filePath) {
- // Remove file name at the end
- var folder = filePath.substring(0, filePath.lastIndexOf('/'));
- var splitedPath = folder.split(settingProject.folder);
- return splitedPath[1];
- }
- var SFTPSettings = function(changedFile) {
- var newSettings = sftpInfo();
- var newRemotePath = newSettings.remotePath + '/' + extractRelativePath(changedFile);
- newSettings.remotePath = newRemotePath.replace('//', '/');
- return newSettings;
- }
- gulp.task('upload', function () {
- return gulp.src(settingProject.folder + '/**/*')
- .pipe(plumber())
- .pipe(sftp(sftpInfo()));
- });
- gulp.task('default', function () {
- var watcher = gulp.watch(settingProject.folder + '/**/*', function () {});
- var uploader = function(properties) {
- return gulp.src(properties.path)
- .pipe(plumber())
- .pipe(sftp(SFTPSettings(properties.path)));
- }
- watcher.on('added', function (event) { return uploader(event); });
- watcher.on('change', function (event) { return uploader(event); });
- // The delete event will need implement in gulp-rsync. The gulp-sftp is working wrong with it.
- // watcher.on('deleted', function (event) { return uploader(event); });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement