GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — config/index.js at master · histograph/config Expand file tree/ Copy pathindex.jsMore file actions 64 lines (55 loc) · 1.99 KB / Copy pathindex.jsFile metadata and controls64 lines (55 loc) · 1.99 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 var _ = require('lodash'); var fs = require('fs'); var path = require('path'); var util = require('util'); var validator = require('is-my-json-valid'); var yaml = require('js-yaml'); var argv = require('minimist')(process.argv.slice(2)); module.exports = (function() { var config, data, files, schema, schemaFile, validate; var configFile = argv.config || process.env.HISTOGRAPH_CONFIG; var configDir = argv['config-dir'] || process.env.HISTOGRAPH_CONFIG_DIR; if (configDir) { files = [ path.join(configDir, 'default.yml'), path.join(configDir, 'local.yml') ]; schemaFile = path.join(configDir, 'config.schema.json'); } else if (configFile) { files = [ path.join(__dirname, 'histograph.default.yml'), configFile ]; schemaFile = path.join(__dirname, 'config.schema.json'); } else { throw new Error('Please specify location of your user configuration in environment variable `HISTOGRAPH_CONFIG` or `HISTOGRAPH_CONFIG_DIR`, or use the `--config` or `--config-dir` command line option'); } data = files.map(function(file) { try { return yaml.safeLoad(fs.readFileSync(file, 'utf8')); } catch (err) { throw new Error(util.format('Can’t open configuration file `%s` due to: `%s`', file, err.message)); } }); // Merge default config file with user config // However, arrays should not be merged - all arrays in default config which are // also in userConfig should be emptied first config = _.merge(data[0], data[1], function(a, b) { if (_.isArray(a)) { return b; } }); try { schema = fs.readFileSync(schemaFile, 'utf8'); } catch (err) { throw new Error(util.format('Can’t open schema file `%s` due to: `%s`', schemaFile, err.message)); } validate = validator(schema); if (validate(config)) { return config; } else { throw new Error('Invalid configuration file: ' + validate.errors.map(function (err) { return '\n - ' + err.field + ' ' + err.message; }).join('')); } }()); |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |