Code coverage report for lib/locations/local.js

Statements: 83.33% (15 / 18)      Branches: 50% (2 / 4)      Functions: 100% (4 / 4)      Lines: 83.33% (15 / 18)     

All files » lib/locations/ » local.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 28         28 28 28     28 28            
var Y = require('yui').YUI({useSync: true}).use('base-base'),
    fs = require('fs'),
    basedir = 'assets/compiled';
 
exports.location = function (config) {
    'use strict';
    var appRoot = config.app.root,
        root = '/' + config.app.prefix + '/' + config.app.appName + '/' + basedir + '/',
        files,
        i;
 
    this.yuiConfig = {
        'groups': {
            'app': {
                'base': '/',
                'comboBase': '/combo~',
                'comboSep': '~',
                'combine': true,
                'root': root
            }
        }
    };
 
    // create compiled directory under assets
    try {
        // make assets directory if does not exist
        Iif (!fs.existsSync(appRoot + '/assets')) {
            fs.mkdirSync(appRoot + '/assets');
        }
        fs.mkdirSync(appRoot + '/' +  basedir)
    } catch (e) {
        throw 'Unable to create ' + basedir + ' - ' + e;
    }
 
    this.store = function (resource, done) {
        var checksum = resource.getChecksum(),
            filename = resource.basename + '_' + checksum + '.' + resource.subtype,
            filepath =  appRoot + '/' + basedir + '/' + filename;
 
        // check if file exists, if so do not write file
        fs.exists(filepath, function (exists) {
            var url = root + filename;
            Iif (exists) {
                done(null, url);
            } else {
                require('fs').writeFile(filepath, resource.content, function (err) {
                    done(err, url);
                });
            }
        });
    };
};