Skip to content
This repository has been archived by the owner on Mar 14, 2023. It is now read-only.

added log to runLocally, added test for tarring folder/ #279

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/ssh-pool/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,8 @@
"stream-line-wrapper": "^0.1.1",
"tmp": "^0.1.0",
"which": "^1.3.1"
},
"devDependencies": {
"fs-extra": "^9.0.1"
}
}
2 changes: 2 additions & 0 deletions packages/ssh-pool/src/Connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions packages/ssh-pool/src/commands/tar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello from anotherfolder
22 changes: 21 additions & 1 deletion packages/ssh-pool/tests/integration.test.js
Original file line number Diff line number Diff line change
@@ -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')

Expand All @@ -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`;
Expand All @@ -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)
})
34 changes: 34 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down