function formatResourceChangesInScope()

in src/helpers/whatif.ts [239:262]


function formatResourceChangesInScope(
  builder: ColorStringBuilder,
  scope: string,
  resourceChangesInScope: WhatIfChange[],
): void {
  builder.appendLine().appendLine(`Scope: ${scope}`);

  const sortedResourceChanges = resourceChangesInScope.sort(
    (a, b) =>
      changeTypeToWeight[a.changeType] - changeTypeToWeight[b.changeType],
  );

  const grouped = groupBy(sortedResourceChanges, x => x.changeType);
  for (const [changeType, resourceChanges] of entries(grouped)) {
    builder.withColorScope(changeTypeToColor[changeType], () => {
      for (const resourceChange of resourceChanges) {
        const isLast =
          resourceChange ===
          sortedResourceChanges[sortedResourceChanges.length - 1];
        formatResourceChange(builder, resourceChange, isLast);
      }
    });
  }
}