Skip to content

Commit

Permalink
chore: generate wrangler using confbox
Browse files Browse the repository at this point in the history
  • Loading branch information
atinux committed May 3, 2024
1 parent 4266acb commit 927c1b7
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 37 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"@sindresorhus/slugify": "^2.2.1",
"@uploadthing/mime-types": "^0.2.9",
"citty": "^0.1.6",
"confbox": "^0.1.7",
"defu": "^6.1.4",
"h3": "^1.11.1",
"mime": "^4.0.3",
Expand Down
10 changes: 4 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 42 additions & 31 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,49 @@
import { addCustomTab } from '@nuxt/devtools-kit'
import type { Nuxt } from 'nuxt/schema'
import { stringifyTOML } from 'confbox'

export function generateWrangler(hub: { kv: boolean, database: boolean, blob: boolean, cache: boolean, analytics: boolean }) {
return [
hub.analytics
? [
'analytics_engine_datasets = [',
' { binding = "ANALYTICS", dataset = "default" }',
']'
]
: [],
hub.blob
? [
'r2_buckets = [',
' { binding = "BLOB", bucket_name = "default" }',
']'
]
: [],
hub.cache || hub.kv
? [
'kv_namespaces = [',
hub.kv ? ' { binding = "KV", id = "kv_default" },' : '',
hub.cache ? ' { binding = "CACHE", id = "cache_default" },' : '',
']'
]
: [],
hub.database
? [
'd1_databases = [',
' { binding = "DB", database_name = "default", database_id = "default" }',
']'
]
: []
].flat().join('\n')
const wranger: { [key: string]: any } = {}

if (hub.analytics) {
wranger['analytics_engine_datasets'] = [{
binding: 'ANALYTICS',
dataset: 'default'
}]
}

if (hub.blob) {
wranger['r2_buckets'] = [{
binding: 'BLOB',
bucket_name: 'default'
}]
}

if (hub.cache || hub.kv) {
wranger['kv_namespaces'] = []
if (hub.kv) {
wranger['kv_namespaces'].push({
binding: 'KV',
id: 'kv_default'
})
}
if (hub.cache) {
wranger['kv_namespaces'].push({
binding: 'CACHE',
id: 'cache_default'
})
}
}

if (hub.database) {
wranger['d1_databases'] = [{
binding: 'DB',
database_name: 'default',
database_id: 'default'
}]
}

return stringifyTOML(wranger)
}

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

0 comments on commit 927c1b7

Please sign in to comment.