def update_root_yaml()

in solutions_builder/cli/component.py [0:0]


def update_root_yaml(component_name, answers, solution_path):
  # Update Solution root YAML with new component name.
  solution_yaml_dict = read_yaml(f"{solution_path}/sb.yaml") or {}
  components = solution_yaml_dict.get("components", {})
  components[component_name] = answers
  solution_yaml_dict["components"] = components

  # Update global variables.
  global_variables = solution_yaml_dict.get("global_variables", {})
  if "project_id" in answers:
    global_variables["project_id"] = answers["project_id"]
  if "project_number" in answers:
    global_variables["project_number"] = answers["project_number"]
  solution_yaml_dict["global_variables"] = global_variables

  write_yaml(f"{solution_path}/sb.yaml", solution_yaml_dict)