Don't do any merging of config values at all
Leave this up to the user; their config file is a JS file and we give them access to the default config, so they can do as much merging of defaults as they like.
This commit is contained in:
parent
42150826aa
commit
4478b04090
4 changed files with 4 additions and 156 deletions
|
|
@ -1,65 +0,0 @@
|
|||
import _ from 'lodash'
|
||||
|
||||
const configTemplate = {
|
||||
screens: null,
|
||||
colors: null,
|
||||
text: {
|
||||
fonts: null,
|
||||
sizes: null,
|
||||
weights: null,
|
||||
leading: null,
|
||||
tracking: null,
|
||||
colors: null,
|
||||
},
|
||||
backgrounds: {
|
||||
colors: null,
|
||||
},
|
||||
borders: {
|
||||
widths: null,
|
||||
colors: null,
|
||||
},
|
||||
radiuses: null,
|
||||
sizing: {
|
||||
width: null,
|
||||
height: null,
|
||||
minHeight: null,
|
||||
maxHeight: null,
|
||||
minWidth: null,
|
||||
maxWidth: null,
|
||||
},
|
||||
spacing: {
|
||||
padding: null,
|
||||
margin: null,
|
||||
negativeMargin: null,
|
||||
},
|
||||
shadows: null,
|
||||
zIndex: null,
|
||||
opacity: null,
|
||||
}
|
||||
|
||||
function replaceDefaults(template, defaults, replacements) {
|
||||
return Object.keys(template).reduce((merged, key) => {
|
||||
const value = template[key]
|
||||
|
||||
if (_.isPlainObject(value)) {
|
||||
merged[key] = replaceDefaults(value, _.get(defaults, key), _.get(replacements, key))
|
||||
} else {
|
||||
merged[key] = _.get(replacements, key, _.get(defaults, key))
|
||||
}
|
||||
|
||||
return merged
|
||||
}, {})
|
||||
}
|
||||
|
||||
function appendConfig(base, appends) {
|
||||
return _.mergeWith({}, base, appends, (baseValue, appendsValue) => {
|
||||
if (_.isArray(baseValue)) {
|
||||
return baseValue.concat(appendsValue);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export default function mergeConfig(base, other) {
|
||||
const replaced = replaceDefaults(configTemplate, base, other)
|
||||
return appendConfig(replaced, _.get(other, 'extend', {}))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue