<commit_before>'use strict';

let fs = require('fs');
let path = require('path');
let resolvePath = path.resolve;
let basename = path.basename;
let _ = require('lodash');
let globSync = require('glob').sync;
let moment = require('moment');
let mkdirpSync = require('mkdirp').sync;

function jsonStringify(value) {
    return JSON.stringify(value, null, 4);
}

module.exports = function() {
    let handlers = globSync('handlers/*.process.js').map(function(handlerPath) {
        return require(resolvePath(handlerPath));
    });

    let context = (function() {
        let contextFilePath = process.cwd() + '/genesis.json';

        if(fs.existsSync(contextFilePath)) {
            return require(contextFilePath);
        }
        else {
            return {};
        }
    })();

    let currentSnapshotsDirectory = moment().format('YYYY-MM-DD HH-mm-ss');
    let currentSnapshotsPath = 'snapshots/' + currentSnapshotsDirectory;

    mkdirpSync(currentSnapshotsPath);

    let events = globSync('!(genesis).json').map(function(eventPath) {
        return require(resolvePath(eventPath));
    });

    events.forEach(function(event) {
        _.each(handlers, function(handler) {
            handler.call(context, event);
        });

        let currentSnapshotPath = (
            currentSnapshotsPath + '/' +
            event.moment.format('YYYY-MM-DD HH-mm-ss') + '.json'
        );

        fs.writeFileSync(currentSnapshotPath, jsonStringify(context));
    });

    let latestSnapshotsPath = 'snapshots/latest';

    if(fs.existsSync(latestSnapshotsPath)) {
        fs.unlinkSync(latestSnapshotsPath);
    }<commit_msg>Add event.dateTime property based on event file name.<commit_after>'use strict';

let fs = require('fs');
let path = require('path');
let resolvePath = path.resolve;
let basename = path.basename;
let _ = require('lodash');
let globSync = require('glob').sync;
let moment = require('moment');
let mkdirpSync = require('mkdirp').sync;

function jsonStringify(value) {
    return JSON.stringify(value, null, 4);
}

module.exports = function() {
    let handlers = globSync('handlers/*.process.js').map(function(handlerPath) {
        return require(resolvePath(handlerPath));
    });

    let context = (function() {
        let contextFilePath = process.cwd() + '/genesis.json';

        if(fs.existsSync(contextFilePath)) {
            return require(contextFilePath);
        }
        else {
            return {};
        }
    })();

    let currentSnapshotsDirectory = moment().format('YYYY-MM-DD HH-mm-ss');
    let currentSnapshotsPath = 'snapshots/' + currentSnapshotsDirectory;

    mkdirpSync(currentSnapshotsPath);

    let events = globSync('!(genesis).json').map(function(eventPath) {
        let event = require(resolvePath(eventPath));

        event.dateTime = basename(eventPath, '.json');

        return event;
    });

    events.forEach(function(event) {
        _.each(handlers, function(handler) {
            handler.call(context, event);
        });

        let currentSnapshotPath = (
            currentSnapshotsPath + '/' + event.dateTime + '.json'
        );

        delete event.dateTime;

        fs.writeFileSync(currentSnapshotPath, jsonStringify(context));
    });

    let latestSnapshotsPath = 'snapshots/latest';

    if(fs.existsSync(latestSnapshotsPath)) {
        fs.unlinkSync(latestSnapshotsPath);
    }
{'fraction_non_alphanumeric': 0.14040284360189573, 'fraction_numerical': 0.0005924170616113745, 'mean_word_length': 3.04916067146283, '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': '3171223', 'n_tokens_mistral': 1006, 'n_tokens_neox': 964, 'n_words': 178}