From 14603732de56572bd48f69ca7e903b7e92ef6289 Mon Sep 17 00:00:00 2001 From: Tyler Funk Date: Thu, 18 May 2017 15:43:51 -0500 Subject: [PATCH 1/4] added removal functionality? --- index.js | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 32ad676..0e2bba4 100644 --- a/index.js +++ b/index.js @@ -237,7 +237,20 @@ GulpSSH.prototype.dest = function (destDir, options) { return through.obj(function (file, encoding, callback) { if (file.isNull()) { - gutil.log('"' + gutil.colors.cyan(file.path) + '" has no content. Skipping.') + gutil.log('"' + gutil.colors.cyan(file.path) + '" has no content. Attempting delete.') + getSftp(function (err, sftp) { + if (err) return end(err, callback) + var baseRegexp = new RegExp('^' + file.base.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&')) + var outPath = path.join(destDir, file.path.replace(baseRegexp, '')).replace(/\\/g, '/') + gutil.log('Preparing to delete "' + gutil.colors.red(outPath) + '"') + + internalRemove(sftp, outPath, function(err) { + if (err) return end(err, callback) + g + }) + + }) + return callback() } getSftp(function (err, sftp) { @@ -319,6 +332,15 @@ GulpSSH.prototype.shell = function (commands, options) { return outStream } +// function internalRemove(sftp, filePath, callback) { +function internalRemove(sftp, filePath) { + sftp.exists(filePath, function(result) { + if (!result) return + gutil.log('Deleting \'' + gutils.colors.red(filePath) + '\'') + sftp.remove(filePath); + }) +} + function internalMkDirs (sftp, filePath, callback) { var outPathDir = path.dirname(filePath).replace(/\\/g, '/') From c61850ce8267ac3d50f310e345d37e73fe007e19 Mon Sep 17 00:00:00 2001 From: Tyler Funk Date: Thu, 18 May 2017 15:46:16 -0500 Subject: [PATCH 2/4] fix gutils -> gutil --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 0e2bba4..0f9c519 100644 --- a/index.js +++ b/index.js @@ -336,7 +336,7 @@ GulpSSH.prototype.shell = function (commands, options) { function internalRemove(sftp, filePath) { sftp.exists(filePath, function(result) { if (!result) return - gutil.log('Deleting \'' + gutils.colors.red(filePath) + '\'') + gutil.log('Deleting \'' + gutil.colors.red(filePath) + '\'') sftp.remove(filePath); }) } From 8831902bd821d35e5a6a28a55b481a18d2e8511c Mon Sep 17 00:00:00 2001 From: Tyler Funk Date: Thu, 18 May 2017 15:53:19 -0500 Subject: [PATCH 3/4] changed remove to unlink --- index.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 0f9c519..b514c54 100644 --- a/index.js +++ b/index.js @@ -246,7 +246,6 @@ GulpSSH.prototype.dest = function (destDir, options) { internalRemove(sftp, outPath, function(err) { if (err) return end(err, callback) - g }) }) @@ -333,11 +332,11 @@ GulpSSH.prototype.shell = function (commands, options) { } // function internalRemove(sftp, filePath, callback) { -function internalRemove(sftp, filePath) { +function internalRemove(sftp, filePath, callback) { sftp.exists(filePath, function(result) { if (!result) return gutil.log('Deleting \'' + gutil.colors.red(filePath) + '\'') - sftp.remove(filePath); + sftp.unlink(filePath, callback) }) } From 72484b5229748a2e62797ca0d6069e6cf5a6e87f Mon Sep 17 00:00:00 2001 From: Tyler Funk Date: Tue, 5 Dec 2017 10:56:50 -0600 Subject: [PATCH 4/4] add option for remoteDelete; disabled by default --- README.md | 12 ++++++++++++ index.js | 26 +++++++++++++++----------- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index b42d95d..a0f0bb6 100644 --- a/README.md +++ b/README.md @@ -166,6 +166,18 @@ Type: `Object` return `stream`, copy the files to remote through sftp, acts similarly to Gulp dest, will make dirs if not exist. +#### options + +*Option* +Type: `Object` + +#### options.deleteRemote + +*Option* +Type: `Boolean` + +should gulp-ssh delete remote files when they are deleted locally + ## License MIT © [Teambition](https://www.teambition.com) diff --git a/index.js b/index.js index b514c54..fbdfa09 100644 --- a/index.js +++ b/index.js @@ -214,6 +214,8 @@ GulpSSH.prototype.dest = function (destDir, options) { options = options || {} options.autoClose = false + var deleteRemote = options.deleteRemote || false + function getSftp (callback) { if (sftpClient) return callback(null, sftpClient) ssh.gulpReady(function () { @@ -237,19 +239,21 @@ GulpSSH.prototype.dest = function (destDir, options) { return through.obj(function (file, encoding, callback) { if (file.isNull()) { - gutil.log('"' + gutil.colors.cyan(file.path) + '" has no content. Attempting delete.') - getSftp(function (err, sftp) { - if (err) return end(err, callback) - var baseRegexp = new RegExp('^' + file.base.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&')) - var outPath = path.join(destDir, file.path.replace(baseRegexp, '')).replace(/\\/g, '/') - gutil.log('Preparing to delete "' + gutil.colors.red(outPath) + '"') - - internalRemove(sftp, outPath, function(err) { + if (deleteRemote) { + gutil.log('"' + gutil.colors.cyan(file.path) + '" has no content. Attempting delete.') + getSftp(function (err, sftp) { if (err) return end(err, callback) - }) - - }) + var baseRegexp = new RegExp('^' + file.base.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&')) + var outPath = path.join(destDir, file.path.replace(baseRegexp, '')).replace(/\\/g, '/') + gutil.log('Preparing to delete "' + gutil.colors.red(outPath) + '"') + internalRemove(sftp, outPath, function (err) { + if (err) return end(err, callback) + }) + }) + } else { + gutil.log('"' + gutil.colors.cyan(file.path) + '" has no content. Skipping.') + } return callback() } getSftp(function (err, sftp) {