@@ -2,6 +2,7 @@ import * as fs from 'fs'
2
2
import { Parameter } from '@aws-sdk/client-cloudformation'
3
3
import { HttpsProxyAgent } from 'https-proxy-agent'
4
4
import { Tag } from '@aws-sdk/client-cloudformation'
5
+ import { yaml } from 'js-yaml'
5
6
6
7
export function isUrl ( s : string ) : boolean {
7
8
let url
@@ -17,42 +18,41 @@ export function isUrl(s: string): boolean {
17
18
18
19
export function parseTags ( s : string ) : Tag [ ] | undefined {
19
20
if ( ! s || s . trim ( ) === '' ) {
20
- return undefined ;
21
+ return undefined
21
22
}
22
23
23
- let tags ;
24
+ let tags
24
25
25
26
// Try to parse as JSON first (backward compatibility)
26
27
try {
27
- tags = JSON . parse ( s ) ;
28
- return tags ;
28
+ tags = JSON . parse ( s )
29
+ return tags
29
30
} catch ( _ ) {
30
31
// JSON parsing failed, try to parse as YAML
31
32
}
32
33
33
34
// If JSON parsing fails, try to handle as YAML
34
35
try {
35
- const yaml = require ( 'js-yaml' ) ;
36
- const parsed = yaml . load ( s ) ;
37
-
36
+ const parsed = yaml . load ( s )
37
+
38
38
if ( ! parsed ) {
39
- return undefined ;
39
+ return undefined
40
40
}
41
41
42
42
// Handle the two YAML structure formats
43
43
if ( Array . isArray ( parsed ) ) {
44
44
// Already in the format [{Key: 'key', Value: 'value'}, ...]
45
- return parsed ;
45
+ return parsed
46
46
} else if ( typeof parsed === 'object' ) {
47
47
// Convert from {Key1: 'Value1', Key2: 'Value2'} format
48
- return Object . entries ( parsed ) . map ( ( [ Key , Value ] ) => ( { Key, Value } ) ) ;
48
+ return Object . entries ( parsed ) . map ( ( [ Key , Value ] ) => ( { Key, Value } ) )
49
49
}
50
50
} catch ( _ ) {
51
51
// YAML parsing failed
52
- return undefined ;
52
+ return undefined
53
53
}
54
54
55
- return undefined ;
55
+ return undefined
56
56
}
57
57
58
58
export function parseARNs ( s : string ) : string [ ] | undefined {
@@ -67,18 +67,23 @@ export function parseNumber(s: string): number | undefined {
67
67
return parseInt ( s ) || undefined
68
68
}
69
69
70
- export function parseParameters ( parameterOverrides : string | Record < string , any > ) : Parameter [ ] {
70
+ type CFParameterValue = string | string [ ] | boolean
71
+ type CFParameterObject = Record < string , CFParameterValue >
72
+ export function parseParameters (
73
+ parameterOverrides : string | Record < string , CFParameterObject >
74
+ ) : Parameter [ ] {
71
75
// Case 1: Handle native YAML objects
72
76
if ( parameterOverrides && typeof parameterOverrides !== 'string' ) {
73
77
return Object . keys ( parameterOverrides ) . map ( key => {
74
78
const value = parameterOverrides [ key ]
75
79
return {
76
80
ParameterKey : key ,
77
- ParameterValue : typeof value === 'string' ? value : JSON . stringify ( value )
81
+ ParameterValue :
82
+ typeof value === 'string' ? value : JSON . stringify ( value )
78
83
}
79
84
} )
80
85
}
81
-
86
+
82
87
// Case 2: Empty string
83
88
if ( ! parameterOverrides ) {
84
89
return [ ]
0 commit comments