<commit_before>'use strict';

// Native module(s)
var fs   = require('fs');
var os   = require('os');
var path = require('path');

// npm module(s)
var Bottle     = require('bottlejs');
var Connection = require('ssh2');

var bottle = new Bottle();
var conn   = new Connection();

const EOL = os.EOL;

// Packages we'll (eventually) be installing via `apt-get`
var packages = [
    'apache2',
    'apache2-mpm-worker',
    'php5-fpm',
    'php5-cli',
    'php5-phalcon',
    'php5-mysql',
    'git'
];

var paths = {
    config: './config'
};

paths.targetsConfig = paths.config + '/targets';

var targets = fs.readdirSync(paths.targetsConfig)

    // Get a list of JSON files
    .filter(function (file) {
        return path.extname(file) === '.json';
    })

    // Return an array of the JSON objects
    .map(function (file) {
        return require(paths.targetsConfig + '/' + file);
    });

console.log('[TARGETS]', os.EOL, targets, os.EOL);

var target = targets.shift();

console.log('[TARGET]', os.EOL, target, os.EOL);

var queue = ['ls', 'ls -la', 'ls -lh'];

///// return;

/**
 * The code below won't work unless you provide a valid target config object!
 * e.g.
 *
 * ```js
 * {
 *     "host": "domain.com",
 *     "post": 22,
 *     "username": "example-user",
 *     "password": "<PASSWORD>"
 * }
 * ```
 */
conn.on('ready', function () {
    console.log('Connection :: ready');

    var cb = (function () {
        console.log('Executing `' + cmd + '`')
        conn.exec(cmd, function(err, stream) {
            if (err) throw err;
            stream.on('exit', function(code, signal) {
                signal = signal || '[NO SIGNAL]';
                console.log('Stream :: exit :: code: ' + code + ', signal: ' + signal);
            }).on('close', function() {
                cmd = queue.shift();
                console.log('Stream :: close');

                if (!cmd) {
                    console.log('Ending connection now.');
                    conn.end();
                } else {
                    console.log('Triggering callback.');
                    cb();
                }
                console.log(os.EOL);
            }).on('data', function(data) {
                console.log('STDOUT: ' + os.EOL + data);
            }).stderr.on('data', function(data) {
                console.log('STDERR: ' + os.EOL  + data);
            });
        });
    }).bind(this);

    var cmd = queue.shift();

    if (!cmd) return;

    cb();
})
.connect(target);<commit_msg>Minor formatting tweakings.<commit_after>'use strict';

// Native module(s)
var fs   = require('fs');
var os   = require('os');
var path = require('path');

// npm module(s)
var Bottle     = require('bottlejs');
var Connection = require('ssh2');

var bottle = new Bottle();
var conn   = new Connection();

const EOL = os.EOL;

// Packages we'll (eventually) be installing via `apt-get`
var packages = [
    'apache2',
    'apache2-mpm-worker',
    'php5-fpm',
    'php5-cli',
    'php5-phalcon',
    'php5-mysql',
    'git'
];

var paths = {
    config: './config'
};

paths.targetsConfig = paths.config + '/targets';

var targets = fs.readdirSync(paths.targetsConfig)

    // Get a list of JSON files
    .filter(function (file) {
        return path.extname(file) === '.json';
    })

    // Return an array of the JSON objects
    .map(function (file) {
        return require(paths.targetsConfig + '/' + file);
    });

console.log('[TARGETS]', EOL, targets, EOL);

var target = targets.shift();

console.log('[TARGET]', EOL, target, EOL);

var queue = ['ls', 'ls -la', 'ls -lh'];

///// return;

/**
 * The code below won't work unless you provide a valid target config object!
 * e.g.
 *
 * ```js
 * {
 *     "host": "domain.com",
 *     "post": 22,
 *     "username": "example-user",
 *     "password": "<PASSWORD>"
 * }
 * ```
 */
conn.on('ready', function () {
    console.log('Connection :: ready');

    var cb = (function () {
        console.log('Executing `' + cmd + '`')
        conn.exec(cmd, function(err, stream) {
            if (err) throw err;
            stream.on('exit', function(code, signal) {
                signal = signal || '[NO SIGNAL]';
                console.log('Stream :: exit :: code: ' + code + ', signal: ' + signal);
            }).on('close', function() {
                cmd = queue.shift();
                console.log('Stream :: close');

                if (!cmd) {
                    console.log('Ending connection now.');
                    conn.end();
                } else {
                    console.log('Triggering callback.');
                    cb();
                }

                console.log(EOL);
            }).on('data', function(data) {
                console.log('STDOUT: ' + EOL + data);
            }).stderr.on('data', function(data) {
                console.log('STDERR: ' + EOL  + data);
            });
        });
    }).bind(this);

    var cmd = queue.shift();

    if (!cmd) return;

    cb();
})
.connect(target);
{'fraction_non_alphanumeric': 0.1832, 'fraction_numerical': 0.0036, 'mean_word_length': 1.959171597633136, 'pattern_counts': {'":': 8, '<': 5, '<?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': '5333425', 'n_tokens_mistral': 1620, 'n_tokens_neox': 1548, 'n_words': 377}