|
36 | 36 | import FloatingVue from 'floating-vue' |
37 | 37 | import yaml from 'yaml' |
38 | 38 |
|
39 | | - const { java, keyOnly, filesOnly, showPrivate, label:labelProp } = defineProps<{ |
| 39 | + const { java, keyOnly, filesOnly, showPrivate, label:labelProp, keyDelim } = defineProps<{ |
40 | 40 | java?: boolean, |
41 | 41 | keyOnly?: boolean, |
42 | 42 | filesOnly?: boolean, |
43 | 43 | showPrivate?: boolean, |
44 | | - label?: string |
| 44 | + label?: string, |
| 45 | + keyDelim?: string |
45 | 46 | }>() |
46 | 47 |
|
47 | 48 | // sub component that renders code blocks similar to the markdown `::: code-block` syntax |
|
85 | 86 |
|
86 | 87 | const [key, val] = slotVal.split(/\s*[:=]\s*(.*)/) // split on first `:` or `=` |
87 | 88 | const label = labelProp || `${keyOnly ? key: slotVal}` |
| 89 | + const keyDel = keyDelim ?? '.' |
88 | 90 |
|
89 | 91 | const cfgKey = ref() |
90 | 92 | const popperVisible = ref(false) |
|
114 | 116 |
|
115 | 117 | let jsonVal |
116 | 118 | if (typeof value === 'string' && value.trim().match(/^[[{].*[\]}]$/)) { try { jsonVal = JSON.parse(value) } catch {/*ignore*/ } } |
117 | | - const pkg = toJson(key, jsonVal ?? value) |
| 119 | + const pkg = toJson(key, jsonVal ?? value, keyDel) |
118 | 120 |
|
119 | 121 | pkgStr.value = JSON.stringify(pkg, null, 2) |
120 | 122 | rcJsonStr.value = JSON.stringify(pkg.cds??{}, null, 2) |
121 | 123 | rcJsStr.value = 'module.exports = ' + rcJsonStr.value.replace(/"(\w*?)":/g, '$1:') |
122 | 124 | rcYmlStr.value = yaml.stringify(pkg.cds) |
123 | | - propStr.value = `${key}=${jsonVal ? JSON.stringify(jsonVal) : value}` |
124 | 125 |
|
125 | | - let envKey = key.replaceAll('_', '__').replaceAll('.', '_') |
| 126 | + let envKey = key.replaceAll('_', '__').replaceAll(keyDel, '_') |
126 | 127 | if (/^[a-z_]+$/.test(envKey)) envKey = envKey.toUpperCase() // only uppercase if not camelCase |
127 | 128 | envStr.value = `${envKey}=${jsonVal ? JSON.stringify(jsonVal) : value}` |
| 129 | + propStr.value = `${envKey}=${jsonVal ? JSON.stringify(jsonVal) : value}` |
128 | 130 |
|
129 | 131 | javaAppyml.value = yaml.stringify(pkg) |
130 | 132 | javaEnvStr.value = `-D${propStr.value}` |
131 | 133 | }) |
132 | 134 |
|
133 | | -function toJson(key:string, value:string): Record<string, any> { |
| 135 | +function toJson(key:string, value:string, delim:string): Record<string, any> { |
134 | 136 | let res = {} |
135 | | - const parts = key.split('.') |
| 137 | + const parts = key.split(delim) |
136 | 138 | parts.reduce((r:Record<string,any>, a, i) => { |
137 | 139 | r[a] = r[a] || (i < parts.length-1 ? {} : value) |
138 | 140 | return r[a]; |
|
0 commit comments