All files / src/utils parseConfig.js

100% Statements 14/14
100% Branches 6/6
100% Functions 1/1
100% Lines 14/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 373x   3x 3x   3x                   3x   3x 5x 1x 1x   4x   4x       4x       4x     3x  
const _ = require('lodash');
 
const validatePresetConfig = require('./validatePresetConfig');
const log = require('./log');
 
const DEFAULT_CONFIG = {
    initSync: false,
    watch: true,
    include: [],
    exclude: [],
    globalGitignore: false,
    localGitignore: false,
    parseOutput: false,
    showRsyncCommand: false,
};
const CONFIG_NAME = '.synd.config.js';
 
const parseConfig = (syndConfig, name) => {
    if (!(name in syndConfig)) {
        log.errorAndExit(`${name} is not in your ${CONFIG_NAME} file`);
        return null;
    }
    const presetConfig = syndConfig[name];
 
    validatePresetConfig(presetConfig, name);
 
    // TODO move to pre execute helper
    const dest =
        presetConfig.server && typeof presetConfig.server === 'string'
            ? `${presetConfig.server}:${presetConfig.dest}`
            : presetConfig.dest;
 
    return {...DEFAULT_CONFIG, ..._.omit(presetConfig, ['server']), dest, name};
};
 
module.exports = parseConfig;