format: prettify entire project
This commit is contained in:
7
node_modules/rc/browser.js
generated
vendored
7
node_modules/rc/browser.js
generated
vendored
@ -1,7 +1,6 @@
|
||||
|
||||
// when this is loaded into the browser,
|
||||
// when this is loaded into the browser,
|
||||
// just use the defaults...
|
||||
|
||||
module.exports = function (name, defaults) {
|
||||
return defaults
|
||||
}
|
||||
return defaults;
|
||||
};
|
||||
|
4
node_modules/rc/cli.js
generated
vendored
4
node_modules/rc/cli.js
generated
vendored
@ -1,4 +1,4 @@
|
||||
#! /usr/bin/env node
|
||||
var rc = require('./index')
|
||||
var rc = require('./index');
|
||||
|
||||
console.log(JSON.stringify(rc(process.argv[2]), false, 2))
|
||||
console.log(JSON.stringify(rc(process.argv[2]), false, 2));
|
||||
|
81
node_modules/rc/index.js
generated
vendored
81
node_modules/rc/index.js
generated
vendored
@ -1,53 +1,54 @@
|
||||
var cc = require('./lib/utils')
|
||||
var join = require('path').join
|
||||
var deepExtend = require('deep-extend')
|
||||
var etc = '/etc'
|
||||
var win = process.platform === "win32"
|
||||
var home = win
|
||||
? process.env.USERPROFILE
|
||||
: process.env.HOME
|
||||
var cc = require('./lib/utils');
|
||||
var join = require('path').join;
|
||||
var deepExtend = require('deep-extend');
|
||||
var etc = '/etc';
|
||||
var win = process.platform === 'win32';
|
||||
var home = win ? process.env.USERPROFILE : process.env.HOME;
|
||||
|
||||
module.exports = function (name, defaults, argv, parse) {
|
||||
if('string' !== typeof name)
|
||||
throw new Error('rc(name): name *must* be string')
|
||||
if(!argv)
|
||||
argv = require('minimist')(process.argv.slice(2))
|
||||
defaults = (
|
||||
'string' === typeof defaults
|
||||
? cc.json(defaults) : defaults
|
||||
) || {}
|
||||
if ('string' !== typeof name)
|
||||
throw new Error('rc(name): name *must* be string');
|
||||
if (!argv) argv = require('minimist')(process.argv.slice(2));
|
||||
defaults =
|
||||
('string' === typeof defaults ? cc.json(defaults) : defaults) || {};
|
||||
|
||||
parse = parse || cc.parse
|
||||
parse = parse || cc.parse;
|
||||
|
||||
var env = cc.env(name + '_')
|
||||
var env = cc.env(name + '_');
|
||||
|
||||
var configs = [defaults]
|
||||
var configFiles = []
|
||||
function addConfigFile (file) {
|
||||
if (configFiles.indexOf(file) >= 0) return
|
||||
var fileConfig = cc.file(file)
|
||||
var configs = [defaults];
|
||||
var configFiles = [];
|
||||
function addConfigFile(file) {
|
||||
if (configFiles.indexOf(file) >= 0) return;
|
||||
var fileConfig = cc.file(file);
|
||||
if (fileConfig) {
|
||||
configs.push(parse(fileConfig))
|
||||
configFiles.push(file)
|
||||
configs.push(parse(fileConfig));
|
||||
configFiles.push(file);
|
||||
}
|
||||
}
|
||||
|
||||
// which files do we look at?
|
||||
if (!win)
|
||||
[join(etc, name, 'config'),
|
||||
join(etc, name + 'rc')].forEach(addConfigFile)
|
||||
[join(etc, name, 'config'), join(etc, name + 'rc')].forEach(addConfigFile);
|
||||
if (home)
|
||||
[join(home, '.config', name, 'config'),
|
||||
join(home, '.config', name),
|
||||
join(home, '.' + name, 'config'),
|
||||
join(home, '.' + name + 'rc')].forEach(addConfigFile)
|
||||
addConfigFile(cc.find('.'+name+'rc'))
|
||||
if (env.config) addConfigFile(env.config)
|
||||
if (argv.config) addConfigFile(argv.config)
|
||||
[
|
||||
join(home, '.config', name, 'config'),
|
||||
join(home, '.config', name),
|
||||
join(home, '.' + name, 'config'),
|
||||
join(home, '.' + name + 'rc'),
|
||||
].forEach(addConfigFile);
|
||||
addConfigFile(cc.find('.' + name + 'rc'));
|
||||
if (env.config) addConfigFile(env.config);
|
||||
if (argv.config) addConfigFile(argv.config);
|
||||
|
||||
return deepExtend.apply(null, configs.concat([
|
||||
env,
|
||||
argv,
|
||||
configFiles.length ? {configs: configFiles, config: configFiles[configFiles.length - 1]} : undefined,
|
||||
]))
|
||||
}
|
||||
return deepExtend.apply(
|
||||
null,
|
||||
configs.concat([
|
||||
env,
|
||||
argv,
|
||||
configFiles.length ?
|
||||
{ configs: configFiles, config: configFiles[configFiles.length - 1] }
|
||||
: undefined,
|
||||
])
|
||||
);
|
||||
};
|
||||
|
115
node_modules/rc/lib/utils.js
generated
vendored
115
node_modules/rc/lib/utils.js
generated
vendored
@ -1,104 +1,91 @@
|
||||
'use strict';
|
||||
var fs = require('fs')
|
||||
var ini = require('ini')
|
||||
var path = require('path')
|
||||
var stripJsonComments = require('strip-json-comments')
|
||||
|
||||
var parse = exports.parse = function (content) {
|
||||
var fs = require('fs');
|
||||
var ini = require('ini');
|
||||
var path = require('path');
|
||||
var stripJsonComments = require('strip-json-comments');
|
||||
|
||||
var parse = (exports.parse = function (content) {
|
||||
//if it ends in .json or starts with { then it must be json.
|
||||
//must be done this way, because ini accepts everything.
|
||||
//can't just try and parse it and let it throw if it's not ini.
|
||||
//everything is ini. even json with a syntax error.
|
||||
|
||||
if(/^\s*{/.test(content))
|
||||
return JSON.parse(stripJsonComments(content))
|
||||
return ini.parse(content)
|
||||
if (/^\s*{/.test(content)) return JSON.parse(stripJsonComments(content));
|
||||
return ini.parse(content);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
var file = exports.file = function () {
|
||||
var args = [].slice.call(arguments).filter(function (arg) { return arg != null })
|
||||
var file = (exports.file = function () {
|
||||
var args = [].slice.call(arguments).filter(function (arg) {
|
||||
return arg != null;
|
||||
});
|
||||
|
||||
//path.join breaks if it's a not a string, so just skip this.
|
||||
for(var i in args)
|
||||
if('string' !== typeof args[i])
|
||||
return
|
||||
for (var i in args) if ('string' !== typeof args[i]) return;
|
||||
|
||||
var file = path.join.apply(null, args)
|
||||
var content
|
||||
var file = path.join.apply(null, args);
|
||||
var content;
|
||||
try {
|
||||
return fs.readFileSync(file,'utf-8')
|
||||
return fs.readFileSync(file, 'utf-8');
|
||||
} catch (err) {
|
||||
return
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var json = exports.json = function () {
|
||||
var content = file.apply(null, arguments)
|
||||
return content ? parse(content) : null
|
||||
}
|
||||
var json = (exports.json = function () {
|
||||
var content = file.apply(null, arguments);
|
||||
return content ? parse(content) : null;
|
||||
});
|
||||
|
||||
var env = exports.env = function (prefix, env) {
|
||||
env = env || process.env
|
||||
var obj = {}
|
||||
var l = prefix.length
|
||||
for(var k in env) {
|
||||
if(k.toLowerCase().indexOf(prefix.toLowerCase()) === 0) {
|
||||
|
||||
var keypath = k.substring(l).split('__')
|
||||
var env = (exports.env = function (prefix, env) {
|
||||
env = env || process.env;
|
||||
var obj = {};
|
||||
var l = prefix.length;
|
||||
for (var k in env) {
|
||||
if (k.toLowerCase().indexOf(prefix.toLowerCase()) === 0) {
|
||||
var keypath = k.substring(l).split('__');
|
||||
|
||||
// Trim empty strings from keypath array
|
||||
var _emptyStringIndex
|
||||
while ((_emptyStringIndex=keypath.indexOf('')) > -1) {
|
||||
keypath.splice(_emptyStringIndex, 1)
|
||||
var _emptyStringIndex;
|
||||
while ((_emptyStringIndex = keypath.indexOf('')) > -1) {
|
||||
keypath.splice(_emptyStringIndex, 1);
|
||||
}
|
||||
|
||||
var cursor = obj
|
||||
keypath.forEach(function _buildSubObj(_subkey,i){
|
||||
|
||||
var cursor = obj;
|
||||
keypath.forEach(function _buildSubObj(_subkey, i) {
|
||||
// (check for _subkey first so we ignore empty strings)
|
||||
// (check for cursor to avoid assignment to primitive objects)
|
||||
if (!_subkey || typeof cursor !== 'object')
|
||||
return
|
||||
if (!_subkey || typeof cursor !== 'object') return;
|
||||
|
||||
// If this is the last key, just stuff the value in there
|
||||
// Assigns actual value from env variable to final key
|
||||
// (unless it's just an empty string- in that case use the last valid key)
|
||||
if (i === keypath.length-1)
|
||||
cursor[_subkey] = env[k]
|
||||
|
||||
if (i === keypath.length - 1) cursor[_subkey] = env[k];
|
||||
|
||||
// Build sub-object if nothing already exists at the keypath
|
||||
if (cursor[_subkey] === undefined)
|
||||
cursor[_subkey] = {}
|
||||
if (cursor[_subkey] === undefined) cursor[_subkey] = {};
|
||||
|
||||
// Increment cursor used to track the object at the current depth
|
||||
cursor = cursor[_subkey]
|
||||
|
||||
})
|
||||
|
||||
cursor = cursor[_subkey];
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return obj
|
||||
}
|
||||
return obj;
|
||||
});
|
||||
|
||||
var find = exports.find = function () {
|
||||
var rel = path.join.apply(null, [].slice.call(arguments))
|
||||
var find = (exports.find = function () {
|
||||
var rel = path.join.apply(null, [].slice.call(arguments));
|
||||
|
||||
function find(start, rel) {
|
||||
var file = path.join(start, rel)
|
||||
var file = path.join(start, rel);
|
||||
try {
|
||||
fs.statSync(file)
|
||||
return file
|
||||
fs.statSync(file);
|
||||
return file;
|
||||
} catch (err) {
|
||||
if(path.dirname(start) !== start) // root
|
||||
return find(path.dirname(start), rel)
|
||||
if (path.dirname(start) !== start)
|
||||
// root
|
||||
return find(path.dirname(start), rel);
|
||||
}
|
||||
}
|
||||
return find(process.cwd(), rel)
|
||||
}
|
||||
|
||||
|
||||
return find(process.cwd(), rel);
|
||||
});
|
||||
|
Reference in New Issue
Block a user