<commit_before>var path = require('path'),
    utils = require('mojito/lib/management/utils'),
    fs = require('fs'),
    Queue = require('buildy').Queue,
    Registry = require('buildy').Registry,
    ShakerCore = require('./core').ShakerCore,
    async = require('async');

function Rollup() {
    this._js = [];
    this._css = [];
}

Rollup.prototype = {
    addJS: function(file) {
        this._js.push(file);
    },

    setJS: function(files) {
        this._js = files;
    },

    processJS: function(name, callback) {
        this._process(name, this._js, '.js', callback);
    },

    addCSS: function(file) {
        this._css.push(file);
    },

    setCSS: function(files) {
        this._css = files;
    },

    processCSS: function(name, callback) {
        this._process(name, this._css, '.css', callback);
    },

    _process: function(name, files, ext, callback) {
        var registry = new Registry();
        registry.load(__dirname + '/tasks/checksumwrite.js');
        var queue = new Queue('MojitoRollup', {registry: registry});

        queue.on('taskComplete', function(data) {
            if (data.task.type === 'checksumwrite') {
                callback(data.result);
            }
        });

        queue.task('files', files)
            .task('concat')
            .task(ext === '.js' ? 'jsminify' : 'cssminify')
            .task('checksumwrite', {name: name + '_{checksum}' + ext})
            .run();
    }
};

function Shaker(store) {
    this._store = store;
    this._root = process.cwd();

    this._config = this._store.getAppConfig(null, 'definition').shaker || {};
    this._config.deploy = this._config.deploy || false;
    this._config.minify = this._config.minify || false;
}

Shaker.prototype = {
    run: function(callback) {
        this._callback = callback;
        this.rollupMojito();

        var shaker = new ShakerCore({root: './'});
        utils.log('[SHAKER] - Analizying application assets to Shake... ');
        shaker.shakeAll(this.onShake.bind(this));
    },

    rollupMojito: function() {
        var rollup = new Rollup(),
            files;

        this._store.preload();
        files = this._store.getRollupsApp('client', {}).srcs;

        files.forEach(function(file) {
            // Skip the app level files (Note: to override path: substr(this._root.length + 1);)
            if (this._root !== file.substr(0, this._root.length)) {
                rollup.addJS(file);
            }
        }, this);

        rollup.processJS('assets/mojito/mojito_rollup_full', function(filename) {
            utils.log('[SHAKER] - Created rollup for mojito-core in: ' + filename);
        });
    },

    onShake: function(metadata) {
        console.log(this._config.deploy);

        if (this._config.deploy) {
            utils.log('[SHAKER] - Minifying and optimizing rollups...');
            this.compress(metadata, this._callback);
        } else {
            utils.log('[SHAKER] - Processing assets for development env.');
            this.rename(metadata, this._callback);
        }
    },

    rename: function(metadata, callback){
        var mojit, action, dim, item, list,
            app = path.basename(this._root);

        for (mojit in metadata.mojits) {
            for (action in metadata.mojits[mojit]) {
                for (dim in metadata.mojits[mojit][action].shaken) {
                    for (item in metadata.mojits[mojit][action].shaken[dim]) {
                        list = metadata.mojits[mojit][action].shaken[dim];
                        list[item] = list[item].replace('./mojits', '/static');
                    }
                }
            }
        }

        for (action in metadata.app) {
            for (dim in metadata.app[action].shaken) {
                for (item in metadata.app[action].shaken[dim]) {
                    list = metadata.app[action].shaken[dim];
                    var tmp = list[item];<commit_msg>Removed console log<commit_after>var path = require('path'),
    utils = require('mojito/lib/management/utils'),
    fs = require('fs'),
    Queue = require('buildy').Queue,
    Registry = require('buildy').Registry,
    ShakerCore = require('./core').ShakerCore,
    async = require('async');

function Rollup() {
    this._js = [];
    this._css = [];
}

Rollup.prototype = {
    addJS: function(file) {
        this._js.push(file);
    },

    setJS: function(files) {
        this._js = files;
    },

    processJS: function(name, callback) {
        this._process(name, this._js, '.js', callback);
    },

    addCSS: function(file) {
        this._css.push(file);
    },

    setCSS: function(files) {
        this._css = files;
    },

    processCSS: function(name, callback) {
        this._process(name, this._css, '.css', callback);
    },

    _process: function(name, files, ext, callback) {
        var registry = new Registry();
        registry.load(__dirname + '/tasks/checksumwrite.js');
        var queue = new Queue('MojitoRollup', {registry: registry});

        queue.on('taskComplete', function(data) {
            if (data.task.type === 'checksumwrite') {
                callback(data.result);
            }
        });

        queue.task('files', files)
            .task('concat')
            .task(ext === '.js' ? 'jsminify' : 'cssminify')
            .task('checksumwrite', {name: name + '_{checksum}' + ext})
            .run();
    }
};

function Shaker(store) {
    this._store = store;
    this._root = process.cwd();

    this._config = this._store.getAppConfig(null, 'definition').shaker || {};
    this._config.deploy = this._config.deploy || false;
    this._config.minify = this._config.minify || false;
}

Shaker.prototype = {
    run: function(callback) {
        this._callback = callback;
        this.rollupMojito();

        var shaker = new ShakerCore({root: './'});
        utils.log('[SHAKER] - Analizying application assets to Shake... ');
        shaker.shakeAll(this.onShake.bind(this));
    },

    rollupMojito: function() {
        var rollup = new Rollup(),
            files;

        files = this._store.getRollupsApp('client', {}).srcs;

        files.forEach(function(file) {
            // Skip the app level files (Note: to override path: substr(this._root.length + 1);)
            if (this._root !== file.substr(0, this._root.length)) {
                rollup.addJS(file);
            }
        }, this);

        rollup.processJS('assets/mojito/mojito_rollup_full', function(filename) {
            utils.log('[SHAKER] - Created rollup for mojito-core in: ' + filename);
        });
    },

    onShake: function(metadata) {
        if (this._config.deploy) {
            utils.log('[SHAKER] - Minifying and optimizing rollups...');
            this.compress(metadata, this._callback);
        } else {
            utils.log('[SHAKER] - Processing assets for development env.');
            this.rename(metadata, this._callback);
        }
    },

    rename: function(metadata, callback){
        var mojit, action, dim, item, list,
            app = path.basename(this._root);

        for (mojit in metadata.mojits) {
            for (action in metadata.mojits[mojit]) {
                for (dim in metadata.mojits[mojit][action].shaken) {
                    for (item in metadata.mojits[mojit][action].shaken[dim]) {
                        list = metadata.mojits[mojit][action].shaken[dim];
                        list[item] = list[item].replace('./mojits', '/static');
                    }
                }
            }
        }

        for (action in metadata.app) {
            for (dim in metadata.app[action].shaken) {
                for (item in metadata.app[action].shaken[dim]) {
                    list = metadata.app[action].shaken[dim];
                    var tmp = list[item];
{'fraction_non_alphanumeric': 0.15158892875448488, 'fraction_numerical': 0.0005125576627370579, 'mean_word_length': 2.019342359767892, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3052136', 'n_tokens_mistral': 2383, 'n_tokens_neox': 2308, 'n_words': 447}