Skip to content

Commit 7a97033

Browse files
committed
Config inspector: support camelCase env keys
Also use `export ...` pattern for env.vars on Linux/Mac.
1 parent b5ce35d commit 7a97033

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

.vitepress/theme/components/ConfigInspect.vue

+6-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
{ id: 'js', label: '.cdsrc.js', lang: 'js', group, code: jsStr },
2121
{ id: 'yml', label: '.cdsrc.yaml', lang: 'yml', group, code: ymlStr },
2222
{ id: 'env', label: '.env file', lang: 'properties', group, code: propStr },
23-
{ id: 'shl', label: 'Linux/macOS Shells', lang: 'sh', group, code: envStr, transient: true },
23+
{ id: 'shl', label: 'Linux/macOS Shells', lang: 'sh', group, code: 'export '+envStr, transient: true },
2424
{ id: 'shp', label: 'Powershell', lang: 'powershell', group, code: '$Env:'+envStr, transient: true },
2525
{ id: 'shw', label: 'Cmd Shell', lang: 'cmd', group, code: 'set '+envStr, transient: true }
2626
]" />
@@ -80,6 +80,7 @@
8080
FloatingVue.options.themes.cfgPopper = { $extend: 'dropdown' }
8181
8282
const slots = useSlots()
83+
//@ts-expect-error
8384
const slotVal = slots.default?.().at(0)?.children?.toString().trim() ?? 'error: provide <Config>your_key:value</Config>'
8485
8586
const [key, val] = slotVal.split(/\s*[:=]\s*/)
@@ -117,7 +118,10 @@
117118
pkgStr.value = JSON.stringify(pkg, null, 2)
118119
jsStr.value = 'module.exports = ' + pkgStr.value.replace(/"(\w*?)":/g, '$1:')
119120
propStr.value = `${key}=${jsonVal ? JSON.stringify(jsonVal) : value}`
120-
envStr.value = `${key.replaceAll('_', '__').replaceAll('.', '_').toUpperCase()}=${jsonVal ? JSON.stringify(jsonVal) : value}`
121+
122+
let envKey = key.replaceAll('_', '__').replaceAll('.', '_')
123+
if (/^[a-z_]+$/.test(envKey)) envKey = envKey.toUpperCase() // only uppercase if not camelCase
124+
envStr.value = `${envKey}=${jsonVal ? JSON.stringify(jsonVal) : value}`
121125
122126
javaAppyml.value = ymlStr.value = yaml.stringify(pkg)
123127
javaEnvStr.value = `-D${propStr.value}`

0 commit comments

Comments
 (0)