|
1
|
import type { BaseSpec, DeepPartial } from "../types.js" |
|
2
|
import { |
|
3
|
cloudChangelogBanner, |
|
4
|
type CloudChangelogInput, |
|
5
|
type CloudChangelogSpec, |
|
6
|
} from "./cloud-changelog/index.js" |
|
7
|
import { |
|
8
|
releaseBanner, |
|
9
|
type ReleaseInput, |
|
10
|
type ReleaseSpec, |
|
11
|
} from "./release/index.js" |
|
12
|
import type { BannerDefinition } from "./types.js" |
|
13
|
|
|
14
|
/** |
|
15
|
* Every kind of banner this package renders. |
|
16
|
* |
|
17
|
* Adding one means adding a directory under `banners/`, exporting a |
|
18
|
* {@link BannerDefinition} from it, and listing it here — the renderer, the |
|
19
|
* preview page and the CLI all read the type off this registry. |
|
20
|
*/ |
|
21
|
export const BANNERS = { |
|
22
|
release: releaseBanner, |
|
23
|
"cloud-changelog": cloudChangelogBanner, |
|
24
|
} satisfies { |
|
25
|
release: BannerDefinition<ReleaseSpec, ReleaseInput> |
|
26
|
"cloud-changelog": BannerDefinition<CloudChangelogSpec, CloudChangelogInput> |
|
27
|
} |
|
28
|
|
|
29
|
export type BannerType = keyof typeof BANNERS |
|
30
|
|
|
31
|
export const BANNER_TYPES = Object.keys(BANNERS) as BannerType[] |
|
32
|
|
|
33
|
/** The default type, so callers that only ever wanted a release can omit it. */ |
|
34
|
export const DEFAULT_BANNER_TYPE: BannerType = "release" |
|
35
|
|
|
36
|
/** One banner's input, discriminated by `type`. */ |
|
37
|
export type BannerInput = ReleaseInput | CloudChangelogInput |
|
38
|
|
|
39
|
/** The input for a given type, e.g. `InputFor<"release">`. */ |
|
40
|
export type InputFor<T extends BannerType> = Extract<BannerInput, { type: T }> |
|
41
|
|
|
42
|
/** |
|
43
|
* A definition with its per-type generics collapsed. |
|
44
|
* |
|
45
|
* `BANNERS[input.type]` gives TypeScript a *union* of definitions, which it |
|
46
|
* will not call with a union of inputs even though every pairing that reaches |
|
47
|
* it is sound — the type is the same key that selected the definition. This is |
|
48
|
* the one place that is papered over, rather than at every call site. |
|
49
|
*/ |
|
50
|
export type ResolvedBanner = BannerDefinition< |
|
51
|
BaseSpec & Record<string, unknown>, |
|
52
|
{ spec?: DeepPartial<BaseSpec & Record<string, unknown>> } |
|
53
|
> |
|
54
|
|
|
55
|
/** Looks up the definition for a type, ready to be called with its inputs. */ |
|
56
|
export function bannerOf(type: BannerType): ResolvedBanner { |
|
57
|
return BANNERS[type] as unknown as ResolvedBanner |
|
58
|
} |
|
59
|
|
|
60
|
/** Looks up the definition for an input, ready to be called with it. */ |
|
61
|
export function bannerFor(input: BannerInput): ResolvedBanner { |
|
62
|
return bannerOf(input.type) |
|
63
|
} |
|
64
|
|
|
65
|
export type { BannerDefinition, BannerPreview } from "./types.js" |
|
66
|
export { |
|
67
|
normalizeVersion, |
|
68
|
releaseBanner, |
|
69
|
RELEASE_SPEC, |
|
70
|
FILL_RESOLVES_AT, |
|
71
|
} from "./release/index.js" |
|
72
|
export type { |
|
73
|
PillSpec, |
|
74
|
ReleaseContentSpec, |
|
75
|
ReleaseInput, |
|
76
|
ReleaseSpec, |
|
77
|
} from "./release/index.js" |
|
78
|
export { |
|
79
|
cloudChangelogBanner, |
|
80
|
CLOUD_CHANGELOG_SPEC, |
|
81
|
} from "./cloud-changelog/index.js" |
|
82
|
export type { |
|
83
|
CloudChangelogContentSpec, |
|
84
|
CloudChangelogInput, |
|
85
|
CloudChangelogSpec, |
|
86
|
CloudPillSpec, |
|
87
|
} from "./cloud-changelog/index.js" |