diff --git a/packages/ssh-pool/package.json b/packages/ssh-pool/package.json index 287939a..21b89c9 100644 --- a/packages/ssh-pool/package.json +++ b/packages/ssh-pool/package.json @@ -24,5 +24,8 @@ "stream-line-wrapper": "^0.1.1", "tmp": "^0.1.0", "which": "^1.3.1" + }, + "devDependencies": { + "fs-extra": "^9.0.1" } } diff --git a/packages/ssh-pool/src/Connection.js b/packages/ssh-pool/src/Connection.js index ac540d5..1fdfc6e 100644 --- a/packages/ssh-pool/src/Connection.js +++ b/packages/ssh-pool/src/Connection.js @@ -430,6 +430,8 @@ class Connection { const stdoutPipe = stdout || this.options.stdout const stderrPipe = stderr || this.options.stderr + this.log('Running "%s" on locally.', cmd) + return exec(cmd, cmdOptions, child => { if (stdoutPipe) child.stdout diff --git a/packages/ssh-pool/src/commands/tar.js b/packages/ssh-pool/src/commands/tar.js index 7344aca..1c189bb 100644 --- a/packages/ssh-pool/src/commands/tar.js +++ b/packages/ssh-pool/src/commands/tar.js @@ -7,17 +7,17 @@ function formatExcludes(excludes) { ) } -export function formatTarCommand({ file, archive, excludes, mode }) { +export function formatTarCommand({ file: fileOrDir, archive, excludes, mode }) { let args = ['tar'] switch (mode) { case 'compress': { - requireArgs(['file', 'archive'], { file, archive }, 'tar') + requireArgs(['file', 'archive'], { file: fileOrDir, archive }, 'tar') if (excludes) args = [...args, ...formatExcludes(excludes)] - args = [...args, '-czf', archive, file] + args = [...args, '-czf', archive, fileOrDir] return joinCommandArgs(args) } case 'extract': { - requireArgs(['archive'], { file, archive }, 'tar') + requireArgs(['archive'], { file: fileOrDir, archive }, 'tar') args = [...args, '-xzf', archive] return joinCommandArgs(args) } diff --git a/packages/ssh-pool/tests/__fixtures__/anotherfolder/test.txt b/packages/ssh-pool/tests/__fixtures__/anotherfolder/test.txt new file mode 100644 index 0000000..c59bb3e --- /dev/null +++ b/packages/ssh-pool/tests/__fixtures__/anotherfolder/test.txt @@ -0,0 +1 @@ +Hello from anotherfolder diff --git a/packages/ssh-pool/tests/integration.test.js b/packages/ssh-pool/tests/integration.test.js index 2c82c9f..de5e266 100644 --- a/packages/ssh-pool/tests/integration.test.js +++ b/packages/ssh-pool/tests/integration.test.js @@ -1,5 +1,6 @@ import {resolve, basename} from 'path' import {copyFileSync, unlinkSync} from 'fs'; +import {copySync as fseCopySync, removeSync as fseRemoveSync} from 'fs-extra'; const sshPool = require('../src') @@ -25,7 +26,7 @@ describe('ssh-pool', () => { expect(second).toBe('$USER\n') }, 10000) - it('should copy to remote', async () => { + it('should copy a file to remote', async () => { const time = (+new Date); const sourceFile = resolve(__dirname, '__fixtures__/test.txt') const targetFile = `${__dirname}/__fixtures__/test.${time}.txt`; @@ -41,4 +42,23 @@ describe('ssh-pool', () => { } }, 1e6) + + it('should copy a folder to remote', async () => { + const time = (+new Date); + const sourceFile = resolve(__dirname, '__fixtures__/anotherfolder') + const targetFile = `${__dirname}/__fixtures__/anotherfolder${time}`; + + fseCopySync(sourceFile, targetFile); + + try { + await pool.scpCopyToRemote(targetFile, './',); + const [{ stdout: first }] = await pool.run(`ls -la | grep anotherfolder${time}`); + const [{ stdout: second }] = await pool.run(`cat ./anotherfolder${time}/test.txt`); + expect(first).toContain(`anotherfolder${time}\n`) + expect(second).toBe('Hello from anotherfolder\n') + } finally { + fseRemoveSync(targetFile); + } + + }, 1e6) }) diff --git a/yarn.lock b/yarn.lock index b2249f4..4373bf6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2092,6 +2092,11 @@ asynckit@^0.4.0: resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79" integrity sha1-x57Zf380y48robyXkLzDZkdLS3k= +at-least-node@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/at-least-node/-/at-least-node-1.0.0.tgz#602cd4b46e844ad4effc92a8011a3c46e0238dc2" + integrity sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg== + atob-lite@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/atob-lite/-/atob-lite-2.0.0.tgz#0fef5ad46f1bd7a8502c65727f0367d5ee43d696" @@ -4214,6 +4219,16 @@ fs-extra@^8.1.0: jsonfile "^4.0.0" universalify "^0.1.0" +fs-extra@^9.0.1: + version "9.0.1" + resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-9.0.1.tgz#910da0062437ba4c39fedd863f1675ccfefcb9fc" + integrity sha512-h2iAoN838FqAFJY2/qVpzFXy+EBxfVE220PalAqQLDVsFOHLJrZvut5puAbCdNv6WJk+B8ihI+k0c7JK5erwqQ== + dependencies: + at-least-node "^1.0.0" + graceful-fs "^4.2.0" + jsonfile "^6.0.1" + universalify "^1.0.0" + fs-minipass@^1.2.5: version "1.2.6" resolved "https://registry.yarnpkg.com/fs-minipass/-/fs-minipass-1.2.6.tgz#2c5cc30ded81282bfe8a0d7c7c1853ddeb102c07" @@ -5669,6 +5684,15 @@ jsonfile@^4.0.0: optionalDependencies: graceful-fs "^4.1.6" +jsonfile@^6.0.1: + version "6.1.0" + resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-6.1.0.tgz#bc55b2634793c679ec6403094eb13698a6ec0aae" + integrity sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ== + dependencies: + universalify "^2.0.0" + optionalDependencies: + graceful-fs "^4.1.6" + jsonparse@^1.2.0: version "1.3.1" resolved "https://registry.yarnpkg.com/jsonparse/-/jsonparse-1.3.1.tgz#3f4dae4a91fac315f71062f8521cc239f1366280" @@ -8543,6 +8567,16 @@ universalify@^0.1.0: resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.1.2.tgz#b646f69be3942dabcecc9d6639c80dc105efaa66" integrity sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg== +universalify@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/universalify/-/universalify-1.0.0.tgz#b61a1da173e8435b2fe3c67d29b9adf8594bd16d" + integrity sha512-rb6X1W158d7pRQBg5gkR8uPaSfiids68LTJQYOtEUhoJUWBdaQHsuT/EUduxXYxcrt4r5PJ4fuHW1MHT6p0qug== + +universalify@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/universalify/-/universalify-2.0.0.tgz#75a4984efedc4b08975c5aeb73f530d02df25717" + integrity sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ== + unset-value@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/unset-value/-/unset-value-1.0.0.tgz#8376873f7d2335179ffb1e6fc3a8ed0dfc8ab559"