|
15 | 15 | </div> |
16 | 16 | <div class="vp-code-group vp-doc" v-else> |
17 | 17 | <CodeGroup :groups="[ |
18 | | - { id: 'pkg-priv', label: '~/.cdsrc.json', lang: 'json', group, code: pkgStr, private: true }, |
19 | | - { id: 'pkg', label: 'package/.cdsrc.json', lang: 'json', group, code: pkgStr }, |
20 | | - { id: 'js', label: '.cdsrc.js', lang: 'js', group, code: jsStr }, |
21 | | - { id: 'yml', label: '.cdsrc.yaml', lang: 'yml', group, code: ymlStr }, |
| 18 | + { id: 'pkg-rc', label: 'package.json', lang: 'json', group, code: pkgStr }, |
| 19 | + { id: 'pkg-priv', label: '~/.cdsrc.json', lang: 'json', group, code: rcJsonStr, private: true }, |
| 20 | + { id: 'pkg', label: '.cdsrc.json', lang: 'json', group, code: rcJsonStr }, |
| 21 | + { id: 'js', label: '.cdsrc.js', lang: 'js', group, code: rcJsStr }, |
| 22 | + { id: 'yml', label: '.cdsrc.yaml', lang: 'yml', group, code: rcYmlStr }, |
22 | 23 | { id: 'env', label: '.env file', lang: 'properties', group, code: propStr }, |
23 | | - { id: 'shl', label: 'Linux/macOS Shells', lang: 'sh', group, code: envStr, transient: true }, |
| 24 | + { id: 'shl', label: 'Linux/macOS Shells', lang: 'sh', group, code: 'export '+envStr, transient: true }, |
24 | 25 | { id: 'shp', label: 'Powershell', lang: 'powershell', group, code: '$Env:'+envStr, transient: true }, |
25 | 26 | { id: 'shw', label: 'Cmd Shell', lang: 'cmd', group, code: 'set '+envStr, transient: true } |
26 | 27 | ]" /> |
|
53 | 54 | h('input', { type: 'radio', name: 'group', id: `${b.group}-${b.id}`, checked: idx === 0 }), |
54 | 55 | h('label', { for: `${b.group}-${b.id}` }, b.label) |
55 | 56 | ])), |
56 | | - h('div', { class: 'blocks' }, groups.flatMap((b, idx) => [ |
57 | | - h('div', { class: ['language-'+b.lang, idx === 0 ? 'active': ''] }, [ |
58 | | - h('button', { title: 'Copy Code', class: 'copy' }), |
59 | | - h('span', { class: 'lang' }, b.lang), |
60 | | - h('pre', { class: 'shiki' }, |
61 | | - h('code', |
62 | | - h('span', { class: 'line' }, |
63 | | - h('span', b.code) |
| 57 | + h('div', { class: 'blocks' }, groups |
| 58 | + .filter((b) => filesOnly ? !b.transient : true) |
| 59 | + .filter((b) => showPrivate ? true : !b.private) |
| 60 | + .flatMap((b, idx) => [ |
| 61 | + h('div', { class: ['language-'+b.lang, idx === 0 ? 'active': ''] }, [ |
| 62 | + h('button', { title: 'Copy Code', class: 'copy' }), |
| 63 | + h('span', { class: 'lang' }, b.lang), |
| 64 | + h('pre', { class: 'shiki' }, |
| 65 | + h('code', |
| 66 | + h('span', { class: 'line' }, |
| 67 | + h('span', b.code) |
| 68 | + ) |
64 | 69 | ) |
65 | 70 | ) |
66 | | - ) |
67 | | - ]) |
68 | | - ])) |
| 71 | + ]) |
| 72 | + ] |
| 73 | + )) |
69 | 74 | ], { |
70 | 75 | props: { |
71 | 76 | groups: { type: Array<{id:string, group:string, code:string, label:string, lang:string, transient?:boolean, private?:boolean }>, required: true } |
|
85 | 90 | const popperVisible = ref(false) |
86 | 91 | const group = ref() |
87 | 92 | const pkgStr = ref() |
88 | | - const jsStr = ref() |
89 | | - const ymlStr = ref() |
| 93 | + const rcJsonStr = ref() |
| 94 | + const rcJsStr = ref() |
| 95 | + const rcYmlStr = ref() |
90 | 96 | const propStr = ref() |
91 | 97 | const envStr = ref() |
92 | 98 | const javaAppyml = ref() |
|
111 | 117 | const pkg = toJson(key, jsonVal ?? value) |
112 | 118 |
|
113 | 119 | pkgStr.value = JSON.stringify(pkg, null, 2) |
114 | | - jsStr.value = 'module.exports = ' + pkgStr.value.replace(/"(\w*?)":/g, '$1:') |
| 120 | + rcJsonStr.value = JSON.stringify(pkg.cds, null, 2) |
| 121 | + rcJsStr.value = 'module.exports = ' + rcJsonStr.value.replace(/"(\w*?)":/g, '$1:') |
| 122 | + rcYmlStr.value = yaml.stringify(pkg.cds) |
115 | 123 | propStr.value = `${key}=${jsonVal ? JSON.stringify(jsonVal) : value}` |
116 | | - envStr.value = `${key.replaceAll('_', '__').replaceAll('.', '_').toUpperCase()}=${jsonVal ? JSON.stringify(jsonVal) : value}` |
117 | 124 |
|
118 | | - javaAppyml.value = ymlStr.value = yaml.stringify(pkg) |
| 125 | + let envKey = key.replaceAll('_', '__').replaceAll('.', '_') |
| 126 | + if (/^[a-z_]+$/.test(envKey)) envKey = envKey.toUpperCase() // only uppercase if not camelCase |
| 127 | + envStr.value = `${envKey}=${jsonVal ? JSON.stringify(jsonVal) : value}` |
| 128 | +
|
| 129 | + javaAppyml.value = yaml.stringify(pkg) |
119 | 130 | javaEnvStr.value = `-D${propStr.value}` |
120 | 131 | }) |
121 | 132 |
|
|
0 commit comments