diff --git a/.babelrc b/.babelrc index e7b1998..4b4ffb0 100644 --- a/.babelrc +++ b/.babelrc @@ -1,3 +1,3 @@ { - "presets": ["es2015-node4"] + "presets": ["es2015-node4", "stage-0"] } diff --git a/README.md b/README.md index 4dfb91d..bc11a20 100644 --- a/README.md +++ b/README.md @@ -116,6 +116,14 @@ The location on your remote machine you wish to apply changes to. An array of file(s) or filepath(s) that, when matched, sicksync will ignore and not send changes. Editor configuration and `.git/*` files are generally ok to ignore. Uses [`anymatch`](https://github.com/es128/anymatch) for globbing. +`disableDeletion: {boolean}` + +When true, this will prevent `sicksync` from deleting files on the server. Defaults to `false`. It can also be switched with the command-line switch `-D` or `--disable-deletion` + +`disableRsync: {boolean}` + +When true, this will prevent `sicksync` from doing rsync for any big file changes. (default: false) (command-line switch: `-R`, or `--disable-rsync`) + `websocketPort: {number}` The port number which you want BOTH the local and remote machines to use for websocket-syncing. diff --git a/package.json b/package.json index 14d7d4c..e68177d 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,7 @@ "babel-cli": "^6.18.0", "babel-core": "^6.18.0", "babel-preset-es2015-node4": "^2.1.0", + "babel-preset-stage-0": "^6.22.0", "babel-register": "^6.18.0", "chai": "^3.2.0", "coveralls": "^2.11.14", diff --git a/src/big-sync.js b/src/big-sync.js index 7533045..e7e00f8 100644 --- a/src/big-sync.js +++ b/src/big-sync.js @@ -30,8 +30,8 @@ export function bigSync(project) { .source(ensureTrailingSlash(project.sourceLocation)) .destination(project.username + '@' + project.hostname + ':' + project.destinationLocation); - if (params.delete === true) { - rsync.set('delete') + if (!(params.disableDeletion || project.disableDeletion)) { + rsync.set('delete'); } if (params.dry) { @@ -43,5 +43,11 @@ export function bigSync(project) { rsync.output(consoleLogFromBuffer, consoleLogFromBuffer); } - rsync.execute(onComplete); + return new Promise((resolve, reject) => { + rsync.execute((err, ...result) => { + onComplete(err, ...result); + if (err) reject(err); + else resolve(...result); + }); + }); } diff --git a/src/commands/start.js b/src/commands/start.js index c58f39b..dd7447b 100644 --- a/src/commands/start.js +++ b/src/commands/start.js @@ -5,9 +5,10 @@ function sicksyncStartCommand(program, config) { program .command('start [projects...]') .description('Starts the continuous sicksync process for the given project(s)') - .option('-D, --no-delete', 'Do not delete remote files on inital rsync') + .option('-D, --disable-deletion', 'Do not delete files on the server') + .option('-R, --disable-rsync', 'Do not do rsync on bigger file changes') .action((projects, options) => - start(_.extend(config, _.pick(options, ['delete'])), projects)) + start(_.extend(config, _.pick(options, ['disableDeletion', 'disableRsync'])), projects)); } export default sicksyncStartCommand; diff --git a/src/local/index.js b/src/local/index.js index 9b40f4c..b08125b 100644 --- a/src/local/index.js +++ b/src/local/index.js @@ -26,15 +26,16 @@ const hostname = os.hostname(); const wsEvents = eventsConf.WS.LOCAL; const fsEvents = eventsConf.FS.LOCAL; -function triggerBigSync(project, params, cb) { - bigSync({ +function triggerBigSync(project, params) { + return bigSync({ project: project.project, excludes: project.excludes, sourceLocation: ensureTrailingSlash(project.sourceLocation), destinationLocation: ensureTrailingSlash(project.destinationLocation), hostname: project.hostname, username: project.username, - }, params, cb); + disableDeletion: project.disableDeletion, + }, params); } export function start(config, projects) { @@ -79,16 +80,16 @@ function startProject(config, projectConf) { }); // WS events - wsClient.on(wsEvents.READY, () => { - triggerBigSync(projectConf, _.pick(config, ['debug', 'delete']), () => { - fsHelper.watch(); - - localLog( - text.SYNC_ON_CONNECT, - projectConf.hostname, (projectConf.prefersEncrypted) ? 'using' : 'not using', - 'encryption' - ); - }); + wsClient.on(wsEvents.READY, async () => { + if (!(config.disableRsync || projectConf.disableRsync)) { + await triggerBigSync(projectConf, _.pick(config, ['debug', 'delete'])); + } + fsHelper.watch(); + localLog( + text.SYNC_ON_CONNECT, + projectConf.hostname, (projectConf.prefersEncrypted) ? 'using' : 'not using', + 'encryption' + ); }); wsClient.on(wsEvents.RECONNECTING, _.partial(_.ary(localLog, 1), text.SYNC_ON_RECONNECT)); @@ -121,14 +122,14 @@ function startProject(config, projectConf) { wsClient.send(fileChange); }); - fsHelper.on(fsEvents.LARGE, () => { + fsHelper.on(fsEvents.LARGE, async () => { localLog(text.SYNC_ON_LARGE_CHANGE); fsHelper.pauseWatch(); - - triggerBigSync(projectConf, { debug: config.debug }, () => { - localLog(text.SYNC_ON_LARGE_CHANGE_DONE); - fsHelper.watch(); - }); + if (!(config.disableRsync || projectConf.disableRsync)) { + await triggerBigSync(projectConf, { debug: config.debug }); + } + localLog(text.SYNC_ON_LARGE_CHANGE_DONE); + fsHelper.watch(); }); } @@ -139,15 +140,18 @@ export function once(config, projects, opts) { return logProjectsNotFound(foundProjects); } - _.each(foundProjects, (project) => { + _.each(foundProjects, async (project) => { const localLog = generateLog(project.project, hostname); localLog(text.SYNC_ON_ONCE); - triggerBigSync(project, { - dry: opts.dryRun, - debug: config.debug, - }, _.partial(localLog, text.SYNC_ON_ONCE_DONE)); + if (!(config.disableRsync || project.disableRsync)) { + await triggerBigSync(project, { + dry: opts.dryRun, + debug: config.debug, + }); + } + localLog(text.SYNC_ON_ONCE_DONE); }); } diff --git a/src/project-helper.js b/src/project-helper.js index bd63f8d..edfcd4b 100644 --- a/src/project-helper.js +++ b/src/project-helper.js @@ -60,6 +60,16 @@ export const add = (config) => { before: util.toBoolean, default: 'no', }, + disableDeletion: { + description: 'Prevent sicksync from deleting files on the remote server? (yes/no):', + before: util.toBoolean, + default: 'no', + }, + disableRsync: { + description: 'Prevent sicksync from doing rsync on big file changes? (yes/no):', + default: 'no', + before: util.toBoolean, + }, websocketPort: { description: 'What port should sicksync use for this project?', default: 8675,