Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: option to specify storage directory in development #112

Merged
merged 3 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions docs/content/docs/1.getting-started/2.installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,6 @@ export default defineNuxtConfig({
```

::field-group
::field{name="remote" type="boolean|string"}
Default to `false` - Allows working with remote storage (database, kv, blob) from your deployed project. :br
[Read more about remote storage for usage](/docs/getting-started/remote-storage).
::

::field{name="analytics" type="boolean"}
Default to `false` - Enables analytics for your project (coming soon).
::
Expand All @@ -99,6 +94,16 @@ export default defineNuxtConfig({
::field{name="kv" type="boolean"}
Default to `false` - Enables Key-Value to store JSON data accessible globally.
::

::field{name="remote" type="boolean|string"}
Default to `false` - Allows working with remote storage (database, kv, blob) from your deployed project. :br
[Read more about remote storage for usage](/docs/getting-started/remote-storage).
::

::field{name="dir" type="string"}
Default to `'.data/hub'` - The directory used for storage (D1, KV, R2, etc.) in development mode.
::

::

::tip{icon="i-ph-rocket-launch-duotone"}
Expand Down
13 changes: 10 additions & 3 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ export interface ModuleOptions {
* @default process.env.NUXT_HUB_PROJECT_SECRET_KEY
*/
projectSecretKey?: string
/**
* The directory used for storage (D1, KV, R2, etc.) in development mode.
* @default '.data/hub'
*/
dir?: string
}

export default defineNuxtModule<ModuleOptions>({
Expand Down Expand Up @@ -107,6 +112,8 @@ export default defineNuxtModule<ModuleOptions>({
// Remote storage
remote: remoteArg || process.env.NUXT_HUB_REMOTE,
remoteManifest: undefined,
// Local storage
dir: '.data/hub',
// NuxtHub features
analytics: false,
blob: false,
Expand Down Expand Up @@ -378,10 +385,10 @@ export default defineNuxtModule<ModuleOptions>({

// Local development without remote connection
if (nuxt.options.dev && !hub.remote) {
log.info('Using local storage from `.data/hub`')
log.info(`Using local storage from \`${hub.dir}\``)

// Create the .data/hub/ directory
const hubDir = join(rootDir, './.data/hub')
// Create the hub.dir directory
const hubDir = join(rootDir, hub.dir)
try {
await mkdir(hubDir, { recursive: true })
} catch (e: any) {
Expand Down
Loading