mirror of
https://github.com/jsbin/jsbin.git
synced 2026-01-18 15:18:04 +00:00
45 lines
1.4 KiB
JavaScript
45 lines
1.4 KiB
JavaScript
var fs = require('fs'),
|
|
path = require('path'),
|
|
existsSync = fs.existsSync || path.existsSync, // yeah folks, have some of that.
|
|
localconfig = path.resolve(__dirname, '..', 'config.local.json');
|
|
|
|
if (!process.env.JSBIN_CONFIG && process.argv[2]) {
|
|
process.env.JSBIN_CONFIG = process.argv[2];
|
|
}
|
|
|
|
// If a custom config is passed in, resolve its path
|
|
if (process.env.JSBIN_CONFIG) {
|
|
localconfig = path.resolve(process.cwd(), process.env.JSBIN_CONFIG);
|
|
}
|
|
|
|
|
|
// Loads the configuration options from the config.*.json files.
|
|
//
|
|
// By default load the contents of config.default.json, these keys can be
|
|
// over-ridden by providing a user config.local.json file with any keys that
|
|
// you wish to override.
|
|
//
|
|
// It is also possible to define your own config file by passing an absolute
|
|
// path to the file as the JSBIN_CONFIG environment variable.
|
|
//
|
|
// Example:
|
|
//
|
|
// $ JSBIN_CONFIG=/path/to/config.js jsbin
|
|
module.exports = require('../config.default.json');
|
|
|
|
function deepExtend(target, object) {
|
|
Object.getOwnPropertyNames(object).forEach(function (key) {
|
|
var value = object[key];
|
|
|
|
if (typeof value === "object" && value !== null && !Array.isArray(value)) {
|
|
target[key] = deepExtend(target[key] || {}, value);
|
|
} else {
|
|
target[key] = value;
|
|
}
|
|
});
|
|
return target;
|
|
}
|
|
|
|
if (existsSync(localconfig)) {
|
|
deepExtend(module.exports, require(localconfig));
|
|
} |