diff --git a/packages/shipit-cli/src/Shipit.js b/packages/shipit-cli/src/Shipit.js index 7772271..89ac9c1 100644 --- a/packages/shipit-cli/src/Shipit.js +++ b/packages/shipit-cli/src/Shipit.js @@ -170,6 +170,26 @@ class Shipit extends Orchestrator { return this } + /** + * Add --progress flag to rsync config. + * + * @returns {Shipit} for chaining + */ + setShowProgress(){ + this.config.rsync = this.config.rsync ? [...this.config.rsync, "--progress"] : ["--progress"] + return this + } + + /** + * Add --stats flag to rsync config. + * + * @returns {Shipit} for chaining + */ + setShowStats(){ + this.config.rsync = this.config.rsync ? [...this.config.rsync, "--stats"] : ["--stats"] + return this + } + /** * Initialize shipit configuration. * @@ -228,7 +248,13 @@ class Shipit extends Orchestrator { ignores: this.config && this.config.ignores ? this.config.ignores : [], rsync: this.config && this.config.rsync ? this.config.rsync : [], } - const copyOptions = { ...defaultOptions, ...options } + let copyOptions = { ...defaultOptions, ...options } + + // Stop rsync config to be overwrited from the deploy rsync options. + if(typeof copyOptions.rsync === 'string') { + copyOptions.rsync = [copyOptions.rsync] + } + copyOptions = {...copyOptions, rsync: [...new Set([...defaultOptions.rsync, ...copyOptions.rsync])]} return this.pool.copy(src, dest, copyOptions) } @@ -252,7 +278,14 @@ class Shipit extends Orchestrator { ignores: this.config && this.config.ignores ? this.config.ignores : [], rsync: this.config && this.config.rsync ? this.config.rsync : [], } - const copyOptions = { ...defaultOptions, ...options } + let copyOptions = { ...defaultOptions, ...options } + + // Stop rsync config to be overwrited from the deploy rsync options. + if(typeof copyOptions.rsync === 'string') { + copyOptions.rsync = [copyOptions.rsync] + } + copyOptions = {...copyOptions, rsync: [...new Set([...defaultOptions.rsync, ...copyOptions.rsync])]} + return this.pool.copyToRemote(src, dest, copyOptions) } @@ -274,7 +307,14 @@ class Shipit extends Orchestrator { ignores: this.config && this.config.ignores ? this.config.ignores : [], rsync: this.config && this.config.rsync ? this.config.rsync : [], } - const copyOptions = { ...defaultOptions, ...options } + let copyOptions = { ...defaultOptions, ...options } + + // Stop rsync config to be overwrited from the deploy rsync options. + if(typeof copyOptions.rsync === 'string') { + copyOptions.rsync = [copyOptions.rsync] + } + copyOptions = {...copyOptions, rsync: [...new Set([...defaultOptions.rsync, ...copyOptions.rsync])]} + return this.pool.copyFromRemote(src, dest, copyOptions) } diff --git a/packages/shipit-cli/src/Shipit.test.js b/packages/shipit-cli/src/Shipit.test.js index ddd836c..a02f85a 100644 --- a/packages/shipit-cli/src/Shipit.test.js +++ b/packages/shipit-cli/src/Shipit.test.js @@ -153,6 +153,36 @@ describe('Shipit', () => { rsync: ['--bar'], }) }) + + it('should support show-progress flag', () => { + + shipit.setShowProgress() + + shipit.remoteCopy('src', 'dest', { + direction: 'remoteToLocal', + }) + + expect(shipit.pool.copy).toBeCalledWith('src', 'dest', { + direction: 'remoteToLocal', + ignores: [], + rsync: ["--progress"], + }) + }) + + it('should support show-stats flag', () => { + + shipit.setShowStats() + + shipit.remoteCopy('src', 'dest', { + direction: 'remoteToLocal', + }) + + expect(shipit.pool.copy).toBeCalledWith('src', 'dest', { + direction: 'remoteToLocal', + ignores: [], + rsync: ["--stats"], + }) + }) }) describe('#copyFromRemote', () => { @@ -193,6 +223,30 @@ describe('Shipit', () => { rsync: ['--bar'], }) }) + + it('should support show-progress flag', () => { + + shipit.setShowProgress() + + shipit.copyFromRemote('src', 'dest') + + expect(shipit.pool.copyFromRemote).toBeCalledWith('src', 'dest', { + ignores: [], + rsync: ["--progress"], + }) + }) + + it('should support show-stats flag', () => { + + shipit.setShowStats() + + shipit.copyFromRemote('src', 'dest') + + expect(shipit.pool.copyFromRemote).toBeCalledWith('src', 'dest', { + ignores: [], + rsync: ["--stats"], + }) + }) }) describe('#copyToRemote', () => { @@ -233,5 +287,29 @@ describe('Shipit', () => { rsync: ['--bar'], }) }) + + it('should support show-progress flag', () => { + + shipit.setShowProgress() + + shipit.copyToRemote('src', 'dest') + + expect(shipit.pool.copyToRemote).toBeCalledWith('src', 'dest', { + ignores: [], + rsync: ["--progress"], + }) + }) + + it('should support show-stats flag', () => { + + shipit.setShowStats() + + shipit.copyToRemote('src', 'dest') + + expect(shipit.pool.copyToRemote).toBeCalledWith('src', 'dest', { + ignores: [], + rsync: ["--stats"], + }) + }) }) }) diff --git a/packages/shipit-cli/src/cli.js b/packages/shipit-cli/src/cli.js index 8ca0cec..420d31a 100644 --- a/packages/shipit-cli/src/cli.js +++ b/packages/shipit-cli/src/cli.js @@ -26,6 +26,8 @@ program .option('--require ', 'Script required before launching Shipit') .option('--tasks', 'List available tasks') .option('--environments', 'List available environments') + .option('-p, --show-progress', 'Show rsync Progress') + .option('-s, --show-stats', 'Show rsync Stats') program.parse(process.argv) @@ -49,6 +51,14 @@ function logEnvironments(shipit) { ) } +function logProgress(shipit) { + shipit.setShowProgress() +} + +function logStats(shipit) { + shipit.setShowStats() +} + async function asyncInvoke(env) { if (!env.configPath) { console.error(chalk.red('shipitfile not found')) @@ -71,6 +81,13 @@ async function asyncInvoke(env) { throw error } + if(program.showProgress) { + logProgress(shipit) + } + if(program.showStats){ + logStats(shipit) + } + if (program.tasks === true) { logTasks(shipit) } else if (program.environments === true) { diff --git a/packages/ssh-pool/src/Connection.js b/packages/ssh-pool/src/Connection.js index 8a4e1d3..405bb7f 100644 --- a/packages/ssh-pool/src/Connection.js +++ b/packages/ssh-pool/src/Connection.js @@ -337,7 +337,7 @@ class Connection { src, dest, remoteShell: sshCommand, - additionalArgs: typeof rsync === 'string' ? [rsync] : rsync, + additionalArgs: (typeof rsync === 'string' ? [rsync] : rsync), excludes: ignores, })