Skip to content

Commit

Permalink
feat: option to specify storage directory in development (nuxt-hub#112)
Browse files Browse the repository at this point in the history
Co-authored-by: Sébastien Chopin <seb@nuxt.com>
  • Loading branch information
unibeck and atinux authored May 21, 2024
1 parent 82acf09 commit 162942a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
30 changes: 25 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,8 +94,33 @@ 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"}
You're all set! Now, let's dive into connecting to your Cloudflare account and [deploying it on the Edge](/docs/getting-started/deploy).
::

## Nightly Builds

You can also use the latest features and bug fixes (commited on the `main` branch) by installing the [nightly tag](https://www.npmjs.com/package/@nuxthub/core?activeTab=versions):

```diff [package.json]
{
"Dependencies": {
- "@nuxthub/core": "^0.5.0"
+ "@nuxthub/core": "npm:@nuxthub/core@nightly"
}
}
```

Then run `npm install`, `pnpm install`, `yarn install` or `bun install` to update the dependency.
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

0 comments on commit 162942a

Please sign in to comment.