All files / src syndProcess.js

100% Statements 27/27
100% Branches 10/10
100% Functions 2/2
100% Lines 25/25

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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 623x 3x                 3x   3x 5x   5x 1x 1x   2x         5x   4x   4x 4x 4x   4x   4x         4x 1x   4x 4x   4x 1x     4x   4x                 3x  
const fs = require('fs');
const getRsyncFunc = require('./rsync');
const {
    getOnFileChangeFunc,
    getSyncFunc,
    getConfig,
    getFilterFile,
    getPaths,
    parseConfig,
    log,
} = require('./utils');
 
const syndProcess = (name, cmd) => {
    const syndConfig = getConfig();
 
    if (cmd.list === true) {
        log.plain(`Your presets:`);
        log.plain(
            Object.keys(syndConfig)
                .map(k => `- ${k}`)
                .join('\n'),
        );
    }
 
    if (name === undefined) return null;
 
    log(`Going to try to do the "${name}" preset`);
 
    const userConfig = parseConfig(syndConfig, name);
    const userConfigWithFullIncludeExclude = getPaths(userConfig);
    const filterFilePath = getFilterFile(userConfigWithFullIncludeExclude);
 
    log(`about to sync \n\t${userConfig.src} to \n\t${userConfig.dest}\n\n`);
 
    const rsyncFunc = getRsyncFunc({
        ...userConfigWithFullIncludeExclude,
        filterFilePath,
    });
 
    if (userConfig.showRsyncCommand)
        log(`rsync command\n\n${rsyncFunc.command()}`);
 
    const syncFunc = getSyncFunc({rsyncFunc});
    const onFileChangeFunc = getOnFileChangeFunc({syncFunc});
 
    if (userConfig.watch) {
        fs.watch(userConfig.src, {recursive: true}, onFileChangeFunc);
    }
 
    if (userConfig.initSync === true) syncFunc();
 
    return {
        ...userConfigWithFullIncludeExclude,
        filterFilePath,
        rsyncFunc,
        syncFunc,
        onFileChangeFunc,
    };
};
 
module.exports = syndProcess;