mirror of
https://gitlab.com/bramw/baserow.git
synced 2024-11-24 16:36:46 +00:00
37 lines
1.0 KiB
JavaScript
37 lines
1.0 KiB
JavaScript
const FF_ENABLE_ALL = '*'
|
|
export const FF_DASHBOARDS = 'dashboards'
|
|
|
|
/**
|
|
* A comma separated list of feature flags used to enable in-progress or not ready
|
|
* features for developers. See docs/development/feature-flags.md for more info
|
|
* @param env: The environment that should be used to get the flags from
|
|
* @returns {string[]}
|
|
*/
|
|
function getFeatureFlags(env = process.env) {
|
|
return (env.FEATURE_FLAGS || '')
|
|
.split(',')
|
|
.map((flag) => flag.trim().toLowerCase())
|
|
}
|
|
|
|
/**
|
|
* Checks if a feature is enabled
|
|
* @param featureFlags: The list of feature flags
|
|
* @param flag: The flag that is being checked for
|
|
* @returns {boolean|*}
|
|
*/
|
|
function featureFlagIsEnabled(featureFlags, flag) {
|
|
if (featureFlags.includes(FF_ENABLE_ALL)) {
|
|
return true
|
|
} else {
|
|
return featureFlags.includes(flag.toLowerCase())
|
|
}
|
|
}
|
|
|
|
export default function ({ app }, inject) {
|
|
const FEATURE_FLAGS = getFeatureFlags(app.$config)
|
|
|
|
inject('featureFlagIsEnabled', (flag) =>
|
|
featureFlagIsEnabled(FEATURE_FLAGS, flag)
|
|
)
|
|
}
|