Skip to content

Commit 7969a02

Browse files
committed
Custom key delimiters in config inspector
1 parent 93f50e0 commit 7969a02

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

.vitepress/theme/components/ConfigInspect.vue

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,13 @@
3636
import FloatingVue from 'floating-vue'
3737
import yaml from 'yaml'
3838
39-
const { java, keyOnly, filesOnly, showPrivate, label:labelProp } = defineProps<{
39+
const { java, keyOnly, filesOnly, showPrivate, label:labelProp, keyDelim } = defineProps<{
4040
java?: boolean,
4141
keyOnly?: boolean,
4242
filesOnly?: boolean,
4343
showPrivate?: boolean,
44-
label?: string
44+
label?: string,
45+
keyDelim?: string
4546
}>()
4647
4748
// sub component that renders code blocks similar to the markdown `::: code-block` syntax
@@ -85,6 +86,7 @@
8586
8687
const [key, val] = slotVal.split(/\s*[:=]\s*(.*)/) // split on first `:` or `=`
8788
const label = labelProp || `${keyOnly ? key: slotVal}`
89+
const keyDel = keyDelim ?? '.'
8890
8991
const cfgKey = ref()
9092
const popperVisible = ref(false)
@@ -114,25 +116,25 @@
114116
115117
let jsonVal
116118
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)
118120
119121
pkgStr.value = JSON.stringify(pkg, null, 2)
120122
rcJsonStr.value = JSON.stringify(pkg.cds??{}, null, 2)
121123
rcJsStr.value = 'module.exports = ' + rcJsonStr.value.replace(/"(\w*?)":/g, '$1:')
122124
rcYmlStr.value = yaml.stringify(pkg.cds)
123-
propStr.value = `${key}=${jsonVal ? JSON.stringify(jsonVal) : value}`
124125
125-
let envKey = key.replaceAll('_', '__').replaceAll('.', '_')
126+
let envKey = key.replaceAll('_', '__').replaceAll(keyDel, '_')
126127
if (/^[a-z_]+$/.test(envKey)) envKey = envKey.toUpperCase() // only uppercase if not camelCase
127128
envStr.value = `${envKey}=${jsonVal ? JSON.stringify(jsonVal) : value}`
129+
propStr.value = `${envKey}=${jsonVal ? JSON.stringify(jsonVal) : value}`
128130
129131
javaAppyml.value = yaml.stringify(pkg)
130132
javaEnvStr.value = `-D${propStr.value}`
131133
})
132134
133-
function toJson(key:string, value:string): Record<string, any> {
135+
function toJson(key:string, value:string, delim:string): Record<string, any> {
134136
let res = {}
135-
const parts = key.split('.')
137+
const parts = key.split(delim)
136138
parts.reduce((r:Record<string,any>, a, i) => {
137139
r[a] = r[a] || (i < parts.length-1 ? {} : value)
138140
return r[a];

0 commit comments

Comments
 (0)