mirror of
https://github.com/easingthemes/ssh-deploy.git
synced 2024-04-28 00:37:18 +08:00
ec9347f8c6
* feat: Add SSH remote script support - before and after rsync * fix: remove __dirname * feat: add sshCmdArgs option * Add promise instead of callback * fix: improve logs * fix: Add simple command exists instead of a plugin * add non interactive install * feat: add onStderr and onStdout logs * Improve reject messages * feat: Add RSYNC_STDOUT env variable * emoji updates * fix: update workflow actions
48 lines
1.4 KiB
JavaScript
48 lines
1.4 KiB
JavaScript
#!/usr/bin/env node
|
|
const { sshDeploy } = require('./rsyncCli');
|
|
const { remoteCmdBefore, remoteCmdAfter } = require('./remoteCmd');
|
|
const { addSshKey, getPrivateKeyPath, updateKnownHosts } = require('./sshKey');
|
|
const { validateRequiredInputs } = require('./helpers');
|
|
const inputs = require('./inputs');
|
|
|
|
const run = async () => {
|
|
const {
|
|
source, remoteUser, remoteHost, remotePort,
|
|
deployKeyName, sshPrivateKey,
|
|
args, exclude, sshCmdArgs,
|
|
scriptBefore, scriptAfter,
|
|
rsyncServer
|
|
} = inputs;
|
|
// Validate required inputs
|
|
validateRequiredInputs({ sshPrivateKey, remoteHost, remoteUser });
|
|
// Add SSH key
|
|
addSshKey(sshPrivateKey, deployKeyName);
|
|
const { path: privateKeyPath } = getPrivateKeyPath(deployKeyName);
|
|
// Update known hosts if ssh command is present to avoid prompt
|
|
if (scriptBefore || scriptAfter) {
|
|
updateKnownHosts(remoteHost);
|
|
}
|
|
// Check Script before
|
|
if (scriptBefore) {
|
|
await remoteCmdBefore(scriptBefore, privateKeyPath);
|
|
}
|
|
/* eslint-disable object-property-newline */
|
|
await sshDeploy({
|
|
source, rsyncServer, exclude, remotePort,
|
|
privateKeyPath, args, sshCmdArgs
|
|
});
|
|
// Check script after
|
|
if (scriptAfter) {
|
|
await remoteCmdAfter(scriptAfter, privateKeyPath);
|
|
}
|
|
};
|
|
|
|
run()
|
|
.then((data = '') => {
|
|
console.log('✅ [DONE]', data);
|
|
})
|
|
.catch((error) => {
|
|
console.error('❌ [ERROR]', error.message);
|
|
process.exit(1);
|
|
});
|