47 lines
1.1 KiB
TypeScript
47 lines
1.1 KiB
TypeScript
import fs from 'fs-extra';
|
|
import path from 'path';
|
|
import { execute } from '../../execute';
|
|
|
|
/**
|
|
* Deploy using ssh and rsync
|
|
* @param outDir Repoistory output
|
|
* @param sshconf ssh deployment configuration
|
|
*/
|
|
export async function sshDeploy(
|
|
outDir: string,
|
|
sshconf: any
|
|
): Promise<void> {
|
|
|
|
const key = sshconf.key;
|
|
const host = sshconf.host;
|
|
const username = sshconf.user;
|
|
const port = sshconf.port || 22;
|
|
const target = sshconf.target;
|
|
const args = sshconf.args || '-rltgoDzvO';
|
|
|
|
if (!key || !host || !username || !target) {
|
|
console.error('SSH deployment requires more arguments.');
|
|
return;
|
|
}
|
|
|
|
console.log('Deploying to %s@%s:%d%s', username, host, port, target);
|
|
|
|
const fileList = (await fs.readdir(outDir)).filter((val) => {
|
|
return val === 'repository.json' || val.match('.tgz$');
|
|
}).map((x) => path.join(outDir, x));
|
|
|
|
const pargs = [
|
|
'rsync',
|
|
args,
|
|
'-e',
|
|
`ssh -i ${key} -p ${port}`,
|
|
...fileList,
|
|
`${username}@${host}:${target}`,
|
|
];
|
|
|
|
console.log(pargs.join(' '));
|
|
await execute(pargs, outDir);
|
|
|
|
console.log('Done!');
|
|
}
|