Code coverage report for tasks/clean.js

Statements: 23.08% (9 / 39)      Branches: 0% (0 / 34)      Functions: 0% (0 / 12)      Lines: 25.71% (9 / 35)      Ignored: none     

All files » tasks/ » clean.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 531 1 1 1 1 1   1                       1                                                   1              
var Promise = require('es6-promise').Promise;
var path = require('path');
var log = require('./utils/log');
var fs = require('./utils/fs');
var helper = require('./utils/config-helper');
var config;
 
function clean(location, options){
    log.info(' * ' + location);
    return fs.del(location, options).then(function(delPaths){
        if (options.verbose && delPaths.length){
            delPaths.forEach(function(delPath){
                log.info('    * ' + delPath.replace(config.appRoot,''));
            });
        }
    });
}
 
//pipe all task execution through here to unify config normalisation
function exec(subtask, location, options){
    var tasks;
    config = helper.getConfig();
 
    var globsArr = [config.globs[subtask]];
    if (subtask==='copy') globsArr = config.tasks.copy;
    if (subtask==='build') globsArr = Object.keys(config.globs).map(function(key){ return config.globs[key]; });
    if (subtask==='all') globsArr = ['/**'];
 
    //normalise the args into an array of tasks
    if (location && typeof location === 'object'){  //from node API
        tasks = [{ source: globsArr, options: location}];
    } else if (location && typeof location != 'object'){  //from node API
        tasks = [{ source: location, options: options || { }}];
    } else {  //from node CLI
        tasks = helper.normaliseClean(globsArr, config, options || { });
    }
 
    //do prep-task then do copy task
    log.info('Cleaning :');
    var promises = tasks.map(function(params){
        return clean(params.source, params.options);
    });
    return Promise.all(promises).catch(log.onError);
}
 
module.exports = {
    'copy': function(location, options){ return exec('copy', location, options || arguments[2]); },
    'build': function(location, options){ return exec('build', location, options || arguments[2]); },
    'html': function(location, options){ return exec('html', location, options || arguments[2]); },
    'styles': function(location, options){ return exec('styles', location, options || arguments[2]); },
    'scripts': function(location, options){ return exec('scripts', location, options || arguments[2]); },
    'all': function(location, options){ return exec('all', location, options || arguments[2]); }
};