Code coverage report for tasks/utils/config-helper.js

Statements: 62.75% (32 / 51)      Branches: 68.97% (40 / 58)      Functions: 50% (3 / 6)      Lines: 64.58% (31 / 48)      Ignored: none     

All files » tasks/utils/ » config-helper.js
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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 921 1 1 1   1   9 19                                                           6 6     6     6     6 1   6 1       6 1   6       6 1     6 1       6 1 5         6 5 5   1       1       1
var log = require('../utils/log');
var findup = require('findup-sync');
var fs = require('../utils/fs');
var config;
 
var helper = {
    matches: function matches(config, plugins){
        return config && config.map(function(i){
            if (plugins.indexOf(i)>-1) return i;
        }).join('');
    },
    getConfig : function(){
        if (config) return config;
        var configPath = findup('caddy.config.js');
        config = (configPath) ? require(configPath) : false;
        config.appRoot = configPath.replace('caddy.config.js','');
        this.createBuildPaths(config);
        this.createGlobs(config);
        return config;
    },
    createGlobs : function(config) {
        config.globs = {
            'testCoverage':'./test/coverage/**/*',
            'serverConfig':  '/*{CNAME,.htaccess,robots.txt,manifest.json}',
            'html':  '/*.{html,jade,ms,mustache}',
            'styles':  '/{.,*}/!(_)*.{css,scss,sass}',
            'scripts': '/{.,*}/*.js',
            'fonts': '/{.,*}/*.{svg,ttf,woff,eot}',
            'images': '/{.,*}/*.{ico,png,jpg,jpeg,gif,svg}'
        };
    },
    createBuildPaths : function(config) {
        if (config.buildPaths || !config.paths){ return; }
        config.buildPaths = [];
        config.paths.source && config.buildPaths.push({ source: config.paths.source, targets:[config.paths.target]});
        config.paths.demo && config.buildPaths.push({ source: config.paths.demo, targets:[config.paths.target]});
    },
    configCheck : function(){
        var config = this.getConfig();
        var error = [
            'Your `caddy.config.js` seems to be incorrect.'
        ];
        var warn = [
            'Your `caddy.config.js` seems to be out of date.'
        ];
        Iif (!config){
            log.onError('You must have a caddy.config.js in the root of your project.');
        }
        if (!config.pkg.version){
            error.push(' * The package.json requires as a `version` string (even "version": "0.0.0" is fine)');
        }
        if (!Array.isArray(config.karma) && typeof config.karma!=='string'){
            error.push(' * The karma object within caddy.config.js must now be a String or an Array containing the karma config file(s) i.e. \n ' +
                ' karma: [\'./test/karma.unit.js\',\'./test/karma.functional.js\']');
        }
        //check old config
        if (!config.tasks){
            error.push(' * Please ensure there is a `tasks` object within your caddy.config.js');
        }
        Iif (!config.buildPaths){
            error.push(' * Please ensure there is a `buildPaths` object within your caddy.config.js');
        }
        //check build config
        if (config.tasks && config.tasks.build && config.tasks.build.indexOf && config.tasks.build.indexOf('requirejs')>=0 && !config.requirejs){
            error.push(' * There is no scripts config object:  `requirejs:{...}`');
        }
        //check test config
        if (config.tasks && config.tasks.test && !config[config.tasks.test]){
            error.push(' * There is no test config object: `' + config.tasks.test + ': {...}`');
        }
 
        //check release config
        if (config.tasks && config.tasks.release && config.tasks.release.indexOf('s3')>=0 && !config.s3){
            error.push(' * There is no release config object:  `s3:{...}`');
        } else Iif (config.tasks && config.tasks.release && config.tasks.release.indexOf('s3')>=0 && config.s3.profile &&
            (config.s3.secret || config.s3.accessKey)){
            error.push(' * Your s3 config need either `profile` OR `secret/accessKey` not all.');
        }
 
        if (error.length>1){
            log.onError(error.join('\n'));
            return error.join('\n');
        }
        Iif (warn.length>1){
            log.warn(warn.join('\n'));
            return warn.join('\n');
        }
        return true;
    }
};
 
module.exports = helper;