buildRoutesObject()

in config/wdl-workspace-routes-plugin.js [36:69]


  buildRoutesObject() {
    const {env} = this.options;
    const result = {};
    const keys = Object.keys(wdlWorkspaceEnvs);
    for (let keyIndex = 0; keyIndex < keys.length; keyIndex++) {
      const key = keys[keyIndex];
      const value = wdlWorkspaceEnvs[key];
      if (!value.routesJsonProperty) {
        continue;
      }
      const propValue = env && env[key] ? env[key] : value.default;
      if (!propValue) {
        if (value.required) {
          console.log(chalk.yellow(`${key} value is missing`));
          return null;
        } else {
          continue;
        }
      }
      const paths = value.routesJsonProperty.split('.');
      let obj = result;
      for (let i = 0; i < paths.length; i++) {
        if (!obj[paths[i]]) {
          obj[paths[i]] = {};
        }
        if (i < paths.length - 1) {
          obj = obj[paths[i]];
        } else {
          obj[paths[i]] = propValue;
        }
      }
    }
    return result;
  }