Skip to content

Commit

Permalink
Refactor util functions (#2616)
Browse files Browse the repository at this point in the history
* Refactor getAllConfigs util function

* Update eslint parser options to ES2020
  • Loading branch information
20lives committed May 10, 2021
1 parent d86cf0d commit 77ef260
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/util/getAllConfigs.js
@@ -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]
}

0 comments on commit 77ef260

Please sign in to comment.