@@ -3,9 +3,23 @@ import PluginConfig, { PlatformConfig } from './@types/pluginConfig'
3
3
import { resolve as androidResolve } from './platforms/android'
4
4
import { resolve as iOSResolve } from './platforms/iOS'
5
5
6
- const generateNotes = async ( config : PluginConfig , ctx : GenerateNotesContext ) => {
7
- const platformVersions : { [ key in keyof PlatformConfig ] ?: string } = { }
6
+ const formatter = ( platforms : { displayName : string ; versionRange : string } [ ] , heading ?: string ) => {
7
+ let result = ''
8
+
9
+ if ( heading ) {
10
+ result += `### ${ heading } \n\n`
11
+ }
8
12
13
+ result += platforms
14
+ . map ( ( { displayName, versionRange } ) => {
15
+ return `${ displayName } Version Range: **\`${ versionRange } \`**`
16
+ } )
17
+ . join ( '\n\n' )
18
+
19
+ return result
20
+ }
21
+
22
+ const generateNotes = async ( config : PluginConfig , ctx : GenerateNotesContext ) => {
9
23
// Normalize plugin config: prefer `platforms`, fall back to legacy top-level platform keys for backward compatibility
10
24
// TODO: Remove support for top-level `android` and `iOS` keys in the next major release (BC)
11
25
const platforms : PlatformConfig = config . platforms || { }
@@ -25,33 +39,27 @@ const generateNotes = async (config: PluginConfig, ctx: GenerateNotesContext) =>
25
39
throw new Error ( 'No platforms specified. You must configure at least one platform under `platforms`.' )
26
40
}
27
41
42
+ const platformVersions : { displayName : string ; versionRange : string } [ ] = [ ]
43
+
28
44
if ( platforms . android ) {
29
45
const androidVersion = await androidResolve ( ctx , platforms . android )
30
- platformVersions . android = androidVersion
46
+ platformVersions . push ( {
47
+ displayName : platforms . android . displayName ?? 'Android' ,
48
+ versionRange : androidVersion ,
49
+ } )
31
50
ctx . logger . log ( `Detected Android Version: \`${ androidVersion } \`` )
32
51
}
33
52
34
53
if ( platforms . iOS ) {
35
54
const iOSVersion = await iOSResolve ( ctx , platforms . iOS )
36
- platformVersions . iOS = iOSVersion
55
+ platformVersions . push ( {
56
+ displayName : platforms . iOS . displayName ?? 'iOS' ,
57
+ versionRange : iOSVersion ,
58
+ } )
37
59
ctx . logger . log ( `Detected iOS Version: \`${ iOSVersion } \`` )
38
60
}
39
61
40
- let notes = ''
41
-
42
- if ( config . heading ) {
43
- notes += `### ${ config . heading } \n\n`
44
- }
45
-
46
- notes += Object . keys ( platformVersions )
47
- . map ( ( platformKey ) => {
48
- const platform = platformKey as keyof PlatformConfig
49
- const version = platformVersions [ platform ]
50
- return `${ platforms [ platform ] ?. displayName ?? platform } Version Range: **\`${ version } \`**`
51
- } )
52
- . join ( '\n\n' )
53
-
54
- return notes
62
+ return formatter ( platformVersions , config . heading )
55
63
}
56
64
57
65
export default generateNotes
0 commit comments