Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
// which files do we look at?
if (!win)
[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)
return deepExtend.apply(null, configs.concat([
env,
argv,
configFiles.length ? {configs: configFiles, config: configFiles[configFiles.length - 1]} : null,
]))
}
}
// which files do we look at?
if (!win)
[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)
return deepExtend.apply(null, configs.concat([
env,
argv,
configFiles.length ? {configs: configFiles, config: configFiles[configFiles.length - 1]} : undefined,
]))
}
}
// which files do we look at?
if (!win)
[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)
return deepExtend.apply(null, configs.concat([
env,
argv,
configFiles.length ? {configs: configFiles, config: configFiles[configFiles.length - 1]} : undefined,
]))
}
}
// which files do we look at?
if (!win)
[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)
return deepExtend.apply(null, configs.concat([
env,
argv,
configFiles.length ? {configs: configFiles, config: configFiles[configFiles.length - 1]} : undefined,
]))
}
let l10nFiles;
try {
l10nFiles = lsSync(this.config.l10n, 0);
} catch (e) {
logger.fatal(`Unable to find the localization data file ${this.config.l10nFile}`);
return this;
}
l10nFiles.forEach(filepath => {
l10nData.push(loadYaml(filepath));
});
// Merge the objects in reverse order so that the first one loaded wins.
this._l10nData = deepExtend.apply(deepExtend, l10nData.reverse());
this._l10nFormatter = new MessageFormat(this.locale).compile(this._l10nData);
return this;
}
}
// which files do we look at?
if (!win)
[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)
return deepExtend.apply(null, configs.concat([
env,
argv,
configFiles.length ? {configs: configFiles, config: configFiles[configFiles.length - 1]} : undefined,
]))
}
function getTranslations(lang) {
var langFiles = [
paths.join(constants.path.defaultDir, "lang", "en.json"),
paths.join(constants.path.defaultDir, "lang", lang + ".json"),
paths.join(constants.path.userData, "lang", lang + ".json")
],
translations = [];
langFiles.forEach(function(file) {
try {
var fileContent = fs.readFileSync(file, 'utf8');
translations.push(JSON.parse(fileContent));
} catch (err) {
console.warn("Error while loading localization data: " + err);
}
});
return deepExtend.apply(this, translations);
}
module.exports = function (name, defaults, argv) {
if(!name)
throw new Error('nameless configuration fail')
if(!argv)
argv = require('minimist')(process.argv.slice(2))
defaults = (
'string' === typeof defaults
? cc.json(defaults) : defaults
) || {}
var local = cc.find('.'+name+'rc')
return deepExtend.apply(null, [
defaults,
win ? {} : cc.json(join(etc, name, 'config')),
win ? {} : cc.json(join(etc, name + 'rc')),
home ? cc.json(join(home, '.config', name, 'config')) : {},
home ? cc.json(join(home, '.config', name)) : {},
home ? cc.json(join(home, '.' + name, 'config')) : {},
home ? cc.json(join(home, '.' + name + 'rc')) : {},
cc.json(local || argv.config),
local ? {config: local} : null,
cc.env(name + '_'),
argv
])
}
module.exports = function (name, defaults, argv) {
if(!name)
throw new Error('nameless configuration fail')
if(!argv)
argv = require('minimist')(process.argv.slice(2))
defaults = (
'string' === typeof defaults
? cc.json(defaults) : defaults
) || {}
var local = cc.find('.'+name+'rc')
return deepExtend.apply(null, [
defaults,
win ? {} : cc.json(join(etc, name, 'config')),
win ? {} : cc.json(join(etc, name + 'rc')),
home ? cc.json(join(home, '.config', name, 'config')) : {},
home ? cc.json(join(home, '.config', name)) : {},
home ? cc.json(join(home, '.' + name, 'config')) : {},
home ? cc.json(join(home, '.' + name + 'rc')) : {},
cc.json(local || argv.config),
local ? {config: local} : null,
cc.env(name + '_'),
argv
])
}