diff --git a/README.md b/README.md index 5b1eafa..05f322b 100755 --- a/README.md +++ b/README.md @@ -1,15 +1,17 @@ # FTP-Sync extension for VS Code -This extension allows you to easily synchronise your local workspace (project files) with an FTP server. It also has several advanced features such as __automatic upload on save__. +This extension allows you to easily synchronise your local workspace (project files) with an FTP server. It also has several advanced features such as **automatic upload on save**. ![Demo of extension](https://i.imgur.com/W9h4pwW.gif) ## Usage + There are four commands available. You can access them from the command palette (Ctrl+Shift+P on Windows/Linux). You can also sync a single file by right-clicking on it in the left menu and using the "Ftp-sync: Upload File" and "Ftp-sync: Download File" commands. ### Ftp-sync: Init + Initializes a default FTP-Sync configuration file in the `.vscode` directory. Options can be customised as follows: - remotePath - This can be set to the path on the remote that you would like to upload to. The default is `./` i.e. the root. @@ -26,22 +28,23 @@ Initializes a default FTP-Sync configuration file in the `.vscode` directory. Op - agent - Specifies the ssh-agent to use for SFTP. The default is `null`. - allow - An array of escaped regular expression strings specifying paths which are allowed. If nonempty, unless a path matches any of these regular expressions it will not be included in the sync. Default value is empty, implying everything is allowed. - ignore - An array of escaped regular expression strings specifying paths to ignore. If a path matches any of these regular expressions then it will not be included in the sync. Default values are `"\\.git"`, `"\\.vscode"` and `".DS_Store"`. -- "generatedFiles": { - * "uploadOnSave": true, - * "path": "", [e.g.] "/build", - * "extensionsToInclude": [] e.g. [".js", ".styl"] -} +- generatedFiles: - Automatically upload freshly generated files. Also uploads files that are deleted. Path and extensionsToInclude have to be specified for this feature to work. + - path: "" - This specifies the path to the directory where the files are, [e.g.] "/build", + - extensionsToInclude: [""] e.g. [".js", ".css"] - Array of strings specifying what extensions to add for auto-upload. Default is "" which means that it will automatically upload files of all extensions. ### Ftp-sync: Sync Local to Remote + Displays a synchronization wizard to configure a sync operation that changes FTP files and folders to match project files. ### Ftp-sync: Sync Remote to Local + Displays a synchronization wizard to configure a sync operation that changes project files and folders to match FTP files. ### Ftp-sync: Commit + Commits reviewed list of changes made with Sync Local to Remote or Sync Remote to Local command. --------- +--- ## To be added soon: @@ -56,6 +59,7 @@ Commits reviewed list of changes made with Sync Local to Remote or Sync Remote t - Integration with git-ftp ### Found any bugs? Got any questions or ideas? + - Rise a ticket [here](https://github.com/lukasz-wronski/vscode-ftp-sync/issues)! - Contact me at vscode[at]lukaszwronski.pl @@ -65,84 +69,69 @@ I'm looking forward to get any feedback from extension users! Contribution, espe Great thanks for suggestions and help with debugging for [Martin](https://github.com/kasik96), [Allan](https://github.com/EthraZa), [Maxime](https://github.com/maximedupre), [suuuunto](https://github.com/suuuunto) and all other folks who reported bugs or made improvement requests. ------- +--- Use at your own risk - I do not guarantee that it will work correctly! ------- +--- ## Version history + - 0.3.7 - - Added [ Fix for broken uploadOnSave and subdirectories not adding properly](https://github.com/lukasz-wronski/vscode-ftp-sync/pull/264) + - Added [ Fix for broken uploadOnSave and subdirectories not adding properly](https://github.com/lukasz-wronski/vscode-ftp-sync/pull/264) - 0.3.5 - - Added [ Various enhancements (SCP Support, bug fixes, list command)](https://github.com/lukasz-wronski/vscode-ftp-sync/pull/237) - - Added [ List commands](https://github.com/lukasz-wronski/vscode-ftp-sync/pull/215) - - Added [ Fix for broken ignore and allow regex](https://github.com/lukasz-wronski/vscode-ftp-sync/pull/210) - - [ Introduced separate store to store syncOption](https://github.com/lukasz-wronski/vscode-ftp-sync/pull/200) - - Added [ Prompt for password if no password was given in config](https://github.com/lukasz-wronski/vscode-ftp-sync/pull/199) - - Added [ Fix for config secureOptions being ignored](https://github.com/lukasz-wronski/vscode-ftp-sync/pull/195) - - [ Implemented allow config](https://github.com/lukasz-wronski/vscode-ftp-sync/pull/170) - - Added [ Fix for incorrect path for ignore of remote sync](https://github.com/lukasz-wronski/vscode-ftp-sync/pull/163) - - Added [ Ability to download a single file using the context menu](https://github.com/lukasz-wronski/vscode-ftp-sync/pull/152) - - Added [ Rudimentary ssh-agent support](https://github.com/lukasz-wronski/vscode-ftp-sync/pull/134) + - Added [ Various enhancements (SCP Support, bug fixes, list command)](https://github.com/lukasz-wronski/vscode-ftp-sync/pull/237) + - Added [ List commands](https://github.com/lukasz-wronski/vscode-ftp-sync/pull/215) + - Added [ Fix for broken ignore and allow regex](https://github.com/lukasz-wronski/vscode-ftp-sync/pull/210) + - [ Introduced separate store to store syncOption](https://github.com/lukasz-wronski/vscode-ftp-sync/pull/200) + - Added [ Prompt for password if no password was given in config](https://github.com/lukasz-wronski/vscode-ftp-sync/pull/199) + - Added [ Fix for config secureOptions being ignored](https://github.com/lukasz-wronski/vscode-ftp-sync/pull/195) + - [ Implemented allow config](https://github.com/lukasz-wronski/vscode-ftp-sync/pull/170) + - Added [ Fix for incorrect path for ignore of remote sync](https://github.com/lukasz-wronski/vscode-ftp-sync/pull/163) + - Added [ Ability to download a single file using the context menu](https://github.com/lukasz-wronski/vscode-ftp-sync/pull/152) + - Added [ Rudimentary ssh-agent support](https://github.com/lukasz-wronski/vscode-ftp-sync/pull/134) - 0.3.3 - - Added [ Support for generated files](https://github.com/lukasz-wronski/vscode-ftp-sync/pull/118) + - Added [ Support for generated files](https://github.com/lukasz-wronski/vscode-ftp-sync/pull/118) - 0.3.2 - - Added [FTP over SSL support](https://github.com/lukasz-wronski/vscode-ftp-sync/pull/62) - - Added [Sync current file to Remote](https://github.com/lukasz-wronski/vscode-ftp-sync/pull/77) - - Fixed bug #86 (by PR #84) - - [Improved readme and fixed debug mode](https://github.com/lukasz-wronski/vscode-ftp-sync/pull/67) - - [Compatibility for vscode 1.5+](https://github.com/lukasz-wronski/vscode-ftp-sync/pull/87) - - [Improve Error handling around parsing config file](https://github.com/lukasz-wronski/vscode-ftp-sync/pull/102) + - Added [FTP over SSL support](https://github.com/lukasz-wronski/vscode-ftp-sync/pull/62) + - Added [Sync current file to Remote](https://github.com/lukasz-wronski/vscode-ftp-sync/pull/77) + - Fixed bug #86 (by PR #84) + - [Improved readme and fixed debug mode](https://github.com/lukasz-wronski/vscode-ftp-sync/pull/67) + - [Compatibility for vscode 1.5+](https://github.com/lukasz-wronski/vscode-ftp-sync/pull/87) + - [Improve Error handling around parsing config file](https://github.com/lukasz-wronski/vscode-ftp-sync/pull/102) - 0.3.1 - - Added [SFTP private key support](https://github.com/lukasz-wronski/vscode-ftp-sync/issues/28) + - Added [SFTP private key support](https://github.com/lukasz-wronski/vscode-ftp-sync/issues/28) - 0.3.0 - - Added [SFTP protocol support](https://github.com/lukasz-wronski/vscode-ftp-sync/issues/26) - - Improvement of sync performance in environments with many nested directories - - Fix for problems with upload on save on unsynced directories + - Added [SFTP protocol support](https://github.com/lukasz-wronski/vscode-ftp-sync/issues/26) + - Improvement of sync performance in environments with many nested directories + - Fix for problems with upload on save on unsynced directories - 0.2.9 - - Fix for [Running the contributed command:'extension.ftpsyncinit' failed](https://github.com/lukasz-wronski/vscode-ftp-sync/issues/3) - - Fix for [After some tryes the Review file stopped to work](https://github.com/lukasz-wronski/vscode-ftp-sync/issues/7) - - Added debug output option to config file - - Error message for incorrect JSON like in [this issue](https://github.com/lukasz-wronski/vscode-ftp-sync/issues/25) - - Closing review file after commit (pointed out in [this issue](https://github.com/lukasz-wronski/vscode-ftp-sync/issues/23)) - - Fix for [uploadOnSave will fail for files on new created folders](https://github.com/lukasz-wronski/vscode-ftp-sync/issues/22) - - Added ES6 support in extension source + - Fix for [Running the contributed command:'extension.ftpsyncinit' failed](https://github.com/lukasz-wronski/vscode-ftp-sync/issues/3) + - Fix for [After some tryes the Review file stopped to work](https://github.com/lukasz-wronski/vscode-ftp-sync/issues/7) + - Added debug output option to config file + - Error message for incorrect JSON like in [this issue](https://github.com/lukasz-wronski/vscode-ftp-sync/issues/25) + - Closing review file after commit (pointed out in [this issue](https://github.com/lukasz-wronski/vscode-ftp-sync/issues/23)) + - Fix for [uploadOnSave will fail for files on new created folders](https://github.com/lukasz-wronski/vscode-ftp-sync/issues/22) + - Added ES6 support in extension source - 0.2.8 - - Attempt to fix [uploadOnSave will fail for files on new created folders](https://github.com/lukasz-wronski/vscode-ftp-sync/issues/22) + - Attempt to fix [uploadOnSave will fail for files on new created folders](https://github.com/lukasz-wronski/vscode-ftp-sync/issues/22) - 0.2.7 - - Fix for [Sync R2L does not delete folder](https://github.com/lukasz-wronski/vscode-ftp-sync/issues/21) - - Replace of deprecated method `TextEditor.hide` with command call + - Fix for [Sync R2L does not delete folder](https://github.com/lukasz-wronski/vscode-ftp-sync/issues/21) + - Replace of deprecated method `TextEditor.hide` with command call - 0.2.6 - - Fix for [Error: EXDEV: cross-device link not permitted on mounted drive](https://github.com/lukasz-wronski/vscode-ftp-sync/issues/6) + - Fix for [Error: EXDEV: cross-device link not permitted on mounted drive](https://github.com/lukasz-wronski/vscode-ftp-sync/issues/6) - 0.2.5 - - Fix for [Local to remote "Full sync" error](https://github.com/lukasz-wronski/vscode-ftp-sync/issues/20) + - Fix for [Local to remote "Full sync" error](https://github.com/lukasz-wronski/vscode-ftp-sync/issues/20) - 0.2.4 - - Fix for [Duplicate folder in folder we upload to](https://github.com/lukasz-wronski/vscode-ftp-sync/issues/19) + - Fix for [Duplicate folder in folder we upload to](https://github.com/lukasz-wronski/vscode-ftp-sync/issues/19) - 0.2.3 - - Fix for [Cant download](https://github.com/lukasz-wronski/vscode-ftp-sync/issues/14) + - Fix for [Cant download](https://github.com/lukasz-wronski/vscode-ftp-sync/issues/14) - 0.2.2 - - Fix for [Upload on save don't track ignored files](https://github.com/lukasz-wronski/vscode-ftp-sync/issues/15) - - Added support for [ftp passive mode](https://github.com/lukasz-wronski/vscode-ftp-sync/issues/16) -- 0.2.1 - - Fix for [Save on second try](https://github.com/lukasz-wronski/vscode-ftp-sync/issues/12) -- 0.2.0 - - Rewritten sync mechanism - - Changes based on [this conversation](https://github.com/lukasz-wronski/vscode-ftp-sync/issues/2): - - New sync wizard - - Reviewing changes before save - - Choose to remove orphans or not (safe sync) - - Fix for [uncontrolled number of ftp connections](https://github.com/lukasz-wronski/vscode-ftp-sync/issues/4) -- 0.1.4 - - Fix for [No handler found for the command: 'extension.ftpsyncdownload'](https://github.com/lukasz-wronski/vscode-ftp-sync/issues/1) -- 0.1.2 - - Basic progress indication in sync process - - Better error handling in sync command - - Github links in package.json -- 0.1.1 - - All information messages moved to status bar - - Removed "alertOnSync" parameter from config - - Addedd progress indication in download process - - Fixes in download process -- 0.1.0 - - First version containing all basic features + - Fix for [Upload on save don't track ignored files](https://github.com/lukasz-wronski/vscode-ftp-sync/issues/15) + - Added support for [ftp passive mode](https://github.com/lukasz-wronski/vscode-ftp-sync/issues/16) +- 0.2.1 - Fix for [Save on second try](https://github.com/lukasz-wronski/vscode-ftp-sync/issues/12) +- 0.2.0 - Rewritten sync mechanism - Changes based on [this conversation](https://github.com/lukasz-wronski/vscode-ftp-sync/issues/2): - New sync wizard - Reviewing changes before save - Choose to remove orphans or not (safe sync) - Fix for [uncontrolled number of ftp connections](https://github.com/lukasz-wronski/vscode-ftp-sync/issues/4) +- 0.1.4 - Fix for [No handler found for the command: 'extension.ftpsyncdownload'](https://github.com/lukasz-wronski/vscode-ftp-sync/issues/1) +- 0.1.2 - Basic progress indication in sync process - Better error handling in sync command - Github links in package.json +- 0.1.1 - All information messages moved to status bar - Removed "alertOnSync" parameter from config - Addedd progress indication in download process - Fixes in download process +- 0.1.0 - First version containing all basic features diff --git a/extension.js b/extension.js index 573419d..3b91e91 100644 --- a/extension.js +++ b/extension.js @@ -1,75 +1,112 @@ // The module 'vscode' contains the VS Code extensibility API // Import the module and reference it with the alias vscode in your code below -var vscode = require('vscode') +var vscode = require("vscode"); global.STATUS_TIMEOUT = 3000; // this method is called when your extension is activated // your extension is activated the very first time the command is executed function activate(context) { + var syncHelper, currentConfig; + var ftpConfig = require("./modules/ftp-config"); + var getSyncHelper = function() { + var oldConfig = currentConfig; + currentConfig = ftpConfig.getSyncConfig(); - var syncHelper, currentConfig; - var ftpConfig = require('./modules/ftp-config'); - var getSyncHelper = function() { - var oldConfig = currentConfig; - currentConfig = ftpConfig.getSyncConfig(); + if (!syncHelper) syncHelper = require("./modules/sync-helper")(); + else if (ftpConfig.connectionChanged(oldConfig)) syncHelper.disconnect(); - if(!syncHelper) - syncHelper = require('./modules/sync-helper')(); - else if(ftpConfig.connectionChanged(oldConfig)) - syncHelper.disconnect(); + syncHelper.useConfig(currentConfig); - syncHelper.useConfig(currentConfig) + return syncHelper; + }; - return syncHelper; - } + var initCommand = vscode.commands.registerCommand( + "extension.ftpsyncinit", + require("./modules/init-command") + ); + var syncCommand = vscode.commands.registerCommand( + "extension.ftpsyncupload", + function() { + require("./modules/sync-command")(true, getSyncHelper); + } + ); + var downloadCommand = vscode.commands.registerCommand( + "extension.ftpsyncdownload", + function() { + require("./modules/sync-command")(false, getSyncHelper); + } + ); + var commitCommand = vscode.commands.registerCommand( + "extension.ftpsynccommit", + function() { + require("./modules/commit-command")(getSyncHelper); + } + ); + var singleCommand = vscode.commands.registerTextEditorCommand( + "extension.ftpsyncsingle", + function(editor) { + require("./modules/sync-single-command")(editor, getSyncHelper); + } + ); + var uploadcurrentCommand = vscode.commands.registerCommand( + "extension.ftpsyncuploadselected", + function(fileUrl) { + require("./modules/uploadcurrent-command")(fileUrl, getSyncHelper); + } + ); + var downloadcurrentCommand = vscode.commands.registerCommand( + "extension.ftpsyncdownloadselected", + function(fileUrl) { + require("./modules/downloadcurrent-command")(fileUrl, getSyncHelper); + } + ); + var listcurrentCommand = vscode.commands.registerCommand( + "extension.ftpsynclistselected", + function(fileUrl) { + require("./modules/list-command")(fileUrl, getSyncHelper); + } + ); + var onSave = require("./modules/on-save"); + var onGenerate = require("./modules/on-generate"); - var initCommand = vscode.commands.registerCommand('extension.ftpsyncinit', require('./modules/init-command')); - var syncCommand = vscode.commands.registerCommand('extension.ftpsyncupload', function() { require('./modules/sync-command')(true, getSyncHelper) }); - var downloadCommand = vscode.commands.registerCommand('extension.ftpsyncdownload', function() { require('./modules/sync-command')(false, getSyncHelper) }); - var commitCommand = vscode.commands.registerCommand('extension.ftpsynccommit', function() { require('./modules/commit-command')(getSyncHelper) }); - var singleCommand = vscode.commands.registerTextEditorCommand('extension.ftpsyncsingle', function(editor) { require('./modules/sync-single-command')(editor, getSyncHelper) }); - var uploadcurrentCommand = vscode.commands.registerCommand("extension.ftpsyncuploadselected", function(fileUrl) { require('./modules/uploadcurrent-command')(fileUrl, getSyncHelper) }); - var downloadcurrentCommand = vscode.commands.registerCommand("extension.ftpsyncdownloadselected", function(fileUrl) { require('./modules/downloadcurrent-command')(fileUrl, getSyncHelper) }); - var listcurrentCommand = vscode.commands.registerCommand("extension.ftpsynclistselected", function(fileUrl) { require('./modules/list-command')(fileUrl, getSyncHelper) }); - var onSave = require('./modules/on-save'); + var currentConfig = getSyncHelper().getConfig(); + if (currentConfig.generatedFiles.uploadOnSave) { + fsw = vscode.workspace.createFileSystemWatcher( + currentConfig.getGeneratedDir() + "/**" + ); + // fsw.onDidChange(function(ev) { + // //an attempt to normalize onDidChange with onDidSaveTextDocument. + // ev['uri'] = {fsPath: ev.fsPath}; + // onSave(ev, getSyncHelper); + // }) + fsw.onDidCreate(function(ev) { + ev["uri"] = { fsPath: ev.fsPath }; + onGenerate(ev, getSyncHelper); + }); + fsw.onDidDelete(function(ev) { + ev["uri"] = { fsPath: ev.fsPath }; + onGenerate(ev, getSyncHelper); + }); + } - var currentConfig = getSyncHelper().getConfig(); - if (currentConfig.generatedFiles.uploadOnSave) { - fsw = vscode.workspace.createFileSystemWatcher( currentConfig.getGeneratedDir() + '/**'); - fsw.onDidChange(function(ev) { - //an attempt to normalize onDidChange with onDidSaveTextDocument. - ev['uri'] = {fsPath: ev.fsPath}; - onSave(ev, getSyncHelper); - }) - fsw.onDidCreate(function(ev) { - ev['uri'] = {fsPath: ev.fsPath}; - onSave(ev, getSyncHelper); - }) - fsw.onDidDelete(function(ev) { - ev['uri'] = {fsPath: ev.fsPath}; - onSave(ev, getSyncHelper); - }) - } - - vscode.workspace.onDidSaveTextDocument( function(file) { - onSave(file, getSyncHelper); - }); + vscode.workspace.onDidSaveTextDocument(function(file) { + onSave(file, getSyncHelper); + }); - - context.subscriptions.push(initCommand); - context.subscriptions.push(syncCommand); - context.subscriptions.push(downloadCommand); - context.subscriptions.push(commitCommand); - context.subscriptions.push(singleCommand); - context.subscriptions.push(uploadcurrentCommand); - context.subscriptions.push(downloadcurrentCommand); - context.subscriptions.push(listcurrentCommand); + context.subscriptions.push(initCommand); + context.subscriptions.push(syncCommand); + context.subscriptions.push(downloadCommand); + context.subscriptions.push(commitCommand); + context.subscriptions.push(singleCommand); + context.subscriptions.push(uploadcurrentCommand); + context.subscriptions.push(downloadcurrentCommand); + context.subscriptions.push(listcurrentCommand); } exports.activate = activate; function deactivate() { - fsw.dispose(); + fsw.dispose(); } exports.deactivate = deactivate; diff --git a/modules/ftp-config.js b/modules/ftp-config.js index bcb2191..b8a75b2 100644 --- a/modules/ftp-config.js +++ b/modules/ftp-config.js @@ -5,96 +5,102 @@ var _ = require("lodash"); var upath = require("upath"); module.exports = { - rootPath: function() { - return vscode.workspace.workspaceFolders[0].uri; - }, - getConfigPath: function() { - return this.getConfigDir() + "/ftp-sync.json"; - }, - getConfigDir: function() { - return this.rootPath().fsPath + "/.vscode"; - }, - getGeneratedDir: function() { - return upath.join(this.rootPath().fsPath, this.generatedFiles.path); - }, - defaultConfig: { - remotePath: "./", - host: "host", - username: "username", - password: "password", - port: 21, - secure: false, - protocol: "ftp", - uploadOnSave: false, - passive: false, - debug: false, - privateKeyPath: null, - passphrase: null, - agent: null, - allow: [], - ignore: ["\\.vscode", "\\.git", "\\.DS_Store"], - generatedFiles: { - uploadOnSave: false, - extensionsToInclude: [], - path: '' - } - }, - getConfig: function() { - var configjson = fs.readFileSync(this.getConfigPath()).toString(); - var configObject; + rootPath: function() { + return vscode.workspace.workspaceFolders[0].uri; + }, + getConfigPath: function() { + return this.getConfigDir() + "/ftp-sync.json"; + }, + getConfigDir: function() { + return this.rootPath().fsPath + "/.vscode"; + }, + getGeneratedDir: function() { + return upath.join(this.rootPath().fsPath, this.generatedFiles.path); + }, + defaultConfig: { + remotePath: "./", + host: "host", + username: "username", + password: "password", + port: 21, + secure: false, + protocol: "ftp", + uploadOnSave: false, + passive: false, + debug: false, + privateKeyPath: null, + passphrase: null, + agent: null, + allow: [], + ignore: ["\\.vscode", "\\.git", "\\.DS_Store"], + generatedFiles: { + extensionsToInclude: [""], + path: "" + } + }, + getConfig: function() { + var configjson = fs.readFileSync(this.getConfigPath()).toString(); + var configObject; - try { - configObject = JSON.parse(configjson); - } - catch (err){ - vscode.window.showErrorMessage("Ftp-sync: Config file is not a valid JSON document. - " + err.message); - } - return _.defaults(configObject, this.defaultConfig); - }, - validateConfig: function() { - if(!fs.existsSync(this.getConfigPath())) { - var options = ["Create ftp-sync config now...", "Nah, forget about it..."]; - var pick = vscode.window.showQuickPick(options, { placeHolder: "No configuration file found. Run Init command first." }); - pick.then( function(answer) { - if(answer == options[0]) - require("./init-command")(); - }) - return false; - } + try { + configObject = JSON.parse(configjson); + } catch (err) { + vscode.window.showErrorMessage( + "Ftp-sync: Config file is not a valid JSON document. - " + err.message + ); + } + return _.defaults(configObject, this.defaultConfig); + }, + validateConfig: function() { + if (!fs.existsSync(this.getConfigPath())) { + var options = [ + "Create ftp-sync config now...", + "Nah, forget about it..." + ]; + var pick = vscode.window.showQuickPick(options, { + placeHolder: "No configuration file found. Run Init command first." + }); + pick.then(function(answer) { + if (answer == options[0]) require("./init-command")(); + }); + return false; + } - return true; - }, - getSyncConfig: function() { - let config = this.getConfig(); - return { - getGeneratedDir: this.getGeneratedDir, - local: config.localPath, - root: config.rootPath, - remote: upath.toUnix(config.remotePath), - host: config.host, - port: config.port, - user: config.username, - password: config.password, - passphrase: config.passphrase, - allow: config.allow, - ignore: config.ignore, - passive: config.passive, - secure: config.secure, - secureOptions: config.secureOptions, - protocol: config.protocol || "ftp", - privateKeyPath: config.privateKeyPath, - passphrase: config.passphrase, - agent: config.agent, - generatedFiles: config.generatedFiles, - debug: config.debug, - rootPath: this.rootPath - } - }, - connectionChanged: function(oldConfig) { - var config = this.getSyncConfig(); - return config.host != oldConfig.host - || config.port != oldConfig.port - || config.user != oldConfig.user - || config.password != oldConfig.password; - } -} + return true; + }, + getSyncConfig: function() { + let config = this.getConfig(); + return { + getGeneratedDir: this.getGeneratedDir, + local: config.localPath, + root: config.rootPath, + remote: upath.toUnix(config.remotePath), + host: config.host, + port: config.port, + user: config.username, + password: config.password, + passphrase: config.passphrase, + allow: config.allow, + ignore: config.ignore, + passive: config.passive, + secure: config.secure, + secureOptions: config.secureOptions, + protocol: config.protocol || "ftp", + privateKeyPath: config.privateKeyPath, + passphrase: config.passphrase, + agent: config.agent, + generatedFiles: config.generatedFiles, + debug: config.debug, + rootPath: this.rootPath + }; + }, + connectionChanged: function(oldConfig) { + var config = this.getSyncConfig(); + return ( + config.host != oldConfig.host || + config.port != oldConfig.port || + config.user != oldConfig.user || + config.password != oldConfig.password + ); + } +}; diff --git a/modules/on-generate.js b/modules/on-generate.js new file mode 100644 index 0000000..62d0b9d --- /dev/null +++ b/modules/on-generate.js @@ -0,0 +1,63 @@ +/* global STATUS_TIMEOUT */ +var vscode = require("vscode"); +var ftpconfig = require("./ftp-config"); +var path = require("path"); +var isIgnored = require("./is-ignored"); +var upath = require("upath"); + +module.exports = function(document, getFtpSync, skipOnSaveCheck) { + if (document.uri.fsPath.indexOf(ftpconfig.rootPath().fsPath) < 0) return; + + var config = ftpconfig.getConfig(); + + //Should we bother to check for generated file uploads? (also check if the generated files path is set otherwise skip) + if ( + config.generatedFiles.extensionsToInclude.length > 0 && + config.generatedFiles.path != "" + ) { + //If it's not an auto uploaded generated file it won't start with that directory + if ( + !upath.normalize(path.dirname(document.uri.fsPath)).startsWith( + getFtpSync() + .getConfig() + .getGeneratedDir() + ) + ) + return; + //It's an auto upload generated file + else { + //Let's see if it's an extension we will be supporting! + var extensionCheck = config.generatedFiles.extensionsToInclude.some( + function(str) { + return document.uri.fsPath.endsWith(str); + } + ); + + if (!extensionCheck) return; + } + } + + if (isIgnored(document.uri.fsPath, config.allow, config.ignore)) return; + + var fileName = path.basename(document.uri.fsPath); + var uploadingStatus = vscode.window.setStatusBarMessage( + "Ftp-sync: Uploading " + fileName + " to FTP server..." + ); + + getFtpSync().uploadFile( + document.uri.fsPath, + ftpconfig.rootPath().fsPath, + function(err) { + uploadingStatus.dispose(); + if (err) + vscode.window.showErrorMessage( + "Ftp-sync: Uploading " + fileName + " failed: " + err + ); + else + vscode.window.setStatusBarMessage( + "Ftp-sync: " + fileName + " uploaded successfully!", + STATUS_TIMEOUT + ); + } + ); +}; diff --git a/modules/on-save.js b/modules/on-save.js index 666257d..b4cb262 100644 --- a/modules/on-save.js +++ b/modules/on-save.js @@ -6,47 +6,34 @@ var isIgnored = require("./is-ignored"); var upath = require("upath"); module.exports = function(document, getFtpSync, skipOnSaveCheck) { - - if(document.uri.fsPath.indexOf(ftpconfig.rootPath().fsPath) < 0) - return; - - var config = ftpconfig.getConfig(); - - //Should we bother to check for generated file uploads? (also check if the generated files path is set otherwise skip) - if (config.generatedFiles.uploadOnSave && (config.generatedFiles.path != "")) { - //If it's not an auto uploaded generated file it won't start with that directory - if (!upath.normalize(path.dirname(document.uri.fsPath)).startsWith( getFtpSync().getConfig().getGeneratedDir()) ) { - //Don't upload it! - if(!config.uploadOnSave && !skipOnSaveCheck) - return; - } - //It's an auto upload generated file - else { - //Let's see if it's an extension we will be supporting! - if (!config.generatedFiles.extensionsToInclude.some(function(str) { - return document.uri.fsPath.endsWith(str); - })) - return; - } - } - //We don't care about generated file uploads, let's see if it's a candidate for upload anyway. - else { - if(!config.uploadOnSave && !skipOnSaveCheck) - return; - } - - if(isIgnored(document.uri.fsPath, config.allow, config.ignore)) return; - - var fileName = path.basename(document.uri.fsPath); - var uploadingStatus = vscode.window.setStatusBarMessage("Ftp-sync: Uploading " + fileName + " to FTP server..."); - - getFtpSync().uploadFile(document.uri.fsPath, ftpconfig.rootPath().fsPath, function(err) { - uploadingStatus.dispose(); - if(err) - vscode.window.showErrorMessage("Ftp-sync: Uploading " + fileName + " failed: " + err); - else - vscode.window.setStatusBarMessage("Ftp-sync: " + fileName + " uploaded successfully!", STATUS_TIMEOUT); - }) - - -} \ No newline at end of file + if (document.uri.fsPath.indexOf(ftpconfig.rootPath().fsPath) < 0) return; + + var config = ftpconfig.getConfig(); + + //We don't care about generated file uploads, let's see if it's a candidate for upload anyway. + if (!config.uploadOnSave && !skipOnSaveCheck) return; + + if (isIgnored(document.uri.fsPath, config.allow, config.ignore)) return; + + var fileName = path.basename(document.uri.fsPath); + var uploadingStatus = vscode.window.setStatusBarMessage( + "Ftp-sync: Uploading " + fileName + " to FTP server..." + ); + + getFtpSync().uploadFile( + document.uri.fsPath, + ftpconfig.rootPath().fsPath, + function(err) { + uploadingStatus.dispose(); + if (err) + vscode.window.showErrorMessage( + "Ftp-sync: Uploading " + fileName + " failed: " + err + ); + else + vscode.window.setStatusBarMessage( + "Ftp-sync: " + fileName + " uploaded successfully!", + STATUS_TIMEOUT + ); + } + ); +}; diff --git a/package-lock.json b/package-lock.json index 00fc6d0..6f3c9a7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "ftp-sync", - "version": "0.3.6", + "version": "0.3.8", "lockfileVersion": 1, "requires": true, "dependencies": {