config.utils.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import deepmerge from 'deepmerge'
  2. import { experiments } from '@/../experimentConfig'
  3. // Merge a default config with a specific scene config
  4. const buildConfig = ({ defaultConfig = {}, scenesConfig = {} }, sceneName) =>
  5. deepmerge(defaultConfig, scenesConfig[sceneName] || {})
  6. /**
  7. * Build a configuration file by merging the default config with the asked scene.
  8. * The asked scene config will overwrite the default config.
  9. * It merges the mixin config with the experiment config.
  10. * Experiment config overwrites all.
  11. *
  12. * @param {Object} experimentName The selected experiment
  13. * @param {Object} sceneName The selected scene
  14. * @returns {Object} The config for the selected experiment with the selected scene
  15. */
  16. export const getExperimentConfig = (experimentName, sceneName) => {
  17. if (!experiments[experimentName])
  18. throw new Error(`Could not find the experiment "${experimentName}" in the config file.`)
  19. // Build parent mixin config
  20. const mixinConfig = buildConfig(experiments[experimentName].mixin, sceneName)
  21. // Build global config
  22. const globalConfig = buildConfig(experiments[experimentName], sceneName)
  23. // Merge configs
  24. return deepmerge(mixinConfig, globalConfig)
  25. }
  26. // /**
  27. // * Read config to get the list of available scenes for a given experiment
  28. // *
  29. // * @param {Object} experimentName The selected experiment
  30. // * @param {String[]} scenesList List of scenes
  31. // * @returns {String[]} The list of available scenes for this experiment
  32. // */
  33. // export const getExperimentSceneList = (experimentName, scenesList) => {
  34. // // TODO: scene blacklist, scene array, all
  35. // return []
  36. // }