All files / src/rsync index.js

92.86% Statements 13/14
53.85% Branches 7/13
100% Functions 1/1
92.86% Lines 13/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 402x 2x 2x   2x 2x 2x   2x                 2x                   2x       2x 1x     2x     2x  
const fs = require('fs');
const path = require('path');
const Rsync = require('rsync');
 
const stdout = require('./stdout');
const stderr = require('./stderr');
const writeToStdout = require('./writeToStdout');
 
const rsync = ({
    src,
    dest,
    exclude = [],
    include = [],
    rsyncFilter,
    parseOutput = true,
    filterFilePath,
}) => {
    const rsyncFunc = new Rsync()
        .shell('ssh')
        .flags('az')
        .source(src)
        .set('progress')
        .destination(dest)
        .exclude(exclude)
        .include(include)
        .output(parseOutput ? stdout : writeToStdout, stderr);
 
    Iif (rsyncFilter && fs.existsSync(path.resolve(src, rsyncFilter))) {
        rsyncFunc.set('filter', `merge ${path.resolve(src, rsyncFilter)}`);
    }
 
    if (filterFilePath && fs.existsSync(filterFilePath)) {
        rsyncFunc.set('filter', `merge ${filterFilePath}`);
    }
 
    return rsyncFunc;
};
 
module.exports = rsync;