{"size": 1981, "ext": "js", "max_stars_repo_path": "src/lib/settings.js", "max_stars_repo_name": "shukriadams/trusty-daemon", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/lib/settings.js", "max_issues_repo_name": "shukriadams/trusty-daemon", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/lib/settings.js", "max_forks_repo_name": "shukriadams/trusty-daemon", "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": 30.953125, "max_line_length": 117, "alphanum_fraction": 0.4644119132}
let fs = require('fs-extra'),
    yaml = require('js-yaml'),
    sanitize = require('sanitize-filename'),
    _settings = null;

module.exports = {
    get : async function(forceRead){

        if (!_settings || forceRead === true){
            let rawSettings = null;

            try {
                let settingsYML = await fs.readFile('./settings.yml', 'utf8');
                rawSettings = yaml.safeLoad(settingsYML);
            } catch (e) {
                console.log('Error reading settings.yml');
                console.log(e);
                throw e;
            }
            
            // force default structures
            rawSettings = Object.assign({
                version : 1,
                port: 3000,
                logPath : './logs',
                operationLog : './jobs',
                timeout: 600000, // timeout of http calls. default is 10 minutes. Set to 0 to disable.
                onstart : null,
                jobs : {}
            }, rawSettings);
    
            for (const jobName in rawSettings.jobs){

                let job = rawSettings.jobs[jobName];

                rawSettings.jobs[jobName] = Object.assign({
                    
                    __name : jobName,

                    __safeName : sanitize(jobName),

                    // enabled field is optional, is always one by default
                    enabled : true,
                    
                    // stderr output with "warning" in them will be ignored. Experimental and not entirely robust, so
                    // disabled by default
                    ignoreWarnings : false,

                    // shell command to run
                    command : '',

                    // if true, all console out will be written to log. This can bloat your logs, so use carefully
                    logResults : false

                }, job);
            }

            _settings = rawSettings;
        }

        return _settings;
    }
};
