Use mapValuesDeep vs reduceDeep
This commit is contained in:
parent
9394730011
commit
43a7bd9ba4
|
@ -3,7 +3,7 @@ const paths = require('path');
|
||||||
const async = require('async');
|
const async = require('async');
|
||||||
|
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const reduceDeep = require('deepdash/getReduceDeep')(_);
|
const mapValuesDeep = require('deepdash/getMapValuesDeep')(_);
|
||||||
|
|
||||||
module.exports = class ConfigLoader {
|
module.exports = class ConfigLoader {
|
||||||
constructor(
|
constructor(
|
||||||
|
@ -218,26 +218,19 @@ module.exports = class ConfigLoader {
|
||||||
}
|
}
|
||||||
|
|
||||||
_resolveAtSpecs(config) {
|
_resolveAtSpecs(config) {
|
||||||
// :TODO: mapValuesDeep may be better here
|
return mapValuesDeep(
|
||||||
return reduceDeep(
|
|
||||||
config,
|
config,
|
||||||
(acc, value, key, parent, ctx) => {
|
value => {
|
||||||
// resolve self references; there may be a better way...
|
|
||||||
if (_.isString(value) && '@' === value.charAt(0)) {
|
if (_.isString(value) && '@' === value.charAt(0)) {
|
||||||
if (value.startsWith('@reference:')) {
|
if (value.startsWith('@reference:')) {
|
||||||
value = value.slice(11);
|
const refPath = value.slice(11);
|
||||||
const ref = _.get(acc, value);
|
value = _.get(config, refPath, value);
|
||||||
if (ref) {
|
|
||||||
_.set(acc, ctx.path, ref);
|
|
||||||
}
|
|
||||||
} else if (value.startsWith('@environment:')) {
|
} else if (value.startsWith('@environment:')) {
|
||||||
value = this._resolveEnvironmentVariable(value);
|
value = this._resolveEnvironmentVariable(value) || value;
|
||||||
if (!_.isUndefined(value)) {
|
|
||||||
_.set(acc, ctx.path, value);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return acc;
|
return value;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue