diff --git a/configure.ts b/configure.ts index 79b0b69..c47e9d4 100644 --- a/configure.ts +++ b/configure.ts @@ -43,7 +43,7 @@ const ADAPTERS_INFO: { pluginCall: 'vue()', importDeclarations: [{ isNamed: false, module: '@vitejs/plugin-vue', identifier: 'vue' }], }, - ssrEntrypoint: 'resources/ssr.ts', + ssrEntrypoint: 'inertia/app/ssr.ts', }, react: { stubFolder: 'react', @@ -61,7 +61,7 @@ const ADAPTERS_INFO: { pluginCall: 'react()', importDeclarations: [{ isNamed: false, module: '@vitejs/plugin-react', identifier: 'react' }], }, - ssrEntrypoint: 'resources/ssr.tsx', + ssrEntrypoint: 'inertia/app/ssr.tsx', }, svelte: { stubFolder: 'svelte', @@ -79,7 +79,7 @@ const ADAPTERS_INFO: { { isNamed: true, module: '@sveltejs/vite-plugin-svelte', identifier: 'svelte' }, ], }, - ssrEntrypoint: 'resources/ssr.ts', + ssrEntrypoint: 'inertia/app/ssr.ts', }, solid: { stubFolder: 'solid', @@ -96,7 +96,7 @@ const ADAPTERS_INFO: { ssrPluginCall: 'solid({ ssr: true })', importDeclarations: [{ isNamed: false, module: 'vite-plugin-solid', identifier: 'solid' }], }, - ssrEntrypoint: 'resources/ssr.tsx', + ssrEntrypoint: 'inertia/app/ssr.tsx', }, } @@ -185,7 +185,7 @@ export async function configure(command: Configure) { /** * Add Inertia middleware */ - await codemods.registerMiddleware('router', [ + await codemods.registerMiddleware('server', [ { path: '@adonisjs/inertia/inertia_middleware', position: 'after' }, ]) @@ -205,6 +205,8 @@ export async function configure(command: Configure) { await codemods.makeUsingStub(stubsRoot, `${stubFolder}/tsconfig.json.stub`, {}) await codemods.makeUsingStub(stubsRoot, `${stubFolder}/app.${appExt}.stub`, { ssr }) await codemods.makeUsingStub(stubsRoot, `${stubFolder}/home.${compExt}.stub`, {}) + await codemods.makeUsingStub(stubsRoot, `${stubFolder}/errors/not_found.${compExt}.stub`, {}) + await codemods.makeUsingStub(stubsRoot, `${stubFolder}/errors/server_error.${compExt}.stub`, {}) if (ssr) { await codemods.makeUsingStub(stubsRoot, `${stubFolder}/ssr.${appExt}.stub`, {}) @@ -214,7 +216,7 @@ export async function configure(command: Configure) { * Register the inertia plugin in vite config */ const inertiaPluginCall = ssr - ? `inertia({ ssr: { enabled: true, entrypoint: 'resources/ssr.${appExt}' } })` + ? `inertia({ ssr: { enabled: true, entrypoint: 'inertia/app/ssr.${appExt}' } })` : `inertia({ ssr: { enabled: false } })` await codemods.registerVitePlugin(inertiaPluginCall, [ @@ -234,7 +236,7 @@ export async function configure(command: Configure) { /** * Register vite with adonisjs plugin */ - const adonisjsPluginCall = `adonisjs({ entrypoints: ['resources/app.${appExt}'], reload: ['resources/views/**/*.edge'] })` + const adonisjsPluginCall = `adonisjs({ entrypoints: ['inertia/app/app.${appExt}'], reload: ['resources/views/**/*.edge'] })` await codemods.registerVitePlugin(adonisjsPluginCall, [ { isNamed: false, module: '@adonisjs/vite/client', identifier: 'adonisjs' }, ]) diff --git a/src/define_config.ts b/src/define_config.ts index 45c885a..ef67b67 100644 --- a/src/define_config.ts +++ b/src/define_config.ts @@ -26,14 +26,16 @@ export function defineConfig(config: InertiaConfig): ConfigProvider ctx.session.flashMessages.get('errors'), + errors: (ctx) => ctx.session?.flashMessages.get('errors'), }, /** diff --git a/stubs/react/app.tsx.stub b/stubs/react/app.tsx.stub index 33ac58a..a00c5b0 100644 --- a/stubs/react/app.tsx.stub +++ b/stubs/react/app.tsx.stub @@ -1,7 +1,7 @@ {{{ - exports({ to: app.makePath('resources/app.tsx') }) + exports({ to: app.makePath('inertia/app/app.tsx') }) }}} -import './css/app.css'; +import '../css/app.css'; {{#if ssr}} import { hydrateRoot } from 'react-dom/client' @@ -20,8 +20,8 @@ createInertiaApp({ resolve: (name) => { return resolvePageComponent( - {{ '`./pages/${name}.tsx`' }}, - import.meta.glob('./pages/**/*.tsx'), + {{ '`../pages/${name}.tsx`' }}, + import.meta.glob('../pages/**/*.tsx'), ) }, diff --git a/stubs/react/errors/not_found.tsx.stub b/stubs/react/errors/not_found.tsx.stub new file mode 100644 index 0000000..1ec6b89 --- /dev/null +++ b/stubs/react/errors/not_found.tsx.stub @@ -0,0 +1,14 @@ +{{{ + exports({ to: app.makePath('inertia/pages/errors/not_found.tsx') }) +}}} +export default function NotFound() { + return ( + <> +
+
Page not found
+ + This page does not exist. +
+ + ) +} diff --git a/stubs/react/errors/server_error.tsx.stub b/stubs/react/errors/server_error.tsx.stub new file mode 100644 index 0000000..919ded4 --- /dev/null +++ b/stubs/react/errors/server_error.tsx.stub @@ -0,0 +1,14 @@ +{{{ + exports({ to: app.makePath('inertia/pages/errors/server_error.tsx') }) +}}} +export default function ServerError(props: { error: any }) { + return ( + <> +
+
Server Error
+ + {props.error.message} +
+ + ) +} diff --git a/stubs/react/home.tsx.stub b/stubs/react/home.tsx.stub index 345270b..065d46e 100644 --- a/stubs/react/home.tsx.stub +++ b/stubs/react/home.tsx.stub @@ -1,5 +1,5 @@ {{{ - exports({ to: app.makePath('resources/pages/home.tsx') }) + exports({ to: app.makePath('inertia/pages/home.tsx') }) }}} import { Head } from '@inertiajs/react' diff --git a/stubs/react/root.edge.stub b/stubs/react/root.edge.stub index 69ad119..0fa9693 100644 --- a/stubs/react/root.edge.stub +++ b/stubs/react/root.edge.stub @@ -1,5 +1,5 @@ {{{ - exports({ to: app.makePath('resources/views/root.edge') }) + exports({ to: app.makePath('resources/views/inertia_layout.edge') }) }}} @@ -12,7 +12,7 @@ @viteReactRefresh() @inertiaHead() - {{ "@vite(['resources/app.tsx', `resources/pages/${page.component}.tsx`])" }} + {{ "@vite(['inertia/app/app.tsx', `inertia/pages/${page.component}.tsx`])" }} diff --git a/stubs/react/ssr.tsx.stub b/stubs/react/ssr.tsx.stub index d22392b..7adbe4a 100644 --- a/stubs/react/ssr.tsx.stub +++ b/stubs/react/ssr.tsx.stub @@ -1,5 +1,5 @@ {{{ - exports({ to: app.makePath('resources/ssr.tsx') }) + exports({ to: app.makePath('inertia/app/ssr.tsx') }) }}} import ReactDOMServer from 'react-dom/server' import { createInertiaApp } from '@inertiajs/react' @@ -9,8 +9,8 @@ export default function render(page: any) { page, render: ReactDOMServer.renderToString, resolve: (name) => { - const pages = import.meta.glob('./pages/**/*.tsx', { eager: true }) - {{ 'return pages[`./pages/${name}.tsx`]' }} + const pages = import.meta.glob('../pages/**/*.tsx', { eager: true }) + {{ 'return pages[`../pages/${name}.tsx`]' }} }, setup: ({ App, props }) => , }) diff --git a/stubs/react/tsconfig.json.stub b/stubs/react/tsconfig.json.stub index e6ecf13..872babd 100644 --- a/stubs/react/tsconfig.json.stub +++ b/stubs/react/tsconfig.json.stub @@ -1,25 +1,15 @@ {{{ - exports({ to: app.makePath('resources/tsconfig.json') }) + exports({ to: app.makePath('inertia/tsconfig.json') }) }}} { + "extends": "@adonisjs/tsconfig/tsconfig.client.json", "compilerOptions": { - "target": "ESNext", - "jsx": "react-jsx", - "lib": ["DOM", "ESNext", "DOM.Iterable", "ES2020"], - "useDefineForClassFields": true, "baseUrl": ".", "module": "ESNext", - "moduleResolution": "Bundler", + "jsx": "react-jsx", "paths": { - "@/*": ["./*"], "~/*": ["../*"], }, - "resolveJsonModule": true, - "types": ["vite/client"], - "allowSyntheticDefaultImports": true, - "esModuleInterop": true, - "verbatimModuleSyntax": true, - "skipLibCheck": true, }, "include": ["./**/*.ts", "./**/*.tsx"], } diff --git a/stubs/solid/app.tsx.stub b/stubs/solid/app.tsx.stub index d4471ad..3854ace 100644 --- a/stubs/solid/app.tsx.stub +++ b/stubs/solid/app.tsx.stub @@ -1,7 +1,7 @@ {{{ - exports({ to: app.makePath('resources/app.tsx') }) + exports({ to: app.makePath('inertia/app/app.tsx') }) }}} -import './css/app.css' +import '../css/app.css' {{#if ssr}} import { hydrate } from 'solid-js/web'; @@ -20,8 +20,8 @@ createInertiaApp({ resolve: (name) => { return resolvePageComponent( - {{ '`./pages/${name}.tsx`' }}, - import.meta.glob('./pages/**/*.tsx'), + {{ '`../pages/${name}.tsx`' }}, + import.meta.glob('../pages/**/*.tsx'), ) }, diff --git a/stubs/solid/errors/not_found.tsx.stub b/stubs/solid/errors/not_found.tsx.stub new file mode 100644 index 0000000..9792a32 --- /dev/null +++ b/stubs/solid/errors/not_found.tsx.stub @@ -0,0 +1,14 @@ +{{{ + exports({ to: app.makePath('inertia/pages/errors/not_found.tsx') }) +}}} +export default function NotFound() { + return ( + <> +
+
Page not found
+ + This page does not exist. +
+ + ) +} diff --git a/stubs/solid/errors/server_error.tsx.stub b/stubs/solid/errors/server_error.tsx.stub new file mode 100644 index 0000000..e35db7b --- /dev/null +++ b/stubs/solid/errors/server_error.tsx.stub @@ -0,0 +1,14 @@ +{{{ + exports({ to: app.makePath('inertia/pages/errors/server_error.tsx') }) +}}} +export default function ServerError(props: { error: any }) { + return ( + <> +
+
Server Error
+ + {props.error.message} +
+ + ) +} diff --git a/stubs/solid/home.tsx.stub b/stubs/solid/home.tsx.stub index f118de8..3a72152 100644 --- a/stubs/solid/home.tsx.stub +++ b/stubs/solid/home.tsx.stub @@ -1,13 +1,10 @@ {{{ - exports({ to: app.makePath('resources/pages/home.tsx') }) + exports({ to: app.makePath('inertia/pages/home.tsx') }) }}} -import { Title } from '@solidjs/meta' export default function Home(props: { version: number }) { return ( <> - Homepage -
AdonisJS {props.version} x Inertia x Solid.js
diff --git a/stubs/solid/root.edge.stub b/stubs/solid/root.edge.stub index 4287d3f..a1531ba 100644 --- a/stubs/solid/root.edge.stub +++ b/stubs/solid/root.edge.stub @@ -1,5 +1,5 @@ {{{ - exports({ to: app.makePath('resources/views/root.edge') }) + exports({ to: app.makePath('resources/views/inertia_layout.edge') }) }}} @@ -11,7 +11,7 @@ AdonisJS x Inertia x SolidJS @inertiaHead() - {{ "@vite(['resources/app.tsx', `resources/pages/${page.component}.tsx`])" }} + {{ "@vite(['inertia/app/app.tsx', `inertia/pages/${page.component}.tsx`])" }} diff --git a/stubs/solid/ssr.tsx.stub b/stubs/solid/ssr.tsx.stub index a4bdbed..5a6fc1b 100644 --- a/stubs/solid/ssr.tsx.stub +++ b/stubs/solid/ssr.tsx.stub @@ -1,5 +1,5 @@ {{{ - exports({ to: app.makePath('resources/ssr.tsx') }) + exports({ to: app.makePath('inertia/app/ssr.tsx') }) }}} import { hydrate } from 'solid-js/web' @@ -9,8 +9,8 @@ export default function render(page: any) { return createInertiaApp({ page, resolve: (name) => { - const pages = import.meta.glob('./pages/**/*.tsx', { eager: true }) - {{ 'return pages[`./pages/${name}.tsx`]' }} + const pages = import.meta.glob('../pages/**/*.tsx', { eager: true }) + {{ 'return pages[`../pages/${name}.tsx`]' }} }, setup({ el, App, props }) { hydrate(() => , el) diff --git a/stubs/solid/tsconfig.json.stub b/stubs/solid/tsconfig.json.stub index 141bd8a..70b4969 100644 --- a/stubs/solid/tsconfig.json.stub +++ b/stubs/solid/tsconfig.json.stub @@ -1,26 +1,16 @@ {{{ - exports({ to: app.makePath('resources/tsconfig.json') }) + exports({ to: app.makePath('inertia/tsconfig.json') }) }}} { + "extends": "@adonisjs/tsconfig/tsconfig.client.json", "compilerOptions": { - "target": "ESNext", - "jsx": "preserve", - "jsxImportSource": "solid-js", - "lib": ["DOM", "ESNext", "DOM.Iterable", "ES2020"], - "useDefineForClassFields": true, "baseUrl": ".", + "jsx": "preserve", "module": "ESNext", - "moduleResolution": "Bundler", + "jsxImportSource": "solid-js", "paths": { - "@/*": ["./*"], - "~/*": ["../*"], + "~/*": ["./*"], }, - "resolveJsonModule": true, - "types": ["vite/client"], - "allowSyntheticDefaultImports": true, - "esModuleInterop": true, - "verbatimModuleSyntax": true, - "skipLibCheck": true, }, "include": ["./**/*.ts", "./**/*.tsx"], } diff --git a/stubs/svelte/app.ts.stub b/stubs/svelte/app.ts.stub index fa68765..4d29ee5 100644 --- a/stubs/svelte/app.ts.stub +++ b/stubs/svelte/app.ts.stub @@ -1,7 +1,7 @@ {{{ - exports({ to: app.makePath('resources/app.ts') }) + exports({ to: app.makePath('inertia/app/app.ts') }) }}} -import './css/app.css'; +import '../css/app.css'; import { createInertiaApp } from '@inertiajs/svelte' import { resolvePageComponent } from '@adonisjs/inertia/helpers' @@ -15,8 +15,8 @@ createInertiaApp({ resolve: (name) => { return resolvePageComponent( - {{ '`./pages/${name}.svelte`' }}, - import.meta.glob('./pages/**/*.svelte'), + {{ '`../pages/${name}.svelte`' }}, + import.meta.glob('../pages/**/*.svelte'), ) }, diff --git a/stubs/svelte/errors/not_found.svelte.stub b/stubs/svelte/errors/not_found.svelte.stub new file mode 100644 index 0000000..2ec6975 --- /dev/null +++ b/stubs/svelte/errors/not_found.svelte.stub @@ -0,0 +1,10 @@ +{{{ + exports({ to: app.makePath('inertia/pages/errors/not_found.svelte') }) +}}} +
+
+
Page not found
+ + This page does not exist. +
+
diff --git a/stubs/svelte/errors/server_error.svelte.stub b/stubs/svelte/errors/server_error.svelte.stub new file mode 100644 index 0000000..e194620 --- /dev/null +++ b/stubs/svelte/errors/server_error.svelte.stub @@ -0,0 +1,14 @@ +{{{ + exports({ to: app.makePath('inertia/pages/errors/server_error.svelte') }) +}}} + + +
+
+
Server Error
+ + {error.message} +
+
diff --git a/stubs/svelte/home.svelte.stub b/stubs/svelte/home.svelte.stub index 8891270..ba1ef6f 100644 --- a/stubs/svelte/home.svelte.stub +++ b/stubs/svelte/home.svelte.stub @@ -1,5 +1,5 @@ {{{ - exports({ to: app.makePath('resources/pages/home.svelte') }) + exports({ to: app.makePath('inertia/pages/home.svelte') }) }}} + + diff --git a/stubs/vue/home.vue.stub b/stubs/vue/home.vue.stub index d2922ea..a944c19 100644 --- a/stubs/vue/home.vue.stub +++ b/stubs/vue/home.vue.stub @@ -1,5 +1,5 @@ {{{ - exports({ to: app.makePath('resources/pages/home.vue') }) + exports({ to: app.makePath('inertia/pages/home.vue') }) }}}