Skip to content

Commit

Permalink
Development plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
4leite committed Jun 11, 2024
1 parent 3f0795c commit c1d8b7d
Show file tree
Hide file tree
Showing 64 changed files with 1,307 additions and 295 deletions.
13 changes: 13 additions & 0 deletions .changeset/fast-pillows-sin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
"@oberoncms/plugin-vercel-postgres": minor
"@oberoncms/plugin-development": minor
"create-oberon-app": minor
"@oberoncms/sqlite": minor
"@oberoncms/core": minor
"@oberoncms/plugin-pgsql": minor
"@oberoncms/plugin-turso": minor
"@oberon/playground": minor
"@oberon/recipe-nextjs": minor
---

Create a development plugin
12 changes: 6 additions & 6 deletions apps/playground/oberon/adapter.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import "server-cli-only"

import { initAdapter } from "@oberoncms/core/adapter"
import { authPlugin, withDevelopmentSend } from "@oberoncms/core/auth"
import { withDevelopmentDatabase } from "@oberoncms/plugin-sqlite"
import { authPlugin } from "@oberoncms/core/auth"

import { plugin as developmentPlugin } from "@oberoncms/plugin-development"
import { plugin as tursoPlugin } from "@oberoncms/plugin-turso"
import { plugin as uploadthingPlugin } from "@oberoncms/plugin-uploadthing/plugin"

import { sendAdapterPlugin } from "./send"
import { plugin as sendPlugin } from "./send"

export const adapter = initAdapter([
withDevelopmentDatabase(tursoPlugin),
withDevelopmentSend(sendAdapterPlugin),
developmentPlugin,
tursoPlugin,
sendPlugin,
authPlugin,
uploadthingPlugin,
])
2 changes: 1 addition & 1 deletion apps/playground/oberon/prebuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ import { exportTailwindClasses } from "@oberoncms/core/adapter"
import { adapter } from "./adapter"

// Script runs before a build
await adapter.init()
await adapter.prebuild()
await exportTailwindClasses(adapter)
2 changes: 1 addition & 1 deletion apps/playground/oberon/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { OberonPlugin } from "@oberoncms/core"

const emailFrom = process.env.EMAIL_FROM || "noreply@tohuhono.com"

export const sendAdapterPlugin: OberonPlugin = () => ({
export const plugin: OberonPlugin = () => ({
name: "Resend",
adapter: {
sendVerificationRequest: async ({
Expand Down
2 changes: 1 addition & 1 deletion apps/playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"dependencies": {
"@datacom-digital/ui-sample-components": "^0.3.2",
"@oberoncms/core": "workspace:*",
"@oberoncms/plugin-sqlite": "workspace:*",
"@oberoncms/plugin-development": "workspace:*",
"@oberoncms/plugin-turso": "workspace:*",
"@oberoncms/plugin-uploadthing": "workspace:*",
"next": "^14.2.3",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"dev": "turbo dev --concurrency 50",
"dev:packages": "turbo dev --concurrency 50 --filter={./packages/**/*}...",
"dev:demo": "turbo dev --concurrency 50 --filter={./packages/**/*}... --filter=demo",
"dev:oberon": "turbo dev --concurrency 50 --filter={./packages/**/*}... --filter=playground",
"dev:oberon": "turbo dev --concurrency 50 --continue --filter={./packages/**/*}... --filter=playground",
"dev:docs": "turbo dev --concurrency 50 --filter=docs...",
"dev:nextjs": "turbo dev --concurrency 50 --filter={./packages/**/*}... --filter=./oberoncms/* --filter=nextjs-recipe",
"prettier": "prettier --check \"**/*.{ts,tsx,js,jsx,css,md,json}\"",
Expand Down
3 changes: 1 addition & 2 deletions packages/create-oberon-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@
"zod": "^3.23.8"
},
"devDependencies": {
"@oberon/recipe-nextjs": "workspace:*",
"@oberoncms/plugin-flydrive": "workspace:*",
"@oberoncms/plugin-pgsql": "workspace:*",
"@oberoncms/plugin-sqlite": "workspace:*",
"@oberoncms/plugin-development": "workspace:*",
"@oberoncms/plugin-turso": "workspace:*",
"@oberoncms/plugin-uploadthing": "workspace:*",
"@oberoncms/plugin-vercel-postgres": "workspace:*",
Expand Down
22 changes: 9 additions & 13 deletions packages/create-oberon-app/src/installer/install-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,10 @@ const createAdapter = (plugins: Plugin[]) => {
})
.join("\n")

const adapterPlugins = [
...aliasedPlugins.map(({ alias, type }) => {
if (type === "database") {
return `withDevelopmentDatabase(${alias})`
}
if (type === "send") {
return `withDevelopmentSend(${alias})`
}
return alias
}),
const pluginAliasNames = [
// Development plugin should be first
"developmentPlugin",
...aliasedPlugins.map(({ alias }) => alias),
// Auth plugin should be last
"authPlugin",
]
Expand All @@ -73,12 +67,14 @@ const createAdapter = (plugins: Plugin[]) => {
import "server-cli-only"
import { initAdapter } from "@oberoncms/core/adapter"
import { authPlugin, withDevelopmentSend } from "@oberoncms/core/auth"
import { withDevelopmentDatabase } from "@oberoncms/plugin-sqlite"
import { authPlugin } from "@oberoncms/core/auth"
import { plugin as developmentPlugin } from "@oberoncms/plugin-development"
${pluginImports}
export const adapter = initAdapter([${adapterPlugins.join(", ")}])
export const adapter = initAdapter([
${pluginAliasNames.join(", ")}
])
`
}

Expand Down
4 changes: 2 additions & 2 deletions packages/oberoncms/core/src/adapter/base-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { notImplemented } from "@tohuhono/utils"
import type { OberonPermissions, OberonAdapter } from "../lib/dtd"

export const baseAdapter: OberonAdapter = {
plugins: {},
plugins: [],
handlers: {},
getCurrentUser: notImplemented("getCurrentUser"),
hasPermission: ({ user, action, permission }) => {
Expand All @@ -26,7 +26,7 @@ export const baseAdapter: OberonAdapter = {
permissions[role][action] === "write"
)
},
init: async () => {},
prebuild: async () => {},
// OberonSendAdapter
sendVerificationRequest: notImplemented("sendVerificationRequest"),
// OberonDatabaseAdapter
Expand Down
54 changes: 37 additions & 17 deletions packages/oberoncms/core/src/adapter/init-adapter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,46 @@ import { getInitialData } from "./get-initial-data"
import { baseAdapter } from "./base-adapter"

export function initAdapter(plugins: OberonPlugin[] = []) {
const adapter = plugins.reduce<OberonAdapter>((accumulator, plugin) => {
const { name, version, adapter, handlers = {} } = plugin(accumulator)
return {
...accumulator,
plugins: {
...accumulator.plugins,
...(name && { [name]: version || "" }),
},
handlers: {
...accumulator.handlers,
...handlers,
},
...adapter,
}
}, baseAdapter)
const adapter: OberonAdapter = plugins.reduce<OberonAdapter>(
(accumulator, plugin) => {
const {
name,
version,
disabled,
adapter,
handlers = {},
} = plugin(accumulator)

if (disabled) {
return {
...accumulator,
plugins: [
...accumulator.plugins,
{ name, disabled, version: version || "" },
],
}
}

return {
...accumulator,
plugins: [
...accumulator.plugins,
{ name, disabled, version: version || "" },
],
handlers: {
...accumulator.handlers,
...handlers,
},
...adapter,
}
},
baseAdapter,
)

return {
...adapter,
init: async () => {
await adapter.init()
prebuild: async () => {
await adapter.prebuild()
const allPages = await adapter.getAllPages()
if (!allPages.length) {
console.log("Initialising welcome page")
Expand Down
2 changes: 0 additions & 2 deletions packages/oberoncms/core/src/auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,3 @@ export { authPlugin } from "./auth/next-auth"

export { VerifyPage } from "./auth/verify"
export { ConfirmPage } from "./auth/confirm"

export { withDevelopmentSend } from "./auth/with-development-send"
2 changes: 1 addition & 1 deletion packages/oberoncms/core/src/auth/next-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export const authPlugin: OberonPlugin = (adapter) => {
}

return {
name: `${name} (auth)`,
name: `${name}/auth`,
version,
handlers: { auth: { ...nextAuth.handlers, GET } },
adapter: {
Expand Down
28 changes: 0 additions & 28 deletions packages/oberoncms/core/src/auth/with-development-send.ts

This file was deleted.

21 changes: 10 additions & 11 deletions packages/oberoncms/core/src/components/site.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,16 @@ export function Site({

<div>@oberoncms/core</div>
<div>{coreVersion}</div>
<ColumnHeading>Plugins</ColumnHeading>
<ColumnHeading></ColumnHeading>
{Object.keys(plugins).map((key) => {
const version = plugins[key]
return (
<Fragment key={key}>
<div>{key}</div>
<div>{version}</div>
</Fragment>
)
})}
<ColumnHeading className="col-span-2">Plugins</ColumnHeading>

{plugins.map(({ name, disabled, version }) => (
<Fragment key={name}>
<div className={disabled ? "font-light" : ""}>
{name} {disabled && " (disabled)"}
</div>
<div>{version}</div>
</Fragment>
))}
</Table>
</>
)
Expand Down
Loading

0 comments on commit c1d8b7d

Please sign in to comment.