ssh-deploy/src/index.js

40 lines
1.1 KiB
JavaScript
Raw Normal View History

2019-10-02 23:52:52 +02:00
#!/usr/bin/env node
const { sshDeploy } = require('./rsyncCli');
const { remoteCmdBefore, remoteCmdAfter } = require('./remoteCmd');
2023-01-02 11:41:31 +01:00
const { addSshKey, getPrivateKeyPath } = require('./sshKey');
const { validateRequiredInputs } = require('./helpers');
const inputs = require('./inputs');
2019-10-02 23:52:52 +02:00
const run = () => {
const {
source, remoteUser, remoteHost, remotePort,
deployKeyName, sshPrivateKey,
2023-01-02 01:33:48 +01:00
args, exclude, sshCmdArgs,
scriptBefore, scriptAfter,
2023-01-02 02:13:02 +01:00
rsyncServer
} = inputs;
// Validate required inputs
validateRequiredInputs({ sshPrivateKey, remoteHost, remoteUser });
// Add SSH key
2023-01-02 11:41:31 +01:00
addSshKey(sshPrivateKey, deployKeyName);
const { path: privateKeyPath } = getPrivateKeyPath(deployKeyName);
// Check Script before
if (scriptBefore) {
remoteCmdBefore(scriptBefore);
}
// Check script after
let callback = () => {};
if (scriptAfter) {
callback = (...result) => {
remoteCmdAfter(scriptAfter, result);
};
}
/* eslint-disable object-property-newline */
sshDeploy({
2023-01-02 02:13:02 +01:00
source, rsyncServer, exclude, remotePort,
2023-01-02 11:41:31 +01:00
privateKeyPath, args, sshCmdArgs, callback
});
2019-10-02 23:52:52 +02:00
};
run();