From e94c1b3857ec4ec09097db6274c95c1e9c12ed63 Mon Sep 17 00:00:00 2001 From: laggingreflex Date: Tue, 21 Feb 2017 21:52:47 +0530 Subject: [PATCH 1/7] feat: disable triggerBigSync Lets you add an option `"triggerBigSync": false` in project conf to disable doing a big rsync. --- README.md | 4 ++++ src/local/index.js | 40 +++++++++++++++++++++++----------------- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 4dfb91d..e22466f 100644 --- a/README.md +++ b/README.md @@ -136,6 +136,10 @@ Flag that will turn on or off encrypted sync messages. When true, this will tell `sicksync` to follow and sync files and folders that are symlinked. Defaults to `false` in setup. +`triggerBigSync: {boolean}` + +When false, this will tell `sicksync` **not** to do rsync for any big file changes. (default: true) + ## Migrating to from 1.x to 2.x 2.x introduces a number of new and breaking changes. It's worthwhile to upgrade, as sicksync now has better reliabitiliy, new functionality, and extensibility in 2.x. Aside from command-line changes, sicksync 2.x also introduces a breaking config change as well. Below are the steps you'll need to run in order to migrate to sicksync 2.x: diff --git a/src/local/index.js b/src/local/index.js index 9b40f4c..290ce2a 100644 --- a/src/local/index.js +++ b/src/local/index.js @@ -80,15 +80,17 @@ 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' - ); - }); + if (projectConf.triggerBigSync !== false) { + 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)); @@ -125,10 +127,12 @@ function startProject(config, projectConf) { localLog(text.SYNC_ON_LARGE_CHANGE); fsHelper.pauseWatch(); - triggerBigSync(projectConf, { debug: config.debug }, () => { - localLog(text.SYNC_ON_LARGE_CHANGE_DONE); - fsHelper.watch(); - }); + if (projectConf.triggerBigSync !== false) { + triggerBigSync(projectConf, { debug: config.debug }, () => { + localLog(text.SYNC_ON_LARGE_CHANGE_DONE); + fsHelper.watch(); + }); + } }); } @@ -144,10 +148,12 @@ export function once(config, projects, opts) { localLog(text.SYNC_ON_ONCE); - triggerBigSync(project, { - dry: opts.dryRun, - debug: config.debug, - }, _.partial(localLog, text.SYNC_ON_ONCE_DONE)); + if (project.triggerBigSync !== false) { + triggerBigSync(project, { + dry: opts.dryRun, + debug: config.debug, + }, _.partial(localLog, text.SYNC_ON_ONCE_DONE)); + } }); } From ed03866c1fabe07d91889576fb4fff4b9e56c08a Mon Sep 17 00:00:00 2001 From: laggingreflex Date: Tue, 21 Feb 2017 22:34:57 +0530 Subject: [PATCH 2/7] fix: Disable deletion Update the logic that controlled disabling deletion from just a --no-delete argument to --disable-deletion argument as well as "disableDeleteion" project config --- README.md | 4 ++++ src/big-sync.js | 4 ++-- src/commands/start.js | 4 ++-- src/local/index.js | 1 + src/project-helper.js | 5 +++++ 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e22466f..2c903c2 100644 --- a/README.md +++ b/README.md @@ -114,6 +114,10 @@ The location on your remote machine you wish to apply changes to. `excludes: {array of relative filepaths or globs}` +`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` + 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. `websocketPort: {number}` diff --git a/src/big-sync.js b/src/big-sync.js index 7533045..a460b2a 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) { diff --git a/src/commands/start.js b/src/commands/start.js index c58f39b..6182608 100644 --- a/src/commands/start.js +++ b/src/commands/start.js @@ -5,9 +5,9 @@ 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') .action((projects, options) => - start(_.extend(config, _.pick(options, ['delete'])), projects)) + start(_.extend(config, _.pick(options, ['disableDeletion'])), projects)); } export default sicksyncStartCommand; diff --git a/src/local/index.js b/src/local/index.js index 290ce2a..0cd0d97 100644 --- a/src/local/index.js +++ b/src/local/index.js @@ -34,6 +34,7 @@ function triggerBigSync(project, params, cb) { destinationLocation: ensureTrailingSlash(project.destinationLocation), hostname: project.hostname, username: project.username, + disableDeletion: project.disableDeletion, }, params, cb); } diff --git a/src/project-helper.js b/src/project-helper.js index bd63f8d..d2f4f78 100644 --- a/src/project-helper.js +++ b/src/project-helper.js @@ -60,6 +60,11 @@ 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', + }, websocketPort: { description: 'What port should sicksync use for this project?', default: 8675, From acb156a9b79be3442b2af37c21483ff4f4df8748 Mon Sep 17 00:00:00 2001 From: laggingreflex Date: Tue, 21 Feb 2017 22:56:57 +0530 Subject: [PATCH 3/7] fix: disableRsync (arg * project conf) instead of project.triggerBigSync project conf --- src/commands/start.js | 1 + src/local/index.js | 6 +++--- src/project-helper.js | 5 +++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/commands/start.js b/src/commands/start.js index 6182608..b5302ce 100644 --- a/src/commands/start.js +++ b/src/commands/start.js @@ -6,6 +6,7 @@ function sicksyncStartCommand(program, config) { .command('start [projects...]') .description('Starts the continuous sicksync process for the given project(s)') .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, ['disableDeletion'])), projects)); } diff --git a/src/local/index.js b/src/local/index.js index 0cd0d97..a42f5a3 100644 --- a/src/local/index.js +++ b/src/local/index.js @@ -81,7 +81,7 @@ function startProject(config, projectConf) { // WS events wsClient.on(wsEvents.READY, () => { - if (projectConf.triggerBigSync !== false) { + if (!projectConf.disableRsync) { triggerBigSync(projectConf, _.pick(config, ['debug', 'delete']), () => { fsHelper.watch(); @@ -128,7 +128,7 @@ function startProject(config, projectConf) { localLog(text.SYNC_ON_LARGE_CHANGE); fsHelper.pauseWatch(); - if (projectConf.triggerBigSync !== false) { + if (!projectConf.disableRsync) { triggerBigSync(projectConf, { debug: config.debug }, () => { localLog(text.SYNC_ON_LARGE_CHANGE_DONE); fsHelper.watch(); @@ -149,7 +149,7 @@ export function once(config, projects, opts) { localLog(text.SYNC_ON_ONCE); - if (project.triggerBigSync !== false) { + if (!project.disableRsync) { triggerBigSync(project, { dry: opts.dryRun, debug: config.debug, diff --git a/src/project-helper.js b/src/project-helper.js index d2f4f78..edfcd4b 100644 --- a/src/project-helper.js +++ b/src/project-helper.js @@ -65,6 +65,11 @@ export const add = (config) => { 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, From ab1e3eb32d8dd565e7eec695a0dc8935001a3b8c Mon Sep 17 00:00:00 2001 From: laggingreflex Date: Tue, 21 Feb 2017 22:56:57 +0530 Subject: [PATCH 4/7] fix: projectConf.disableRsync --- src/commands/start.js | 2 +- src/local/index.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/commands/start.js b/src/commands/start.js index b5302ce..dd7447b 100644 --- a/src/commands/start.js +++ b/src/commands/start.js @@ -8,7 +8,7 @@ function sicksyncStartCommand(program, config) { .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, ['disableDeletion'])), 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 a42f5a3..484ae6f 100644 --- a/src/local/index.js +++ b/src/local/index.js @@ -81,7 +81,7 @@ function startProject(config, projectConf) { // WS events wsClient.on(wsEvents.READY, () => { - if (!projectConf.disableRsync) { + if (!(config.disableRsync || projectConf.disableRsync)) { triggerBigSync(projectConf, _.pick(config, ['debug', 'delete']), () => { fsHelper.watch(); @@ -128,7 +128,7 @@ function startProject(config, projectConf) { localLog(text.SYNC_ON_LARGE_CHANGE); fsHelper.pauseWatch(); - if (!projectConf.disableRsync) { + if (!(config.disableRsync || projectConf.disableRsync)) { triggerBigSync(projectConf, { debug: config.debug }, () => { localLog(text.SYNC_ON_LARGE_CHANGE_DONE); fsHelper.watch(); @@ -149,7 +149,7 @@ export function once(config, projects, opts) { localLog(text.SYNC_ON_ONCE); - if (!project.disableRsync) { + if (!(config.disableRsync || project.disableRsync)) { triggerBigSync(project, { dry: opts.dryRun, debug: config.debug, From 5195de61bece3ed965c55dcc12a1d7369cf30da4 Mon Sep 17 00:00:00 2001 From: laggingreflex Date: Tue, 21 Feb 2017 22:56:57 +0530 Subject: [PATCH 5/7] babel-preset-stage-0 for async/await --- .babelrc | 2 +- package.json | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) 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/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", From 0a7dffa0a88af0cca39e2778d9e1eb0e3daec62d Mon Sep 17 00:00:00 2001 From: laggingreflex Date: Tue, 21 Feb 2017 22:56:57 +0530 Subject: [PATCH 6/7] use async/await, change bigsync callback to promise --- src/big-sync.js | 8 +++++++- src/local/index.js | 41 +++++++++++++++++++---------------------- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/src/big-sync.js b/src/big-sync.js index a460b2a..e7e00f8 100644 --- a/src/big-sync.js +++ b/src/big-sync.js @@ -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/local/index.js b/src/local/index.js index 484ae6f..b08125b 100644 --- a/src/local/index.js +++ b/src/local/index.js @@ -26,8 +26,8 @@ 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), @@ -35,7 +35,7 @@ function triggerBigSync(project, params, cb) { hostname: project.hostname, username: project.username, disableDeletion: project.disableDeletion, - }, params, cb); + }, params); } export function start(config, projects) { @@ -80,18 +80,16 @@ function startProject(config, projectConf) { }); // WS events - wsClient.on(wsEvents.READY, () => { + wsClient.on(wsEvents.READY, async () => { if (!(config.disableRsync || projectConf.disableRsync)) { - triggerBigSync(projectConf, _.pick(config, ['debug', 'delete']), () => { - fsHelper.watch(); - - localLog( - text.SYNC_ON_CONNECT, - projectConf.hostname, (projectConf.prefersEncrypted) ? 'using' : 'not using', - 'encryption' - ); - }); + 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)); @@ -124,16 +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(); - if (!(config.disableRsync || projectConf.disableRsync)) { - triggerBigSync(projectConf, { debug: config.debug }, () => { - localLog(text.SYNC_ON_LARGE_CHANGE_DONE); - fsHelper.watch(); - }); + await triggerBigSync(projectConf, { debug: config.debug }); } + localLog(text.SYNC_ON_LARGE_CHANGE_DONE); + fsHelper.watch(); }); } @@ -144,17 +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); if (!(config.disableRsync || project.disableRsync)) { - triggerBigSync(project, { + await triggerBigSync(project, { dry: opts.dryRun, debug: config.debug, - }, _.partial(localLog, text.SYNC_ON_ONCE_DONE)); + }); } + localLog(text.SYNC_ON_ONCE_DONE); }); } From 6165fbf3032e546b50cb8f1c84919f9951f13ff7 Mon Sep 17 00:00:00 2001 From: laggingreflex Date: Tue, 21 Feb 2017 22:56:57 +0530 Subject: [PATCH 7/7] docs: fix/update readme --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 2c903c2..bc11a20 100644 --- a/README.md +++ b/README.md @@ -114,11 +114,15 @@ The location on your remote machine you wish to apply changes to. `excludes: {array of relative filepaths or globs}` +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` -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. +`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}` @@ -140,10 +144,6 @@ Flag that will turn on or off encrypted sync messages. When true, this will tell `sicksync` to follow and sync files and folders that are symlinked. Defaults to `false` in setup. -`triggerBigSync: {boolean}` - -When false, this will tell `sicksync` **not** to do rsync for any big file changes. (default: true) - ## Migrating to from 1.x to 2.x 2.x introduces a number of new and breaking changes. It's worthwhile to upgrade, as sicksync now has better reliabitiliy, new functionality, and extensibility in 2.x. Aside from command-line changes, sicksync 2.x also introduces a breaking config change as well. Below are the steps you'll need to run in order to migrate to sicksync 2.x: