Code coverage report for tasks/wrappers/requirejs.js

Statements: 50% (13 / 26)      Branches: 0% (0 / 4)      Functions: 14.29% (1 / 7)      Lines: 50% (13 / 26)      Ignored: none     

All files » tasks/wrappers/ » requirejs.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 461 1 1 1 1 1   1 2 2 2     1                                   1                           1
var Promise = require('es6-promise').Promise;
var requirejs = require('requirejs');
var path = require('path');
var fs = require('../utils/fs');
var File = require('../utils/file');
var log = require('../utils/log');
 
function RequireJS(location, destination, options){
    this.location = location;
    this.destination = destination;
    this.options = options;
}
 
RequireJS.prototype.file = function(fileObj) {
    var config = {
        baseUrl: path.join(fileObj.base,fileObj.relativeDir),
        name: fileObj.name.replace('.js',''),
        out: path.join(this.destination, fileObj.relativeDir, fileObj.name),
        generateSourceMaps: true,
        preserveLicenseComments: false,
        optimize: "none",
        mainConfigFile: this.options.mainConfigFile
    };
    return new Promise(function(resolve, reject){
        requirejs.optimize(config, function(args){
            var fileObj = new File({path:args.split('\n')[1]});
            resolve(fileObj);
        }, reject);
    });
};
 
RequireJS.prototype.write = function(){
    var self = this;
    return fs.glob(this.location).then(function(fileObjs){
        if (self.options.verbose && fileObjs.length===0){
            log.info('no .js files found within `' + self.location + '`');
        }
        var promises = [];
        fileObjs.forEach(function (fileObj, i) {
            promises.push(self.file(fileObj));
        });
        return Promise.all(promises);
    });
};
 
module.exports = RequireJS;