create-guren-app 0.1.1-alpha.5 → 0.2.0-alpha.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -56,6 +56,8 @@ function toPackageName(value) {
56
56
  }
57
57
 
58
58
  // src/cli.ts
59
+ var RENDERING_MODES = ["spa", "ssr"];
60
+ var RENDERING_MODE_SET = new Set(RENDERING_MODES);
59
61
  async function ensureTargetDirectory(path, force) {
60
62
  try {
61
63
  await mkdir(path, { recursive: true });
@@ -88,6 +90,39 @@ async function replaceTokens(destination, files, tokens) {
88
90
  }
89
91
  }
90
92
  }
93
+ async function applySsrOverrides(destination) {
94
+ const ssrTemplateDir = fileURLToPath(new URL("../templates/default-ssr", import.meta.url));
95
+ await copyTemplate(ssrTemplateDir, destination);
96
+ }
97
+ async function updateSsrPackageJson(destination) {
98
+ const packageJsonPath = join(destination, "package.json");
99
+ const raw = await readFile(packageJsonPath, "utf8");
100
+ const pkg = JSON.parse(raw);
101
+ pkg.scripts ??= {};
102
+ pkg.scripts.build = "bunx vite build && bunx vite build --ssr";
103
+ await writeFile(packageJsonPath, `${JSON.stringify(pkg, null, 2)}
104
+ `, "utf8");
105
+ }
106
+ async function resolveRenderingMode(flagValue) {
107
+ if (typeof flagValue === "string") {
108
+ const normalized = flagValue.toLowerCase();
109
+ if (!RENDERING_MODE_SET.has(normalized)) {
110
+ throw new Error('Invalid rendering mode. Supported values are "spa" or "ssr".');
111
+ }
112
+ return normalized;
113
+ }
114
+ const result = await consola.prompt("Choose the rendering mode for this project", {
115
+ type: "select",
116
+ options: [
117
+ { value: "ssr", label: "SSR (server-side rendering)" },
118
+ { value: "spa", label: "SPA (client-side rendering only)" }
119
+ ],
120
+ initial: "ssr",
121
+ default: "ssr"
122
+ });
123
+ const value = typeof result === "string" ? result : "ssr";
124
+ return value ?? "ssr";
125
+ }
91
126
  var command = defineCommand({
92
127
  meta: {
93
128
  name: "create-guren-app",
@@ -103,6 +138,10 @@ var command = defineCommand({
103
138
  type: "boolean",
104
139
  alias: "f",
105
140
  description: "Overwrite existing files in the target directory"
141
+ },
142
+ mode: {
143
+ type: "string",
144
+ description: "Rendering mode to scaffold (spa or ssr)"
106
145
  }
107
146
  },
108
147
  async run({ args }) {
@@ -125,6 +164,10 @@ var command = defineCommand({
125
164
  const packageName = toPackageName(appName);
126
165
  const appTitle = toTitleCase(appName);
127
166
  await copyTemplate(templateDir, targetDir);
167
+ const renderingMode = await resolveRenderingMode(args.mode);
168
+ if (renderingMode === "ssr") {
169
+ await applySsrOverrides(targetDir);
170
+ }
128
171
  const tokenMap = /* @__PURE__ */ new Map([
129
172
  ["guren-app-placeholder", packageName],
130
173
  ["__APP_TITLE__", appTitle],
@@ -139,14 +182,20 @@ var command = defineCommand({
139
182
  "resources/js/pages/Home.tsx"
140
183
  ];
141
184
  await replaceTokens(targetDir, filesToTransform, tokenMap);
185
+ if (renderingMode === "ssr") {
186
+ await updateSsrPackageJson(targetDir);
187
+ }
142
188
  const relativeTarget = relative(process.cwd(), targetDir) || ".";
143
- consola.success(`Scaffolded a new Guren app in ${relativeTarget}`);
189
+ consola.success(`Scaffolded a new Guren app (${renderingMode.toUpperCase()}) in ${relativeTarget}`);
144
190
  consola.info("Next steps:");
145
191
  if (relativeTarget !== ".") {
146
192
  consola.log(` cd ${relativeTarget}`);
147
193
  }
148
194
  consola.log(" bun install");
149
195
  consola.log(" bun run dev");
196
+ if (renderingMode === "ssr") {
197
+ consola.log(" bun run build # builds both client and SSR bundles");
198
+ }
150
199
  }
151
200
  });
152
201
  runMain(command).catch((error) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-guren-app",
3
- "version": "0.1.1-alpha.5",
3
+ "version": "0.2.0-alpha.7",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -6,15 +6,20 @@ Welcome to your new Guren application.
6
6
 
7
7
  1. Install dependencies with `bun install`.
8
8
  2. Copy `.env.example` to `.env` and update any required values.
9
- 3. Start the development server with `bun run dev`.
9
+ 3. Start the development servers with `bun run dev` (runs Bun and Vite together).
10
10
 
11
11
  The default setup expects a PostgreSQL database. You can change the connection string in `config/database.ts` or set the `DATABASE_URL` environment variable before running the server.
12
12
 
13
13
  ## Available Scripts
14
14
 
15
- - `bun run dev` - start the local development server.
15
+ - `bun run dev` - start the Bun API server alongside the Vite dev server.
16
+ - `bun run build` - build production frontend assets with Vite.
17
+ - `bun run preview` - preview the production build locally.
18
+ - `bun run routes:types` - regenerate client-side route helpers.
16
19
  - `bun run db:make` - scaffold a new SQL migration from your schema using drizzle-kit.
17
20
  - `bun run db:migrate` - apply database migrations.
18
21
  - `bun run db:seed` - execute seeders.
19
22
 
23
+ Tailwind CSS is ready to use out of the box. Edit `resources/css/app.css` or add utilities to your components and the dev server will pick them up automatically.
24
+
20
25
  Happy hacking!
@@ -0,0 +1,10 @@
1
+ // Register model relationships here. Import this file once during boot so
2
+ // helpers like `hasMany`/`belongsTo` run after all models are defined.
3
+ //
4
+ // Example:
5
+ // import { Post } from './Post'
6
+ // import { User } from './User'
7
+ //
8
+ // User.hasMany('posts', Post, 'authorId', 'id')
9
+ // Post.belongsTo('author', User, 'authorId', 'id')
10
+
@@ -1,5 +1,5 @@
1
1
  import type { ApplicationContext, Provider } from '@guren/server'
2
- import { bootModels } from '../../config/app'
2
+ import { bootModels } from '../../config/app.js'
3
3
 
4
4
  export default class DatabaseProvider implements Provider {
5
5
  private initialized = false
@@ -1,4 +1,4 @@
1
- import app, { ready } from '../src/main'
1
+ import app, { ready } from '../src/main.js'
2
2
 
3
3
  try {
4
4
  await ready
@@ -10,5 +10,4 @@ try {
10
10
  const port = Number.parseInt(process.env.PORT ?? '', 10) || 3333
11
11
  const hostname = process.env.HOST ?? '0.0.0.0'
12
12
 
13
- app.listen({ port, hostname })
14
- console.log(`__APP_TITLE__ listening on http://${hostname}:${port}`)
13
+ await app.listen({ port, hostname })
@@ -1,4 +1,4 @@
1
- import { configureOrm, seedDatabase } from './database'
1
+ import { configureOrm, seedDatabase } from './database.js'
2
2
 
3
3
  let bootstrapped = false
4
4
 
@@ -1,5 +1,5 @@
1
1
  import { createPostgresDatabase } from '@guren/orm'
2
- import * as schema from '../db/schema'
2
+ import * as schema from '../db/schema.js'
3
3
 
4
4
  const database = createPostgresDatabase({
5
5
  schema,
@@ -4,17 +4,20 @@
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "scripts": {
7
- "dev": "bun run bin/serve.ts",
8
- "build": "bunx tsup --config tsup.config.ts",
7
+ "routes:types": "bunx guren routes:types --routes routes/web.ts --out types/generated/routes.d.ts --force",
8
+ "dev": "bun run dev:server",
9
+ "dev:server": "bun run --watch --hot bin/serve.ts",
10
+ "build": "bunx vite build",
11
+ "preview": "bunx vite preview",
9
12
  "db:make": "bunx guren make:migration",
10
13
  "db:migrate": "bunx guren db:migrate",
11
14
  "db:seed": "bunx guren db:seed"
12
15
  },
13
16
  "dependencies": {
14
- "@guren/cli": "^0.1.1-alpha.5",
15
- "@guren/inertia-client": "^0.1.1-alpha.5",
16
- "@guren/orm": "^0.1.1-alpha.5",
17
- "@guren/server": "^0.1.1-alpha.5",
17
+ "@guren/cli": "^0.2.0-alpha.7",
18
+ "@guren/inertia-client": "^0.2.0-alpha.7",
19
+ "@guren/orm": "^0.2.0-alpha.7",
20
+ "@guren/server": "^0.2.0-alpha.7",
18
21
  "@inertiajs/react": "^2.2.15",
19
22
  "drizzle-orm": "0.44.7",
20
23
  "postgres": "^3.4.3",
@@ -25,7 +28,10 @@
25
28
  "@types/react": "^19.0.0",
26
29
  "@types/react-dom": "^19.0.0",
27
30
  "drizzle-kit": "0.27.0",
28
- "tsup": "^8.5.0",
29
- "typescript": "^5.4.0"
31
+ "typescript": "^5.4.0",
32
+ "@vitejs/plugin-react": "^5.0.0",
33
+ "vite": "^7.0.0",
34
+ "@tailwindcss/vite": "^4.1.16",
35
+ "tailwindcss": "^4.1.16"
30
36
  }
31
37
  }
@@ -0,0 +1 @@
1
+ @import 'tailwindcss';
@@ -1,5 +1,15 @@
1
+ import '../css/app.css'
1
2
  import { startInertiaClient } from '@guren/inertia-client'
2
3
 
4
+ let pages: Record<string, () => Promise<unknown>> | undefined
5
+
6
+ try {
7
+ pages = import.meta.glob!('./pages/**/*.tsx')
8
+ } catch {
9
+ pages = undefined
10
+ }
11
+
3
12
  startInertiaClient({
4
- resolve: (name) => import(`./pages/${name}.tsx`),
13
+ pages,
14
+ resolve: pages ? undefined : (name) => import(`./pages/${name}.tsx`),
5
15
  })
@@ -0,0 +1,3 @@
1
+ import '@vite/client'
2
+ import '@vitejs/plugin-react/preamble'
3
+ import './app.tsx'
@@ -1,4 +1,4 @@
1
1
  import { Route } from '@guren/server'
2
- import HomeController from '../app/Http/Controllers/HomeController'
2
+ import HomeController from '../app/Http/Controllers/HomeController.js'
3
3
 
4
4
  Route.get('/', [HomeController, 'index'])
@@ -1,5 +1,5 @@
1
1
  import { Application } from '@guren/server'
2
- import DatabaseProvider from '../app/Providers/DatabaseProvider'
2
+ import DatabaseProvider from '../app/Providers/DatabaseProvider.js'
3
3
 
4
4
  const app = new Application({
5
5
  providers: [DatabaseProvider],
@@ -1,9 +1,11 @@
1
- import { configureInertiaAssets } from '@guren/server'
2
- import app from './app'
3
- import '../routes/web'
1
+ import { autoConfigureInertiaAssets } from '@guren/server'
2
+ import app from './app.js'
3
+ import '../routes/web.js'
4
+ import '../app/Models/relations.js'
4
5
 
5
- configureInertiaAssets(app, {
6
+ autoConfigureInertiaAssets(app, {
6
7
  importMeta: import.meta,
8
+ enableSsr: false,
7
9
  })
8
10
 
9
11
  export async function bootstrap() {
@@ -14,12 +14,17 @@
14
14
  "./app/*"
15
15
  ]
16
16
  },
17
+ "types": [
18
+ "bun-types",
19
+ "vite/client"
20
+ ],
17
21
  "jsx": "react-jsx"
18
22
  },
19
23
  "include": [
20
24
  "src",
21
25
  "app",
22
26
  "routes",
23
- "resources/js"
27
+ "resources/js",
28
+ "types"
24
29
  ]
25
- }
30
+ }
File without changes
@@ -0,0 +1,9 @@
1
+ import { routeTypesPlugin } from '@guren/cli/vite'
2
+ import { defineConfig } from 'vite'
3
+ import guren from '@guren/server/vite'
4
+ import react from '@vitejs/plugin-react'
5
+ import tailwindcss from '@tailwindcss/vite'
6
+
7
+ export default defineConfig({
8
+ plugins: [routeTypesPlugin(), guren(), react(), tailwindcss()],
9
+ })
@@ -0,0 +1,31 @@
1
+ # __APP_TITLE__
2
+
3
+ Welcome to your new Guren application. This template ships with Inertia server-side rendering enabled out of the box.
4
+
5
+ ## Getting Started
6
+
7
+ 1. Install dependencies with `bun install`.
8
+ 2. Copy `.env.example` to `.env` and update any required values.
9
+ 3. Start the development servers with `bun run dev` (runs Bun and Vite together).
10
+
11
+ During development the Bun server reads `resources/js/ssr.tsx` directly. Production builds rely on the Vite-generated SSR bundle and manifest, which are wired automatically by `src/main.ts` through `autoConfigureInertiaAssets`.
12
+
13
+ The default setup expects a PostgreSQL database. You can change the connection string in `config/database.ts` or set the `DATABASE_URL` environment variable before running the server.
14
+
15
+ ## Available Scripts
16
+
17
+ - `bun run dev` - start the Bun API server alongside the Vite dev server.
18
+ - `bun run build` - build both the client and SSR bundles with Vite.
19
+ - `bun run preview` - preview the production build locally.
20
+ - `bun run routes:types` - regenerate client-side route helpers.
21
+ - `bun run db:make` - scaffold a new SQL migration from your schema using drizzle-kit.
22
+ - `bun run db:migrate` - apply database migrations.
23
+ - `bun run db:seed` - execute seeders.
24
+
25
+ ### Production Builds
26
+
27
+ Run `bun run build` before deploying. This script internally executes `bunx vite build` and `bunx vite build --ssr` so the Bun server can stream pre-rendered HTML during the first request.
28
+
29
+ Tailwind CSS is ready to use out of the box. Edit `resources/css/app.css` or add utilities to your components and the dev server will pick them up automatically.
30
+
31
+ Happy hacking!
@@ -0,0 +1,19 @@
1
+ import type { Page } from '@inertiajs/core'
2
+ import { renderInertiaServer } from '@guren/inertia-client'
3
+ import type { InertiaSsrContext, InertiaSsrResult } from '@guren/server'
4
+
5
+ let pages: Record<string, () => Promise<unknown>> | undefined
6
+
7
+ try {
8
+ pages = import.meta.glob('./pages/**/*.tsx')
9
+ } catch {
10
+ pages = undefined
11
+ }
12
+
13
+ export default async function renderSsr(context: InertiaSsrContext): Promise<InertiaSsrResult> {
14
+ return renderInertiaServer({
15
+ page: context.page as Page,
16
+ pages,
17
+ resolve: pages ? undefined : (name) => import(`./pages/${name}.tsx`),
18
+ })
19
+ }
@@ -0,0 +1,17 @@
1
+ import { autoConfigureInertiaAssets } from '@guren/server'
2
+ import app from './app.js'
3
+ import '../routes/web.js'
4
+ import '../app/Models/relations.js'
5
+
6
+ autoConfigureInertiaAssets(app, {
7
+ importMeta: import.meta,
8
+ })
9
+
10
+ export async function bootstrap() {
11
+ await app.boot()
12
+ return app
13
+ }
14
+
15
+ export const ready = bootstrap()
16
+
17
+ export default app
@@ -1,12 +0,0 @@
1
- import { defineConfig } from 'tsup'
2
-
3
- export default defineConfig({
4
- entry: ['resources/js/app.tsx'],
5
- format: ['esm'],
6
- dts: false,
7
- splitting: false,
8
- sourcemap: true,
9
- outDir: 'public/assets',
10
- clean: true,
11
- target: 'esnext',
12
- })