| 1 | const NIGHTLY_SERVER_VERSION_PATTERN = /^[^-+]+-(?:nightly|preview)\.\d{8}\.\d+$/; |
| 2 | |
| 3 | export function formatAppDisplayName(input: { |
| 4 | readonly baseName: string; |
| 5 | readonly stageLabel: string; |
| 6 | }): string { |
| 7 | if (input.stageLabel.trim().toLowerCase() === "latest") { |
| 8 | return input.baseName; |
| 9 | } |
| 10 | |
| 11 | return `${input.baseName} (${input.stageLabel})`; |
| 12 | } |
| 13 | |
| 14 | export function resolveServerBackedAppStageLabel(input: { |
| 15 | readonly primaryServerVersion: string | null | undefined; |
| 16 | readonly fallbackStageLabel: string; |
| 17 | }): string { |
| 18 | return input.primaryServerVersion && |
| 19 | NIGHTLY_SERVER_VERSION_PATTERN.test(input.primaryServerVersion) |
| 20 | ? "Nightly" |
| 21 | : input.fallbackStageLabel; |
| 22 | } |
| 23 | |
| 24 | export function resolveServerBackedAppDisplayName(input: { |
| 25 | readonly baseName: string; |
| 26 | readonly fallbackDisplayName: string; |
| 27 | readonly fallbackStageLabel: string; |
| 28 | readonly primaryServerVersion: string | null | undefined; |
| 29 | }): string { |
| 30 | const stageLabel = resolveServerBackedAppStageLabel({ |
| 31 | primaryServerVersion: input.primaryServerVersion, |
| 32 | fallbackStageLabel: input.fallbackStageLabel, |
| 33 | }); |
| 34 | |
| 35 | return stageLabel === input.fallbackStageLabel |
| 36 | ? input.fallbackDisplayName |
| 37 | : formatAppDisplayName({ baseName: input.baseName, stageLabel }); |
| 38 | } |