Skip to content

Commit

Permalink
chore: move to layer structure
Browse files Browse the repository at this point in the history
  • Loading branch information
atinux committed Feb 5, 2024
1 parent acfbd4e commit 0f1bb0c
Show file tree
Hide file tree
Showing 65 changed files with 1,966 additions and 777 deletions.
1 change: 1 addition & 0 deletions .nuxtrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
typescript.includeWorkspace=true
21 changes: 0 additions & 21 deletions LICENSE

This file was deleted.

12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# NuxtHub Demo
# NuxtHub

A demonstration using [Nuxt](https://nuxt.com) as a fullstack framework on the edge.
The Nuxt Toolkit to create full-stack applications on the Edge.

## Features

- Session management with secured & sealed cookie sessions
- Create and query typed collections with `useDatabase()`
- Access key-value storage with `useKV()`
- Store files with `useBlob()`
- Edge configuration available with `getConfig()` and `useConfig()` (vue app)

## Blob

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 13 additions & 0 deletions _demo/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export default defineNuxtConfig({
devtools: { enabled: true },
extends: [
'..'
],
modules: [
'@nuxt/ui',
'nuxt-auth-utils'
],
ui: {
icons: ['heroicons', 'simple-icons']
}
})
18 changes: 18 additions & 0 deletions _demo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "nuxthub-demo",
"private": true,
"scripts": {
"dev": "nuxi dev",
"build": "nuxi build",
"preview": "nuxi preview"
},
"dependencies": {
"@iconify-json/simple-icons": "^1.1.90",
"@nuxt/ui": "^2.13.0",
"nuxt": "^3.10.0",
"nuxt-hub": "latest"
},
"devDependencies": {
"@nuxt/devtools": "^1.0.8"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions _demo/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
// https://nuxt.com/docs/guide/concepts/typescript
"extends": "./.nuxt/tsconfig.json"
}
34 changes: 0 additions & 34 deletions _nuxthub/modules/drizzle-studio.ts

This file was deleted.

3 changes: 0 additions & 3 deletions _nuxthub/nuxt.config.ts

This file was deleted.

File renamed without changes.
23 changes: 19 additions & 4 deletions _nuxthub/modules/hub/index.ts → modules/hub/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { defineNuxtModule, createResolver, logger } from 'nuxt/kit'
import { join } from 'pathe'
import { defu } from 'defu'
import { randomUUID } from 'uncrypto'
import { mkdir, writeFile, readFile } from 'node:fs/promises'
import { findWorkspaceDir } from 'pkg-types'

export default defineNuxtModule({
meta: {
name: 'hub'
},
async setup (_options, nuxt) {
const rootDir = nuxt.options.rootDir
const { resolve } = createResolver(import.meta.url)

// Production mode
Expand All @@ -25,7 +28,7 @@ export default defineNuxtModule({

// Local development without remote connection
// Create the .hub/ directory
const hubDir = join(nuxt.options.rootDir, './.hub')
const hubDir = join(rootDir, './.hub')
try {
await mkdir(hubDir)
} catch (e: any) {
Expand All @@ -35,11 +38,12 @@ export default defineNuxtModule({
throw e
}
}
const workspaceDir = await findWorkspaceDir(rootDir)
// Add it to .gitignore
const gitignorePath = join(nuxt.options.rootDir, './.gitignore')
const gitignore = await readFile(gitignorePath, 'utf-8')
const gitignorePath = join(workspaceDir , '.gitignore')
const gitignore = await readFile(gitignorePath, 'utf-8').catch(() => '')
if (!gitignore.includes('.hub')) {
await writeFile(gitignorePath, gitignore + '\n.hub', 'utf-8')
await writeFile(gitignorePath, `${gitignore ? gitignore + '\n' : gitignore}.hub`, 'utf-8')
}

// Generate the wrangler.toml file
Expand All @@ -52,6 +56,17 @@ export default defineNuxtModule({
// Add server plugin
nuxt.options.nitro.plugins = nuxt.options.nitro.plugins || []
nuxt.options.nitro.plugins.push(resolve('./runtime/server/plugins/cloudflare.dev'))

// Generate the session password
if (!process.env.NUXT_SESSION_PASSWORD) {
process.env.NUXT_SESSION_PASSWORD = randomUUID().replace(/-/g, '')
// Add it to .env
const envPath = join(rootDir, '.env')
const envContent = await readFile(envPath, 'utf-8').catch(() => '')
if (!envContent.includes('NUXT_SESSION_PASSWORD')) {
await writeFile(envPath, `${envContent ? envContent + '\n' : envContent}NUXT_SESSION_PASSWORD=${process.env.NUXT_SESSION_PASSWORD}`, 'utf-8')
}
}
}
})

Expand Down
15 changes: 1 addition & 14 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
export default defineNuxtConfig({
devtools: { enabled: true },
typescript: { includeWorkspace: true },
// extends: '@nuxt/ui-pro',
extends: [
// '/Users/atinux/Projects/nuxt/ui-pro',
'./_nuxthub'
],
modules: [
'@nuxt/ui',
'nuxt-auth-utils'
],
ui: {
icons: ['heroicons', 'simple-icons']
}
// ./modules are autoloaded
})
43 changes: 29 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,39 +1,54 @@
{
"name": "nuxthub-demo",
"name": "nuxt-hub",
"private": true,
"type": "module",
"main": "nuxt.config.ts",
"version": "0.0.0",
"files": [
"composables",
"modules",
"plugins",
"server",
"types",
"nuxt.config.ts"
],
"license": "PROPRIETARY",
"scripts": {
"dev": "nuxi dev",
"build": "nuxi build --preset cloudflare_pages",
"preview": "nuxt preview",
"dev:prepare": "nuxt prepare _demo",
"dev": "nuxi dev _demo",
"build": "nuxi build --preset cloudflare_pages _demo",
"preview": "nuxt preview _dmeo",
"lint": "eslint .",
"postinstall": "nuxt prepare",
"logs": "wrangler pages deployment tail"
},
"dependencies": {
"@cloudflare/workers-types": "^4.20240129.0",
"@iconify-json/simple-icons": "^1.1.90",
"@libsql/client": "^0.4.3",
"@nuxt/ui": "^2.13.0",
"bufferutil": "^4.0.8",
"drizzle-orm": "^0.29.3",
"image-meta": "^0.2.0",
"mime": "^4.0.1",
"nuxt": "^3.10.0",
"nuxt-auth-utils": "^0.0.15",
"utf-8-validate": "^6.0.3",
"pkg-types": "^1.0.3",
"uncrypto": "^0.1.3",
"wrangler": "^3.26.0",
"zod": "^3.22.4"
},
"devDependencies": {
"@nuxt/devtools": "^1.0.8",
"@nuxt/eslint-config": "^0.2.0",
"eslint": "^8.56.0",
"typescript": "5.3.3",
"release-it": "^17.0.3",
"typescript": "^5.3.3",
"vue-tsc": "^1.8.27"
},
"resolutions": {
"nitropack": "npm:nitropack-nightly@latest",
"h3": "npm:h3-nightly@latest"
},
"release-it": {
"git": {
"commitMessage": "chore(release): release v${version}"
},
"github": {
"release": true,
"releaseName": "v${version}"
}
}
}
File renamed without changes.
Loading

0 comments on commit 0f1bb0c

Please sign in to comment.