Refactor util functions (#2616)

* Refactor getAllConfigs util function

* Update eslint parser options to ES2020
This commit is contained in:
Twentylives 2021-05-10 18:22:47 +03:00 • committed by GitHub
parent d86cf0da8d
commit 77ef260156
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,21 +1,19 @@
import defaultConfig from '../../stubs/defaultConfig.stub.js'
import { flagEnabled } from '../featureFlags'
import { flatMap, get, isFunction } from 'lodash'
export default function getAllConfigs(config) {
const configs = flatMap([...get(config, 'presets', [defaultConfig])].reverse(), (preset) => {
return getAllConfigs(isFunction(preset) ? preset() : preset)
})
const configs = (config?.presets ?? [defaultConfig])
.slice()
.reverse()
.flatMap((preset) => getAllConfigs(preset instanceof Function ? preset() : preset))
const features = {
// Add experimental configs here...
}
Object.keys(features).forEach((feature) => {
if (flagEnabled(config, feature)) {
configs.unshift(features[feature])
}
})
const experimentals = Object.keys(features)
.filter((feature) => flagEnabled(config, feature))
.map((feature) => features[feature])
return [config, ...configs]
return [config, ...experimentals, ...configs]
}