All files / src/utils validatePresetConfig.js

100% Statements 11/11
100% Branches 6/6
100% Functions 1/1
100% Lines 11/11

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 323x 3x   3x   7x 1x           6x 1x           5x 1x             4x     3x  
const fs = require('fs');
const log = require('./log');
 
const validateConfig = (config, name) => {
    // src must be set
    if (typeof config.src !== 'string') {
        log.errorAndExit(
            `Empty 'src' in ${name} preset. Make sure property 'name' is set.`,
        );
    }
 
    // src must exist
    if (!fs.existsSync(config.src)) {
        log.errorAndExit(
            `Invalid 'src' in ${name} preset. Make sure property 'name' is set to a valid path`,
        );
    }
 
    // dest must be set
    if (typeof config.dest !== 'string') {
        log.errorAndExit(
            `Invalid 'dest' property in "${name}". Make sure property 'dest' is set to a valid path.`,
        );
    }
 
    // TODO checks for the rest config options
 
    return true;
};
 
module.exports = validateConfig;