create-guren-app 0.1.1-alpha.0

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/README.md ADDED
@@ -0,0 +1,9 @@
1
+ # create-guren-app
2
+
3
+ `create-guren-app` scaffolds a new Guren project with a sensible default directory layout.
4
+
5
+ ```bash
6
+ npx create-guren-app my-app
7
+ ```
8
+
9
+ Use `--force` to allow scaffolding into a non-empty directory.
package/dist/cli.js ADDED
@@ -0,0 +1,159 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/cli.ts
4
+ import { cp, mkdir, readFile, writeFile } from "fs/promises";
5
+ import { basename, join, relative, resolve } from "path";
6
+ import { fileURLToPath } from "url";
7
+ import process from "process";
8
+ import { consola } from "consola";
9
+ import { defineCommand, runMain } from "citty";
10
+
11
+ // src/utils.ts
12
+ import { readdir, stat } from "fs/promises";
13
+ async function directoryExists(path) {
14
+ try {
15
+ const stats = await stat(path);
16
+ return stats.isDirectory();
17
+ } catch (error) {
18
+ if (error.code === "ENOENT") {
19
+ return false;
20
+ }
21
+ throw error;
22
+ }
23
+ }
24
+ async function isDirectoryEmpty(path) {
25
+ try {
26
+ const entries = await readdir(path);
27
+ return entries.length === 0;
28
+ } catch (error) {
29
+ if (error.code === "ENOENT") {
30
+ return true;
31
+ }
32
+ throw error;
33
+ }
34
+ }
35
+ function toKebabCase(value) {
36
+ return value.replace(/([a-z0-9])([A-Z])/gu, "$1-$2").replace(/[^a-zA-Z0-9]+/gu, "-").toLowerCase().replace(/^-+|-+$/gu, "");
37
+ }
38
+ function toTitleCase(value) {
39
+ const words = value.replace(/[-_]+/gu, " ").split(/\s+/u).filter(Boolean);
40
+ if (words.length === 0) {
41
+ return "Guren App";
42
+ }
43
+ return words.map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join(" ");
44
+ }
45
+ function toPackageName(value) {
46
+ const trimmed = value.trim();
47
+ if (trimmed.startsWith("@")) {
48
+ const withoutScope = trimmed.slice(1);
49
+ const [scope, name = "guren-app"] = withoutScope.split("/", 2);
50
+ const safeScope = toKebabCase(scope);
51
+ const safeName = toKebabCase(name);
52
+ return `@${safeScope || "guren"}/${safeName || "app"}`;
53
+ }
54
+ const safe = toKebabCase(trimmed);
55
+ return safe || "guren-app";
56
+ }
57
+
58
+ // src/cli.ts
59
+ async function ensureTargetDirectory(path, force) {
60
+ try {
61
+ await mkdir(path, { recursive: true });
62
+ } catch (error) {
63
+ if (error.code === "EEXIST") {
64
+ throw new Error(`Path "${path}" exists and is not a directory.`);
65
+ }
66
+ throw error;
67
+ }
68
+ if (!force) {
69
+ const empty = await isDirectoryEmpty(path);
70
+ if (!empty) {
71
+ throw new Error(`Directory "${path}" is not empty. Use --force to scaffold anyway.`);
72
+ }
73
+ }
74
+ }
75
+ async function copyTemplate(template, destination) {
76
+ await cp(template, destination, { recursive: true, force: true });
77
+ }
78
+ async function replaceTokens(destination, files, tokens) {
79
+ for (const file of files) {
80
+ const path = join(destination, file);
81
+ const content = await readFile(path, "utf8");
82
+ let updated = content;
83
+ for (const [token, replacement] of tokens) {
84
+ updated = updated.split(token).join(replacement);
85
+ }
86
+ if (updated !== content) {
87
+ await writeFile(path, updated, "utf8");
88
+ }
89
+ }
90
+ }
91
+ var command = defineCommand({
92
+ meta: {
93
+ name: "create-guren-app",
94
+ description: "Scaffold a new Guren application."
95
+ },
96
+ args: {
97
+ target: {
98
+ type: "positional",
99
+ description: "Directory to create the application in",
100
+ default: "."
101
+ },
102
+ force: {
103
+ type: "boolean",
104
+ alias: "f",
105
+ description: "Overwrite existing files in the target directory"
106
+ }
107
+ },
108
+ async run({ args }) {
109
+ const target = args.target;
110
+ const force = Boolean(args.force);
111
+ const templateName = "default";
112
+ const templateDir = fileURLToPath(new URL(`../templates/${templateName}`, import.meta.url));
113
+ const targetDir = resolve(process.cwd(), target);
114
+ if (await directoryExists(targetDir)) {
115
+ if (!force) {
116
+ const empty = await isDirectoryEmpty(targetDir);
117
+ if (!empty) {
118
+ throw new Error(`Directory "${targetDir}" is not empty. Use --force to scaffold anyway.`);
119
+ }
120
+ }
121
+ } else {
122
+ await ensureTargetDirectory(targetDir, true);
123
+ }
124
+ const appName = basename(targetDir);
125
+ const packageName = toPackageName(appName);
126
+ const appTitle = toTitleCase(appName);
127
+ await copyTemplate(templateDir, targetDir);
128
+ const tokenMap = /* @__PURE__ */ new Map([
129
+ ["guren-app-placeholder", packageName],
130
+ ["__APP_TITLE__", appTitle],
131
+ ["__APP_NAME__", appName]
132
+ ]);
133
+ const filesToTransform = [
134
+ "README.md",
135
+ "package.json",
136
+ "public/index.html",
137
+ "bin/serve.ts",
138
+ "app/Http/Controllers/HomeController.ts",
139
+ "resources/js/pages/Home.tsx"
140
+ ];
141
+ await replaceTokens(targetDir, filesToTransform, tokenMap);
142
+ const relativeTarget = relative(process.cwd(), targetDir) || ".";
143
+ consola.success(`Scaffolded a new Guren app in ${relativeTarget}`);
144
+ consola.info("Next steps:");
145
+ if (relativeTarget !== ".") {
146
+ consola.log(` cd ${relativeTarget}`);
147
+ }
148
+ consola.log(" bun install");
149
+ consola.log(" bun run dev");
150
+ }
151
+ });
152
+ runMain(command).catch((error) => {
153
+ if (error instanceof Error) {
154
+ consola.error(error.message);
155
+ } else {
156
+ consola.error(String(error));
157
+ }
158
+ process.exit(1);
159
+ });
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "create-guren-app",
3
+ "version": "0.1.1-alpha.0",
4
+ "type": "module",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/gurenjs/guren",
9
+ "directory": "packages/create-app"
10
+ },
11
+ "homepage": "https://github.com/gurenjs/guren#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/gurenjs/guren/issues"
14
+ },
15
+ "publishConfig": {
16
+ "access": "public"
17
+ },
18
+ "files": [
19
+ "dist",
20
+ "templates"
21
+ ],
22
+ "bin": {
23
+ "create-guren-app": "./dist/cli.js"
24
+ },
25
+ "scripts": {
26
+ "build": "tsup",
27
+ "typecheck": "tsc --noEmit"
28
+ },
29
+ "dependencies": {
30
+ "citty": "^0.1.6",
31
+ "consola": "^3.4.2"
32
+ },
33
+ "devDependencies": {
34
+ "@types/node": "^20.14.10",
35
+ "tsup": "^8.5.0",
36
+ "typescript": "^5.4.0"
37
+ }
38
+ }
@@ -0,0 +1 @@
1
+ DATABASE_URL=postgres://guren:guren@localhost:54322/guren
@@ -0,0 +1,20 @@
1
+ # __APP_TITLE__
2
+
3
+ Welcome to your new Guren application.
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 server with `bun run dev`.
10
+
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
+
13
+ ## Available Scripts
14
+
15
+ - `bun run dev` - start the local development server.
16
+ - `bun run db:make` - scaffold a new SQL migration from your schema using drizzle-kit.
17
+ - `bun run db:migrate` - apply database migrations.
18
+ - `bun run db:seed` - execute seeders.
19
+
20
+ Happy hacking!
@@ -0,0 +1,11 @@
1
+ import { Controller, Context } from '@guren/server'
2
+
3
+ export default class HomeController extends Controller {
4
+ async index(ctx: Context): Promise<Response> {
5
+ const props = {
6
+ message: 'Welcome to __APP_TITLE__!',
7
+ }
8
+
9
+ return this.inertia('Home', props, { url: ctx.req.path, title: '__APP_TITLE__' })
10
+ }
11
+ }
File without changes
@@ -0,0 +1,15 @@
1
+ import type { ApplicationContext, Provider } from '@guren/server'
2
+ import { bootModels } from '../../config/app'
3
+
4
+ export default class DatabaseProvider implements Provider {
5
+ private initialized = false
6
+
7
+ async boot(_context: ApplicationContext): Promise<void> {
8
+ if (this.initialized) {
9
+ return
10
+ }
11
+
12
+ await bootModels()
13
+ this.initialized = true
14
+ }
15
+ }
@@ -0,0 +1,14 @@
1
+ import app, { ready } from '../src/main'
2
+
3
+ try {
4
+ await ready
5
+ } catch (error) {
6
+ console.error('Failed to bootstrap application:', error)
7
+ process.exit(1)
8
+ }
9
+
10
+ const port = Number.parseInt(process.env.PORT ?? '', 10) || 3333
11
+ const hostname = process.env.HOST ?? '0.0.0.0'
12
+
13
+ app.listen({ port, hostname })
14
+ console.log(`__APP_TITLE__ listening on http://${hostname}:${port}`)
@@ -0,0 +1,19 @@
1
+ import { configureOrm, seedDatabase } from './database'
2
+
3
+ let bootstrapped = false
4
+
5
+ export async function bootModels(): Promise<void> {
6
+ if (bootstrapped) {
7
+ return
8
+ }
9
+
10
+ try {
11
+ await configureOrm()
12
+ await seedDatabase()
13
+ } catch (error) {
14
+ const reason = error instanceof Error ? error.message : String(error)
15
+ console.warn('Skipping ORM bootstrap:', reason)
16
+ }
17
+
18
+ bootstrapped = true
19
+ }
@@ -0,0 +1,11 @@
1
+ import { createPostgresDatabase } from '@guren/orm'
2
+ import * as schema from '../db/schema'
3
+
4
+ const database = createPostgresDatabase({
5
+ schema,
6
+ migrationsFolder: new URL('../db/migrations', import.meta.url),
7
+ seedersFolder: new URL('../db/seeders', import.meta.url),
8
+ connectionString: () => process.env.DATABASE_URL ?? 'postgres://guren:guren@localhost:54322/guren',
9
+ })
10
+
11
+ export const { getDatabase, migrateDatabase, closeDatabase, configureOrm, seedDatabase } = database
File without changes
@@ -0,0 +1,8 @@
1
+ import { pgTable, serial, text, timestamp } from '@guren/orm/drizzle'
2
+
3
+ export const users = pgTable('users', {
4
+ id: serial('id').primaryKey(),
5
+ name: text('name').notNull(),
6
+ email: text('email').notNull(),
7
+ createdAt: timestamp('created_at', { withTimezone: false }).defaultNow().notNull(),
8
+ })
File without changes
@@ -0,0 +1,10 @@
1
+ import { defineConfig } from 'drizzle-kit'
2
+
3
+ export default defineConfig({
4
+ schema: './db/schema.ts',
5
+ out: './db/migrations',
6
+ dialect: 'postgresql',
7
+ dbCredentials: {
8
+ url: process.env.DATABASE_URL ?? 'postgres://guren:guren@localhost:54322/guren',
9
+ },
10
+ })
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "guren-app-placeholder",
3
+ "version": "0.1.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "bun run bin/serve.ts",
8
+ "build": "bunx tsup --config tsup.config.ts",
9
+ "db:make": "bunx guren make:migration",
10
+ "db:migrate": "bunx guren db:migrate",
11
+ "db:seed": "bunx guren db:seed"
12
+ },
13
+ "dependencies": {
14
+ "@guren/cli": "^0.1.0",
15
+ "@guren/inertia-client": "^0.1.0",
16
+ "@guren/orm": "^0.1.0",
17
+ "@guren/server": "^0.1.0",
18
+ "@inertiajs/react": "^2.2.15",
19
+ "drizzle-orm": "0.44.7",
20
+ "postgres": "^3.4.3",
21
+ "react": "^19.0.0",
22
+ "react-dom": "^19.0.0"
23
+ },
24
+ "devDependencies": {
25
+ "@types/react": "^19.0.0",
26
+ "@types/react-dom": "^19.0.0",
27
+ "drizzle-kit": "0.27.0",
28
+ "tsup": "^8.5.0",
29
+ "typescript": "^5.4.0"
30
+ }
31
+ }
@@ -0,0 +1,12 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <title>__APP_TITLE__</title>
6
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
7
+ </head>
8
+ <body>
9
+ <div id="app"></div>
10
+ <script type="module" src="/resources/js/app.tsx"></script>
11
+ </body>
12
+ </html>
@@ -0,0 +1,5 @@
1
+ import { startInertiaClient } from '@guren/inertia-client'
2
+
3
+ startInertiaClient({
4
+ resolve: (name) => import(`./pages/${name}.tsx`),
5
+ })
@@ -0,0 +1,19 @@
1
+ import { Head } from '@inertiajs/react'
2
+
3
+ interface HomeProps {
4
+ message: string
5
+ }
6
+
7
+ export default function Home({ message }: HomeProps) {
8
+ return (
9
+ <>
10
+ <Head title="__APP_TITLE__" />
11
+ <main style={{ fontFamily: 'system-ui, sans-serif', margin: '4rem auto', maxWidth: '640px' }}>
12
+ <h1 style={{ fontSize: '2.5rem', marginBottom: '1rem' }}>{message}</h1>
13
+ <p style={{ fontSize: '1.125rem', lineHeight: 1.6 }}>
14
+ Edit <code>resources/js/pages/Home.tsx</code> or <code>app/Http/Controllers/HomeController.ts</code> to get started.
15
+ </p>
16
+ </main>
17
+ </>
18
+ )
19
+ }
@@ -0,0 +1,4 @@
1
+ import { Route } from '@guren/server'
2
+ import HomeController from '../app/Http/Controllers/HomeController'
3
+
4
+ Route.get('/', [HomeController, 'index'])
@@ -0,0 +1,8 @@
1
+ import { Application } from '@guren/server'
2
+ import DatabaseProvider from '../app/Providers/DatabaseProvider'
3
+
4
+ const app = new Application({
5
+ providers: [DatabaseProvider],
6
+ })
7
+
8
+ export default app
@@ -0,0 +1,16 @@
1
+ import { configureInertiaAssets } from '@guren/server'
2
+ import app from './app'
3
+ import '../routes/web'
4
+
5
+ configureInertiaAssets(app, {
6
+ importMeta: import.meta,
7
+ })
8
+
9
+ export async function bootstrap() {
10
+ await app.boot()
11
+ return app
12
+ }
13
+
14
+ export const ready = bootstrap()
15
+
16
+ export default app
@@ -0,0 +1,25 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "NodeNext",
5
+ "moduleResolution": "NodeNext",
6
+ "strict": true,
7
+ "esModuleInterop": true,
8
+ "resolveJsonModule": true,
9
+ "forceConsistentCasingInFileNames": true,
10
+ "skipLibCheck": true,
11
+ "baseUrl": ".",
12
+ "paths": {
13
+ "@/*": [
14
+ "./app/*"
15
+ ]
16
+ },
17
+ "jsx": "react-jsx"
18
+ },
19
+ "include": [
20
+ "src",
21
+ "app",
22
+ "routes",
23
+ "resources/js"
24
+ ]
25
+ }
@@ -0,0 +1,12 @@
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
+ })