<commit_before>/*globals define*/
/*
 * This is the basic structure for component managers
 *
 * In the component manager, all public functions (functions not preceded by a _)
 * are assumed to be actions accepted from the command line.
 *
 * Note: "init" is a reserved action and cannot be used by the ComponentManager
 */

'use strict';

var utils = require('./utils'),
    rm_rf = require('rimraf'),
    plural = require('plural'),
    fs = require('fs'),
    path = require('path'),
    childProcess = require('child_process'),
    spawn = childProcess.spawn,
    Logger = require(__dirname + '/Logger');

var ComponentManager = function(name, logger) {
    this._logger = logger || new Logger();
    this._name = name;  // Name to be used in cli usage, etc
    this._group = plural(name);  // Plural version of name
    this._webgmeName = name;  // Name to be used only in webgme config
    this._prepareWebGmeConfig();

    var next;
    for (var action in this) {
        if (action[0] !== '_') {
            next = this[action].bind(this);
            this[action] = this._preprocess.bind(this, next);
        }
    }
};

ComponentManager.prototype._preprocess = function(next, args, callback) {
    // Check for project directory
    if (utils.getRootPath() === null) {
        var err = 'Could not find a project in current or any parent directories';
        this._logger.error(err);
        return callback(err);
    }
    this._prepareWebGmeConfig();
    next(args, callback);
};

/**
 * List the currently recognized components.
 *
 * @param args
 * @param callback
 * @return {undefined}
 */
ComponentManager.prototype.ls = function(args, callback) {
    var config = utils.getConfig(),
        plugins = Object.keys(config.components[this._group]).join(' ') || '<none>',
        deps = Object.keys(config.dependencies[this._group]).join(' ') || '<none>';

    this._logger.write('Detected '+this._group+': '+plugins+
        '\nThird party '+this._group+': '+deps);
    callback(null, {components: plugins, dependencies: deps});
};

ComponentManager.prototype.rm = function(args, callback) {
    var name = args.name,
        config = utils.getConfig(),
        type = config.components[this._group][name] !== undefined ? 
            'components' : 'dependencies',
        record = config[type][this._group][name];

    // Remove from config files
    this._removeFromConfig(name, type);

    // Remove any actual files
    if (type === 'components') {
        // Remove the name directories from src, test
        var paths,
            remaining,
            finished;

        paths = Object.keys(record)
            .filter(key => {
                return fs.existsSync(record[key]);
            });
        remaining = paths.length;
        finished = function() {
            if (--remaining === 0) {
                return callback();
            }
        };
<commit_msg>Cleaned ls formatting. Fixes #101<commit_after>/*globals define*/
/*
 * This is the basic structure for component managers
 *
 * In the component manager, all public functions (functions not preceded by a _)
 * are assumed to be actions accepted from the command line.
 *
 * Note: "init" is a reserved action and cannot be used by the ComponentManager
 */

'use strict';

var utils = require('./utils'),
    rm_rf = require('rimraf'),
    plural = require('plural'),
    fs = require('fs'),
    path = require('path'),
    childProcess = require('child_process'),
    spawn = childProcess.spawn,
    Logger = require(__dirname + '/Logger');

var ComponentManager = function(name, logger) {
    this._logger = logger || new Logger();
    this._name = name;  // Name to be used in cli usage, etc
    this._group = plural(name);  // Plural version of name
    this._webgmeName = name;  // Name to be used only in webgme config
    this._prepareWebGmeConfig();

    var next;
    for (var action in this) {
        if (action[0] !== '_') {
            next = this[action].bind(this);
            this[action] = this._preprocess.bind(this, next);
        }
    }
};

ComponentManager.prototype._preprocess = function(next, args, callback) {
    // Check for project directory
    if (utils.getRootPath() === null) {
        var err = 'Could not find a project in current or any parent directories';
        this._logger.error(err);
        return callback(err);
    }
    this._prepareWebGmeConfig();
    next(args, callback);
};

/**
 * List the currently recognized components.
 *
 * @param args
 * @param callback
 * @return {undefined}
 */
ComponentManager.prototype.ls = function(args, callback) {
    var config = utils.getConfig(),
        components = Object.keys(config.components[this._group]).join(' ') || '<none>',
        deps = Object.keys(config.dependencies[this._group]).join(' ') || '<none>';

    this._logger.write(
        this._group+':\n' +
            '    local: ' + components + '\n' +
            '    dependencies: ' + deps + '\n'
    );
    callback(null, {components: components, dependencies: deps});
};

ComponentManager.prototype.rm = function(args, callback) {
    var name = args.name,
        config = utils.getConfig(),
        type = config.components[this._group][name] !== undefined ? 
            'components' : 'dependencies',
        record = config[type][this._group][name];

    // Remove from config files
    this._removeFromConfig(name, type);

    // Remove any actual files
    if (type === 'components') {
        // Remove the name directories from src, test
        var paths,
            remaining,
            finished;

        paths = Object.keys(record)
            .filter(key => {
                return fs.existsSync(record[key]);
            });
        remaining = paths.length;
        finished = function() {
            if (--remaining === 0) {
                return callback();
            }
        };

{'fraction_non_alphanumeric': 0.13510747185261002, 'fraction_numerical': 0.001194131695667008, 'mean_word_length': 2.5255562236921225, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '6476328', 'n_tokens_mistral': 1628, 'n_tokens_neox': 1605, 'n_words': 471}