fix promise

This commit is contained in:
Dragan Filipovic 2023-01-02 01:23:54 +01:00
parent 11a1bc7795
commit a16ae38e86
3 changed files with 9 additions and 7 deletions

2
dist/index.js vendored

File diff suppressed because one or more lines are too long

View File

@ -2,13 +2,14 @@ const { execSync } = require('child_process');
const which = require('which');
const nodeRsync = require('rsyncwrapper');
const validateRsync = async () => {
// eslint-disable-next-line no-async-promise-executor
const validateRsync = () => new Promise(async (resolve, reject) => {
const rsyncCli = await which('rsync', { nothrow: true });
execSync('rsync --version', { stdio: 'inherit' });
if (rsyncCli) {
console.log('⚠️ [CLI] Rsync exists');
execSync('rsync --version', { stdio: 'inherit' });
return;
resolve();
}
console.log('⚠️ [CLI] Rsync doesn\'t exists. Start installation with "apt-get" \n');
@ -16,10 +17,11 @@ const validateRsync = async () => {
try {
execSync('sudo apt-get update && sudo apt-get --no-install-recommends install rsync', { stdio: 'inherit' });
console.log('✅ [CLI] Rsync installed. \n');
resolve();
} catch (err) {
throw new Error(`⚠️ [CLI] Rsync installation failed. Aborting ... error: ${err.message}`);
reject(Error(`⚠️ [CLI] Rsync installation failed. Aborting ... error: ${err.message}`));
}
};
});
const rsyncCli = ({
source, sshServer, exclude, remotePort,
@ -39,7 +41,7 @@ const rsyncCli = ({
/* eslint-disable object-property-newline */
nodeRsync({
src: source, dest: sshServer, excludeFirst: exclude, port: remotePort,
privateKey, args, callback,
privateKey, args,
...defaultOptions
}, (error, stdout, stderr, cmd) => {
if (error) {

View File

@ -8,8 +8,8 @@ const addSshKey = (content, filename) => {
const filePath = join(dir, filename);
writeToFile({ dir, filename: 'known_hosts', content: '' });
console.log('✅ [SSH] known_hosts file ensured', dir, filename, content);
writeToFile({ dir, filename, content, isRequired: true });
console.log('✅ [SSH] key added to `.ssh` dir ', dir);
return filePath;