chore(medusa): Feature flag loader simplify, deduplicate and increase readability (#2025)
This commit is contained in:
@@ -28,40 +28,30 @@ export default (
|
|||||||
const flagConfig: Record<string, boolean> = {}
|
const flagConfig: Record<string, boolean> = {}
|
||||||
for (const flag of supportedFlags) {
|
for (const flag of supportedFlags) {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||||
const importedModule = require(flag)
|
const flagSettings: FlagSettings = require(flag).default
|
||||||
if (!importedModule.default) {
|
if (!flagSettings) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
const flagSettings: FlagSettings = importedModule.default
|
flagConfig[flagSettings.key] = isTruthy(flagSettings.default_val)
|
||||||
|
|
||||||
switch (true) {
|
let from
|
||||||
case typeof process.env[flagSettings.env_key] !== "undefined":
|
if (typeof process.env[flagSettings.env_key] !== "undefined") {
|
||||||
if (logger) {
|
from = "environment"
|
||||||
logger.info(
|
flagConfig[flagSettings.key] = isTruthy(process.env[flagSettings.env_key])
|
||||||
`Using flag ${flagSettings.env_key} from environment with value ${
|
} else if (typeof projectConfigFlags[flagSettings.key] !== "undefined") {
|
||||||
process.env[flagSettings.env_key]
|
from = "project config"
|
||||||
}`
|
flagConfig[flagSettings.key] = isTruthy(
|
||||||
)
|
projectConfigFlags[flagSettings.key]
|
||||||
}
|
)
|
||||||
flagConfig[flagSettings.key] = isTruthy(
|
}
|
||||||
process.env[flagSettings.env_key]
|
|
||||||
)
|
if (logger && from) {
|
||||||
break
|
logger.info(
|
||||||
case typeof projectConfigFlags[flagSettings.key] !== "undefined":
|
`Using flag ${flagSettings.env_key} from ${from} with value ${
|
||||||
if (logger) {
|
flagConfig[flagSettings.key]
|
||||||
logger.info(
|
}`
|
||||||
`Using flag ${flagSettings.key} from project config with value ${
|
)
|
||||||
projectConfigFlags[flagSettings.key]
|
|
||||||
}`
|
|
||||||
)
|
|
||||||
}
|
|
||||||
flagConfig[flagSettings.key] = isTruthy(
|
|
||||||
projectConfigFlags[flagSettings.key]
|
|
||||||
)
|
|
||||||
break
|
|
||||||
default:
|
|
||||||
flagConfig[flagSettings.key] = flagSettings.default_val
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flagConfig[flagSettings.key]) {
|
if (flagConfig[flagSettings.key]) {
|
||||||
|
|||||||
Reference in New Issue
Block a user