Skip to content

Commit 927c1b7

Browse files
committed
chore: generate wrangler using confbox
1 parent 4266acb commit 927c1b7

File tree

3 files changed

+47
-37
lines changed

3 files changed

+47
-37
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"@sindresorhus/slugify": "^2.2.1",
4444
"@uploadthing/mime-types": "^0.2.9",
4545
"citty": "^0.1.6",
46+
"confbox": "^0.1.7",
4647
"defu": "^6.1.4",
4748
"h3": "^1.11.1",
4849
"mime": "^4.0.3",

pnpm-lock.yaml

Lines changed: 4 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/utils.ts

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,49 @@
11
import { addCustomTab } from '@nuxt/devtools-kit'
22
import type { Nuxt } from 'nuxt/schema'
3+
import { stringifyTOML } from 'confbox'
34

45
export function generateWrangler(hub: { kv: boolean, database: boolean, blob: boolean, cache: boolean, analytics: boolean }) {
5-
return [
6-
hub.analytics
7-
? [
8-
'analytics_engine_datasets = [',
9-
' { binding = "ANALYTICS", dataset = "default" }',
10-
']'
11-
]
12-
: [],
13-
hub.blob
14-
? [
15-
'r2_buckets = [',
16-
' { binding = "BLOB", bucket_name = "default" }',
17-
']'
18-
]
19-
: [],
20-
hub.cache || hub.kv
21-
? [
22-
'kv_namespaces = [',
23-
hub.kv ? ' { binding = "KV", id = "kv_default" },' : '',
24-
hub.cache ? ' { binding = "CACHE", id = "cache_default" },' : '',
25-
']'
26-
]
27-
: [],
28-
hub.database
29-
? [
30-
'd1_databases = [',
31-
' { binding = "DB", database_name = "default", database_id = "default" }',
32-
']'
33-
]
34-
: []
35-
].flat().join('\n')
6+
const wranger: { [key: string]: any } = {}
7+
8+
if (hub.analytics) {
9+
wranger['analytics_engine_datasets'] = [{
10+
binding: 'ANALYTICS',
11+
dataset: 'default'
12+
}]
13+
}
14+
15+
if (hub.blob) {
16+
wranger['r2_buckets'] = [{
17+
binding: 'BLOB',
18+
bucket_name: 'default'
19+
}]
20+
}
21+
22+
if (hub.cache || hub.kv) {
23+
wranger['kv_namespaces'] = []
24+
if (hub.kv) {
25+
wranger['kv_namespaces'].push({
26+
binding: 'KV',
27+
id: 'kv_default'
28+
})
29+
}
30+
if (hub.cache) {
31+
wranger['kv_namespaces'].push({
32+
binding: 'CACHE',
33+
id: 'cache_default'
34+
})
35+
}
36+
}
37+
38+
if (hub.database) {
39+
wranger['d1_databases'] = [{
40+
binding: 'DB',
41+
database_name: 'default',
42+
database_id: 'default'
43+
}]
44+
}
45+
46+
return stringifyTOML(wranger)
3647
}
3748

3849
export function addDevtoolsCustomTabs(nuxt: Nuxt, hub: { kv: boolean, database: boolean, blob: boolean, cache: boolean, analytics: boolean }) {

0 commit comments

Comments
 (0)