{"size": 861, "ext": "js", "max_stars_repo_path": "server/controllers/settings.js", "max_stars_repo_name": "doubletapgames/RobloxVersionControl", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "server/controllers/settings.js", "max_issues_repo_name": "doubletapgames/RobloxVersionControl", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "server/controllers/settings.js", "max_forks_repo_name": "doubletapgames/RobloxVersionControl", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 27.7741935484, "max_line_length": 99, "alphanum_fraction": 0.643437863}
const fs = require('fs');
const path = require('path');
const Event = require('../models/event');

const settingsPath = path.join(path.dirname(process.mainModule.filename), 'data', 'settings.json');
const settingsChanged = new Event();

const getSettings = (callback) => {
    fs.readFile(settingsPath, (err, fileContentBuffer) => {
        if (err) {
            console.log(err);
            throw new Error('Could not read file: [data/settings.json]. Is it missing?');
        } else {
            callback(JSON.parse(fileContentBuffer));
        }
    })
}

const setSettings = (settings) => {
    fs.writeFile(settingsPath, JSON.stringify(settings), (err) => {
        console.log(err);
    });

    exports.settings = settings;
    settingsChanged.fire(settings)
}


// exports
exports.getSettings = getSettings;
exports.settingsChanged = settingsChanged;