<commit_before>'use strict';

var path = require('path');
var async = require('async');
var mout = require('mout');
var L = mout.lang;
var defaultConfig = require('../config');
var multikJson = require('../util/multikJson');
var Dependency = require('./Dependency');

var Project = function (options, config) {
    this._options = mout.object.mixIn({}, options || {
        filter: null
    });
    this._config = mout.object.mixIn({}, config || defaultConfig);

    this._jsonFile = path.join(this._config.cwd, 'multik.json');
};

Project.prototype.install = function (callback) {
    callback = callback || function () {
    };

    this._analyse(function (err, dependencies) {
        if (err) {
            return callback(err);
        }

        var stack = [];

        mout.array.forEach(dependencies, function (dependency) {
            stack.push(function (stackCallback) {
                dependency.install(stackCallback);
            });
        });

        // TODO: If parralell limit > 2, then error in git clone
        async.parallelLimit(stack, 1, function (err) {
            callback(err, dependencies);
        });
    })
};

Project.prototype.update = function (callback) {
    callback = callback || function () {
    };

    this._analyse(function (err, dependencies) {
        if (err) {
            return callback(err);
        }

        var stack = [];

        mout.array.forEach(dependencies, function (dependency) {
            stack.push(function (stackCallback) {
                dependency.update(stackCallback);
            });
        });

        async.parallelLimit(stack, 5, function (err) {
            callback(err, dependencies);
        });
    })
};

Project.prototype.status = function (callback) {
    callback = callback || function () {
    };

    this._analyse(function (err, dependencies) {
        if (err) {
            return callback(err);
        }

        var stack = [];

        mout.array.forEach(dependencies, function (dependency) {
            stack.push(function (stackCallback) {
                dependency.status(stackCallback);
            });
        });

        async.parallelLimit(stack, 5, function (err) {
            callback(err, dependencies);
        });
    })
};

Project.prototype.grunt = function (callback) {
    callback = callback || function () {
    };

    this._analyse(function (err, dependencies) {
        if (err) {
            return callback(err);
        }

        var stack = [];

        mout.array.forEach(dependencies, function (dependency) {
            stack.push(function (stackCallback) {
                dependency.grunt(stackCallback);
            });
        });

        async.parallelLimit(stack, 3, function (err) {
            callback(err, dependencies);
        });

    })
};


// -----------------------

Project.prototype._analyse = function (callback) {
    var __self = this;

    async.series([
        function (asyncCallback) {
            __self._readMultikJson(asyncCallback)
        },
        function (asyncCallback) {
            __self._buildDependencies(asyncCallback);
        }
    ], function (err) {
        if (callback) {
            callback(err, __self._dependencies);
        }
    });
};

Project.prototype._readMultikJson = function (callback) {
    if (this._json) {
        return callback(null, this._json);<commit_msg>bugfix in grunt task running<commit_after>'use strict';

var path = require('path');
var async = require('async');
var mout = require('mout');
var L = mout.lang;
var defaultConfig = require('../config');
var multikJson = require('../util/multikJson');
var Dependency = require('./Dependency');

var Project = function (options, config) {
    this._options = mout.object.mixIn({}, options || {
        filter: null
    });
    this._config = mout.object.mixIn({}, config || defaultConfig);

    this._jsonFile = path.join(this._config.cwd, 'multik.json');
};

Project.prototype.install = function (callback) {
    callback = callback || function () {
    };

    this._analyse(function (err, dependencies) {
        if (err) {
            return callback(err);
        }

        var stack = [];

        mout.array.forEach(dependencies, function (dependency) {
            stack.push(function (stackCallback) {
                dependency.install(stackCallback);
            });
        });

        // TODO: If parralell limit > 2, then error in git clone
        async.parallelLimit(stack, 1, function (err) {
            callback(err, dependencies);
        });
    })
};

Project.prototype.update = function (callback) {
    callback = callback || function () {
    };

    this._analyse(function (err, dependencies) {
        if (err) {
            return callback(err);
        }

        var stack = [];

        mout.array.forEach(dependencies, function (dependency) {
            stack.push(function (stackCallback) {
                dependency.update(stackCallback);
            });
        });

        async.parallelLimit(stack, 5, function (err) {
            callback(err, dependencies);
        });
    })
};

Project.prototype.status = function (callback) {
    callback = callback || function () {
    };

    this._analyse(function (err, dependencies) {
        if (err) {
            return callback(err);
        }

        var stack = [];

        mout.array.forEach(dependencies, function (dependency) {
            stack.push(function (stackCallback) {
                dependency.status(stackCallback);
            });
        });

        async.parallelLimit(stack, 5, function (err) {
            callback(err, dependencies);
        });
    })
};

Project.prototype.grunt = function (callback) {
    callback = callback || function () {
    };

    this._analyse(function (err, dependencies) {
        if (err) {
            return callback(err);
        }

        var stack = [];

        mout.array.forEach(dependencies, function (dependency) {
            stack.push(function (stackCallback) {
                dependency.grunt(stackCallback);
            });
        });

        async.series(stack, function (err) {
            callback(err, dependencies);
        });

    })
};


// -----------------------

Project.prototype._analyse = function (callback) {
    var __self = this;

    async.series([
        function (asyncCallback) {
            __self._readMultikJson(asyncCallback)
        },
        function (asyncCallback) {
            __self._buildDependencies(asyncCallback);
        }
    ], function (err) {
        if (callback) {
            callback(err, __self._dependencies);
        }
    });
};

Project.prototype._readMultikJson = function (callback) {
    if (this._json) {
        return callback(null, this._json);
{'fraction_non_alphanumeric': 0.14090571640683, 'fraction_numerical': 0.0013363028953229399, 'mean_word_length': 2.0342342342342343, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4184015', 'n_tokens_mistral': 1845, 'n_tokens_neox': 1765, 'n_words': 372}