create-thexjs-app 1.0.0 → 1.1.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 +56 -915
- package/dist/index.js +265 -196
- package/package.json +5 -1
- package/templates/{basic → addons/auth}/src/api/auth/login.ts +1 -3
- package/templates/{basic → addons/auth}/src/lib/auth.ts +13 -9
- package/templates/{basic → addons/auth}/src/lib/migrations/001_create_sessions.sql +1 -3
- package/templates/addons/auth/src/pages/dashboard/index.tsx +39 -0
- package/templates/addons/auth/src/pages/login.tsx +72 -0
- package/templates/addons/content/content/hello-world.md +13 -0
- package/templates/addons/content/src/pages/blog.tsx +29 -0
- package/templates/{basic → addons/shadcn}/components.json +1 -1
- package/templates/addons/shadcn/src/components/ui/badge.tsx +17 -0
- package/templates/addons/shadcn/src/components/ui/button.tsx +36 -0
- package/templates/addons/shadcn/src/components/ui/card.tsx +33 -0
- package/templates/addons/shadcn/src/components/ui/input.tsx +18 -0
- package/templates/addons/tailwind/src/styles/globals.css +32 -0
- package/templates/base/src/pages/index.tsx +29 -0
- package/templates/base/src/styles/globals.css +22 -0
- package/templates/base/tsconfig.json +24 -0
- package/templates/basic/content/blog/hello.md +0 -8
- package/templates/basic/public/favicon.ico +0 -0
- package/templates/basic/src/actions/dashboard/greet.ts +0 -3
- package/templates/basic/src/api/placeholder/comments.ts +0 -17
- package/templates/basic/src/api/placeholder/posts.ts +0 -20
- package/templates/basic/src/api/placeholder/todos.ts +0 -21
- package/templates/basic/src/api/placeholder/users.ts +0 -12
- package/templates/basic/src/components/Head.tsx +0 -21
- package/templates/basic/src/components/Image.tsx +0 -27
- package/templates/basic/src/components/Link.tsx +0 -10
- package/templates/basic/src/components/ui/badge.tsx +0 -49
- package/templates/basic/src/components/ui/button.tsx +0 -58
- package/templates/basic/src/components/ui/card.tsx +0 -88
- package/templates/basic/src/components/ui/input.tsx +0 -20
- package/templates/basic/src/layouts/main.tsx +0 -38
- package/templates/basic/src/lib/placeholder-data.ts +0 -176
- package/templates/basic/src/pages/_404.tsx +0 -17
- package/templates/basic/src/pages/about.tsx +0 -22
- package/templates/basic/src/pages/blog.tsx +0 -41
- package/templates/basic/src/pages/dashboard/index.tsx +0 -84
- package/templates/basic/src/pages/index.tsx +0 -54
- package/templates/basic/src/pages/login.tsx +0 -92
- package/templates/basic/src/pages/placeholder.tsx +0 -203
- package/templates/basic/src/pages/posts/[id].tsx +0 -17
- package/templates/basic/src/styles/globals.css +0 -90
- package/templates/basic/src/x-routes.ts +0 -29
- package/templates/basic/tsconfig.json +0 -11
- package/templates/basic/x.config.ts +0 -10
- package/templates/blog/components.json +0 -20
- package/templates/blog/content/posts/getting-started.md +0 -38
- package/templates/blog/content/posts/hello-world.md +0 -21
- package/templates/blog/content/posts/tailwind-v4.md +0 -31
- package/templates/blog/public/favicon.ico +0 -0
- package/templates/blog/src/components/ui/avatar.tsx +0 -91
- package/templates/blog/src/components/ui/badge.tsx +0 -49
- package/templates/blog/src/components/ui/button.tsx +0 -58
- package/templates/blog/src/components/ui/card.tsx +0 -88
- package/templates/blog/src/components/ui/input.tsx +0 -20
- package/templates/blog/src/layouts/blog.tsx +0 -46
- package/templates/blog/src/layouts/main.tsx +0 -32
- package/templates/blog/src/lib/utils.ts +0 -5
- package/templates/blog/src/pages/about.tsx +0 -36
- package/templates/blog/src/pages/blog/[slug].tsx +0 -56
- package/templates/blog/src/pages/blog/index.tsx +0 -70
- package/templates/blog/src/pages/index.tsx +0 -73
- package/templates/blog/src/styles/globals.css +0 -90
- package/templates/blog/src/x-routes.ts +0 -20
- package/templates/blog/tsconfig.json +0 -5
- package/templates/blog/x.config.ts +0 -6
- package/templates/default/components.json +0 -19
- package/templates/default/src/layouts/main.tsx +0 -28
- package/templates/default/src/pages/index.tsx +0 -66
- package/templates/default/src/styles/globals.css +0 -55
- package/templates/default/src/x-routes.ts +0 -17
- package/templates/default/tsconfig.json +0 -5
- package/templates/default/x.config.ts +0 -6
- package/templates/landing/components.json +0 -20
- package/templates/landing/public/favicon.ico +0 -0
- package/templates/landing/src/components/code-block.tsx +0 -118
- package/templates/landing/src/components/ui/avatar.tsx +0 -91
- package/templates/landing/src/components/ui/badge.tsx +0 -49
- package/templates/landing/src/components/ui/button.tsx +0 -58
- package/templates/landing/src/components/ui/card.tsx +0 -88
- package/templates/landing/src/components/ui/input.tsx +0 -20
- package/templates/landing/src/layouts/main.tsx +0 -78
- package/templates/landing/src/lib/syntax.tsx +0 -366
- package/templates/landing/src/lib/utils.ts +0 -5
- package/templates/landing/src/pages/docs/_layout.tsx +0 -139
- package/templates/landing/src/pages/docs/api-routes.tsx +0 -113
- package/templates/landing/src/pages/docs/build-deploy.tsx +0 -124
- package/templates/landing/src/pages/docs/configuration.tsx +0 -121
- package/templates/landing/src/pages/docs/content-collections.tsx +0 -130
- package/templates/landing/src/pages/docs/data-layer.tsx +0 -142
- package/templates/landing/src/pages/docs/getting-started.tsx +0 -129
- package/templates/landing/src/pages/docs/index.tsx +0 -187
- package/templates/landing/src/pages/docs/installation.tsx +0 -143
- package/templates/landing/src/pages/docs/introduction.tsx +0 -114
- package/templates/landing/src/pages/docs/layouts.tsx +0 -114
- package/templates/landing/src/pages/docs/middleware.tsx +0 -124
- package/templates/landing/src/pages/docs/packages/cli.tsx +0 -133
- package/templates/landing/src/pages/docs/packages/core.tsx +0 -176
- package/templates/landing/src/pages/docs/packages/env.tsx +0 -128
- package/templates/landing/src/pages/docs/pages.tsx +0 -135
- package/templates/landing/src/pages/docs/routing.tsx +0 -123
- package/templates/landing/src/pages/docs/server-functions.tsx +0 -177
- package/templates/landing/src/pages/features.tsx +0 -129
- package/templates/landing/src/pages/index.tsx +0 -159
- package/templates/landing/src/styles/globals.css +0 -136
- package/templates/landing/src/x-routes.ts +0 -31
- package/templates/landing/tsconfig.json +0 -10
- package/templates/landing/x.config.ts +0 -2
- package/templates/saas/components.json +0 -20
- package/templates/saas/public/favicon.ico +0 -0
- package/templates/saas/src/actions/dashboard.ts +0 -3
- package/templates/saas/src/api/auth/login.ts +0 -31
- package/templates/saas/src/components/ui/avatar.tsx +0 -91
- package/templates/saas/src/components/ui/badge.tsx +0 -49
- package/templates/saas/src/components/ui/button.tsx +0 -58
- package/templates/saas/src/components/ui/card.tsx +0 -88
- package/templates/saas/src/components/ui/input.tsx +0 -20
- package/templates/saas/src/layouts/dashboard.tsx +0 -67
- package/templates/saas/src/layouts/main.tsx +0 -38
- package/templates/saas/src/lib/auth.ts +0 -91
- package/templates/saas/src/lib/migrations/001_create_sessions.sql +0 -9
- package/templates/saas/src/lib/utils.ts +0 -5
- package/templates/saas/src/pages/dashboard/_middleware.ts +0 -9
- package/templates/saas/src/pages/dashboard/analytics.tsx +0 -68
- package/templates/saas/src/pages/dashboard/index.tsx +0 -86
- package/templates/saas/src/pages/dashboard/settings.tsx +0 -111
- package/templates/saas/src/pages/index.tsx +0 -110
- package/templates/saas/src/pages/login.tsx +0 -140
- package/templates/saas/src/pages/pricing.tsx +0 -121
- package/templates/saas/src/styles/globals.css +0 -90
- package/templates/saas/src/x-routes.ts +0 -22
- package/templates/saas/tsconfig.json +0 -5
- package/templates/saas/x.config.ts +0 -7
- /package/templates/{basic → addons/auth}/src/api/auth/logout.ts +0 -0
- /package/templates/{basic → addons/auth}/src/pages/dashboard/_middleware.ts +0 -0
- /package/templates/{basic → addons/shadcn}/src/lib/utils.ts +0 -0
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import type { RouteProps } from "@thexjs/core";
|
|
2
|
-
import { ArrowRight } from "lucide-react";
|
|
3
|
-
import { CodeBlock } from "../../../components/code-block";
|
|
4
|
-
|
|
5
|
-
export const mode = "static";
|
|
6
|
-
|
|
7
|
-
export default function DocPage(_props: RouteProps) {
|
|
8
|
-
return (
|
|
9
|
-
<div>
|
|
10
|
-
<p className="text-xs font-semibold uppercase tracking-[0.2em] text-primary">Packages</p>
|
|
11
|
-
<h1 className="mt-4 text-3xl font-bold tracking-tight sm:text-4xl">@thexjs/cli</h1>
|
|
12
|
-
<p className="mt-4 text-lg text-muted-foreground">
|
|
13
|
-
The <span className="text-foreground">x</span> command-line tool — dev server, production
|
|
14
|
-
build, and production start, built on Bun.
|
|
15
|
-
</p>
|
|
16
|
-
|
|
17
|
-
<CodeBlock label="terminal" lang="bash" code="bun add @thexjs/cli" />
|
|
18
|
-
<p className="mt-4 text-sm text-muted-foreground">
|
|
19
|
-
Requires Bun on your PATH. The CLI shells out to{" "}
|
|
20
|
-
<span className="text-foreground">bun</span> and uses Bun-only APIs (
|
|
21
|
-
<span className="text-foreground">Bun.serve</span>,{" "}
|
|
22
|
-
<span className="text-foreground">Bun.argv</span>).
|
|
23
|
-
</p>
|
|
24
|
-
|
|
25
|
-
<h2 className="mt-12 text-xl font-bold tracking-tight">Commands</h2>
|
|
26
|
-
<CodeBlock
|
|
27
|
-
label="commands"
|
|
28
|
-
code={`x dev # start the dev server with hot reload
|
|
29
|
-
x build # build for production -> .x/
|
|
30
|
-
x start # run the production server (run x build first)
|
|
31
|
-
|
|
32
|
-
x run dev # "run" is optional — alias for npm/bun muscle memory
|
|
33
|
-
|
|
34
|
-
-h, --help # show help
|
|
35
|
-
-v, --version # print installed @thexjs/cli version
|
|
36
|
-
--cwd <dir> # run as if started inside <dir>`}
|
|
37
|
-
/>
|
|
38
|
-
|
|
39
|
-
<h2 className="mt-12 text-xl font-bold tracking-tight">package.json scripts</h2>
|
|
40
|
-
<CodeBlock
|
|
41
|
-
label="package.json"
|
|
42
|
-
code={`{
|
|
43
|
-
"scripts": {
|
|
44
|
-
"dev": "x dev",
|
|
45
|
-
"build": "x build",
|
|
46
|
-
"start": "x start"
|
|
47
|
-
}
|
|
48
|
-
}`}
|
|
49
|
-
/>
|
|
50
|
-
|
|
51
|
-
<h2 className="mt-12 text-xl font-bold tracking-tight">Configuration</h2>
|
|
52
|
-
<p className="mt-3 text-muted-foreground">
|
|
53
|
-
The CLI reads <span className="text-foreground">x.config.ts</span> (or{" "}
|
|
54
|
-
<span className="text-foreground">.js</span> / <span className="text-foreground">.mjs</span>
|
|
55
|
-
) and passes its <span className="text-foreground">defineConfig(...)</span> export to{" "}
|
|
56
|
-
<span className="text-foreground">@thexjs/core</span>:
|
|
57
|
-
</p>
|
|
58
|
-
<CodeBlock
|
|
59
|
-
label="x.config.ts"
|
|
60
|
-
code={`import { defineConfig } from "@thexjs/core";
|
|
61
|
-
|
|
62
|
-
export default defineConfig({
|
|
63
|
-
pagesDir: "./src/pages",
|
|
64
|
-
contentDir: "./src/content",
|
|
65
|
-
port: 3000,
|
|
66
|
-
});`}
|
|
67
|
-
/>
|
|
68
|
-
<p className="mt-4 text-muted-foreground">
|
|
69
|
-
Without a config file, defaults apply: <span className="text-foreground">src/pages</span>{" "}
|
|
70
|
-
for pages, <span className="text-foreground">content</span> for content collections if
|
|
71
|
-
present, port <span className="text-foreground">3000</span>.
|
|
72
|
-
</p>
|
|
73
|
-
|
|
74
|
-
<h2 className="mt-12 text-xl font-bold tracking-tight">What each command does</h2>
|
|
75
|
-
|
|
76
|
-
<h3 className="mt-8 text-lg font-semibold">x dev</h3>
|
|
77
|
-
<p className="mt-2 text-muted-foreground">
|
|
78
|
-
Auto-compiles <span className="text-foreground">src/styles/globals.css</span> via{" "}
|
|
79
|
-
<span className="text-foreground">bunx tailwindcss</span> when that file exists, watches{" "}
|
|
80
|
-
<span className="text-foreground">src/styles</span>, then starts{" "}
|
|
81
|
-
<span className="text-foreground">createApp()</span> under{" "}
|
|
82
|
-
<span className="text-foreground">Bun.serve</span>. If the port is taken, tries up to 20
|
|
83
|
-
ports upward.
|
|
84
|
-
</p>
|
|
85
|
-
|
|
86
|
-
<h3 className="mt-8 text-lg font-semibold">x build</h3>
|
|
87
|
-
<p className="mt-2 text-muted-foreground">
|
|
88
|
-
Compiles Tailwind in production mode, then writes:
|
|
89
|
-
</p>
|
|
90
|
-
<ul className="mt-3 list-inside list-disc space-y-2 text-muted-foreground">
|
|
91
|
-
<li>
|
|
92
|
-
<span className="text-foreground">.x/client/</span> — prerendered HTML for static pages,
|
|
93
|
-
plus <span className="text-foreground">public/</span> assets. Deployable to any static
|
|
94
|
-
host.
|
|
95
|
-
</li>
|
|
96
|
-
<li>
|
|
97
|
-
<span className="text-foreground">.x/server/index.ts</span> — server entry for SSR pages
|
|
98
|
-
and API routes. Requires a Bun-capable host.
|
|
99
|
-
</li>
|
|
100
|
-
</ul>
|
|
101
|
-
|
|
102
|
-
<h3 className="mt-8 text-lg font-semibold">x start</h3>
|
|
103
|
-
<p className="mt-2 text-muted-foreground">
|
|
104
|
-
Runs <span className="text-foreground">.x/server/index.ts</span> with{" "}
|
|
105
|
-
<span className="text-foreground">NODE_ENV=production</span>. Exits with an error if the
|
|
106
|
-
build output is missing.
|
|
107
|
-
</p>
|
|
108
|
-
|
|
109
|
-
<h2 className="mt-12 text-xl font-bold tracking-tight">Deployment</h2>
|
|
110
|
-
<p className="mt-3 text-muted-foreground">
|
|
111
|
-
If every page uses <span className="text-foreground">mode = "static"</span> and you have no
|
|
112
|
-
API routes, deploy <span className="text-foreground">.x/client/</span> to any static host.
|
|
113
|
-
Server-mode pages need a host that keeps a Bun process running (Fly.io, Railway, Docker,
|
|
114
|
-
VPS) and runs <span className="text-foreground">x start</span>.
|
|
115
|
-
</p>
|
|
116
|
-
|
|
117
|
-
<div className="mt-16 flex flex-wrap gap-6 border-t border-border pt-8">
|
|
118
|
-
<a
|
|
119
|
-
href="/docs/packages/env"
|
|
120
|
-
className="inline-flex items-center gap-1 text-sm font-medium text-primary transition-colors hover:text-primary/80"
|
|
121
|
-
>
|
|
122
|
-
@thexjs/env <ArrowRight className="h-3.5 w-3.5" />
|
|
123
|
-
</a>
|
|
124
|
-
<a
|
|
125
|
-
href="/docs"
|
|
126
|
-
className="inline-flex items-center gap-1 text-sm text-muted-foreground transition-colors hover:text-foreground"
|
|
127
|
-
>
|
|
128
|
-
<ArrowRight className="h-3.5 w-3.5 rotate-180" /> Back to docs
|
|
129
|
-
</a>
|
|
130
|
-
</div>
|
|
131
|
-
</div>
|
|
132
|
-
);
|
|
133
|
-
}
|
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
import type { RouteProps } from "@thexjs/core";
|
|
2
|
-
import { ArrowRight } from "lucide-react";
|
|
3
|
-
import { CodeBlock } from "../../../components/code-block";
|
|
4
|
-
|
|
5
|
-
export const mode = "static";
|
|
6
|
-
|
|
7
|
-
export default function DocPage(_props: RouteProps) {
|
|
8
|
-
return (
|
|
9
|
-
<div>
|
|
10
|
-
<p className="text-xs font-semibold uppercase tracking-[0.2em] text-primary">Packages</p>
|
|
11
|
-
<h1 className="mt-4 text-3xl font-bold tracking-tight sm:text-4xl">@thexjs/core</h1>
|
|
12
|
-
<p className="mt-4 text-lg text-muted-foreground">
|
|
13
|
-
The rendering and routing engine behind x — file-based routing, SSR/SSG, islands, server
|
|
14
|
-
functions, content collections, and a lightweight data layer.
|
|
15
|
-
</p>
|
|
16
|
-
|
|
17
|
-
<CodeBlock label="terminal" lang="bash" code="bun add @thexjs/core" />
|
|
18
|
-
<p className="mt-4 text-sm text-muted-foreground">
|
|
19
|
-
Requires Bun. You typically do not install this directly —{" "}
|
|
20
|
-
<a href="/docs/packages/cli" className="text-primary underline underline-offset-2">
|
|
21
|
-
@thexjs/cli
|
|
22
|
-
</a>{" "}
|
|
23
|
-
depends on it and drives <span className="text-foreground">x dev</span> /{" "}
|
|
24
|
-
<span className="text-foreground">x build</span> /{" "}
|
|
25
|
-
<span className="text-foreground">x start</span>.
|
|
26
|
-
</p>
|
|
27
|
-
|
|
28
|
-
<h2 className="mt-12 text-xl font-bold tracking-tight">Quick start</h2>
|
|
29
|
-
<CodeBlock
|
|
30
|
-
label="x.config.ts"
|
|
31
|
-
code={`import { defineConfig } from "@thexjs/core";
|
|
32
|
-
|
|
33
|
-
export default defineConfig({
|
|
34
|
-
pagesDir: "./src/pages",
|
|
35
|
-
contentDir: "./src/content",
|
|
36
|
-
port: 3000,
|
|
37
|
-
});`}
|
|
38
|
-
/>
|
|
39
|
-
<CodeBlock
|
|
40
|
-
label="src/pages/index.tsx"
|
|
41
|
-
code={`import type { RouteProps } from "@thexjs/core";
|
|
42
|
-
|
|
43
|
-
export const mode = "static";
|
|
44
|
-
|
|
45
|
-
export default function HomePage({}: RouteProps) {
|
|
46
|
-
return <h1>Hello from x</h1>;
|
|
47
|
-
}`}
|
|
48
|
-
/>
|
|
49
|
-
|
|
50
|
-
<h2 className="mt-12 text-xl font-bold tracking-tight">File-based routing</h2>
|
|
51
|
-
<CodeBlock
|
|
52
|
-
label="route mapping"
|
|
53
|
-
code={`File Route
|
|
54
|
-
────────────────────────────────────────────
|
|
55
|
-
src/pages/index.tsx /
|
|
56
|
-
src/pages/about.tsx /about
|
|
57
|
-
src/pages/blog/[slug].tsx /blog/:slug
|
|
58
|
-
src/pages/api/users.ts API route at /api/users
|
|
59
|
-
src/pages/_layout.tsx Wraps routes in directory
|
|
60
|
-
src/pages/_middleware.ts Runs before matching routes
|
|
61
|
-
src/pages/_404.tsx Custom not-found page`}
|
|
62
|
-
/>
|
|
63
|
-
<p className="mt-4 text-muted-foreground">
|
|
64
|
-
Files and directories prefixed with <span className="text-foreground">_</span> or{" "}
|
|
65
|
-
<span className="text-foreground">.</span> are never treated as routes.
|
|
66
|
-
</p>
|
|
67
|
-
|
|
68
|
-
<h2 className="mt-12 text-xl font-bold tracking-tight">Route modes</h2>
|
|
69
|
-
<p className="mt-3 text-muted-foreground">
|
|
70
|
-
Every page defaults to server-rendered. Opt into build-time prerendering:
|
|
71
|
-
</p>
|
|
72
|
-
<CodeBlock
|
|
73
|
-
label="src/pages/index.tsx"
|
|
74
|
-
code={`export const mode: "static" | "server" = "static";`}
|
|
75
|
-
/>
|
|
76
|
-
<ul className="mt-4 list-inside list-disc space-y-2 text-muted-foreground">
|
|
77
|
-
<li>
|
|
78
|
-
<span className="text-foreground">static</span> — rendered once at build time to HTML in{" "}
|
|
79
|
-
<span className="text-foreground">.x/client/</span>
|
|
80
|
-
</li>
|
|
81
|
-
<li>
|
|
82
|
-
<span className="text-foreground">server</span> — rendered per request via{" "}
|
|
83
|
-
<span className="text-foreground">x start</span> or{" "}
|
|
84
|
-
<span className="text-foreground">x dev</span>
|
|
85
|
-
</li>
|
|
86
|
-
</ul>
|
|
87
|
-
|
|
88
|
-
<h2 className="mt-12 text-xl font-bold tracking-tight">Loaders</h2>
|
|
89
|
-
<CodeBlock
|
|
90
|
-
label="loader example"
|
|
91
|
-
code={`import type { RouteProps } from "@thexjs/core";
|
|
92
|
-
|
|
93
|
-
export async function loader({ params }: { params: Record<string, string> }) {
|
|
94
|
-
return { user: await getUser(params.id) };
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export default function UserPage({ loaderData }: RouteProps<typeof loader>) {
|
|
98
|
-
return <p>{loaderData.user.name}</p>;
|
|
99
|
-
}`}
|
|
100
|
-
/>
|
|
101
|
-
|
|
102
|
-
<h2 className="mt-12 text-xl font-bold tracking-tight">Islands</h2>
|
|
103
|
-
<p className="mt-3 text-muted-foreground">
|
|
104
|
-
Wrap interactive pieces in <span className="text-foreground"><Island></span> for
|
|
105
|
-
selective hydration:
|
|
106
|
-
</p>
|
|
107
|
-
<CodeBlock
|
|
108
|
-
label="island"
|
|
109
|
-
code={`import { Island } from "@thexjs/core";
|
|
110
|
-
|
|
111
|
-
<Island name="like-button" client="visible">
|
|
112
|
-
<LikeButton />
|
|
113
|
-
</Island>`}
|
|
114
|
-
/>
|
|
115
|
-
<p className="mt-4 text-muted-foreground">
|
|
116
|
-
<span className="text-foreground">client</span> accepts{" "}
|
|
117
|
-
<span className="text-foreground">"idle"</span>,{" "}
|
|
118
|
-
<span className="text-foreground">"visible"</span>, or{" "}
|
|
119
|
-
<span className="text-foreground">"load"</span>.
|
|
120
|
-
</p>
|
|
121
|
-
|
|
122
|
-
<h2 className="mt-12 text-xl font-bold tracking-tight">Content collections</h2>
|
|
123
|
-
<CodeBlock
|
|
124
|
-
label="markdown"
|
|
125
|
-
code={`import { scanContent, renderMarkdown } from "@thexjs/core";
|
|
126
|
-
|
|
127
|
-
const posts = scanContent("./src/content/blog");
|
|
128
|
-
const html = renderMarkdown(posts[0].body);`}
|
|
129
|
-
/>
|
|
130
|
-
|
|
131
|
-
<h2 className="mt-12 text-xl font-bold tracking-tight">Data layer</h2>
|
|
132
|
-
<CodeBlock
|
|
133
|
-
label="sqlite"
|
|
134
|
-
code={`import { connectSQLite, runSQLiteMigrations } from "@thexjs/core/data";
|
|
135
|
-
|
|
136
|
-
const db = connectSQLite({ filename: "./data/dev.db" });
|
|
137
|
-
await runSQLiteMigrations(db, "./data/migrations");`}
|
|
138
|
-
/>
|
|
139
|
-
<CodeBlock
|
|
140
|
-
label="postgres"
|
|
141
|
-
code={`import { connectPostgres, runPostgresMigrations } from "@thexjs/core/data";
|
|
142
|
-
|
|
143
|
-
const sql = connectPostgres({ url: process.env.DATABASE_URL! });
|
|
144
|
-
await runPostgresMigrations(sql, "./data/migrations");`}
|
|
145
|
-
/>
|
|
146
|
-
|
|
147
|
-
<h2 className="mt-12 text-xl font-bold tracking-tight">Key exports</h2>
|
|
148
|
-
<CodeBlock
|
|
149
|
-
label="exports"
|
|
150
|
-
code={`defineConfig, createApp, build App setup & build
|
|
151
|
-
renderPage, renderStaticPage Lower-level rendering
|
|
152
|
-
scanRoutes, scanPages, scanApiDir Routing internals
|
|
153
|
-
Island, IslandProvider Selective hydration
|
|
154
|
-
scanContent, renderMarkdown Markdown content
|
|
155
|
-
composeMiddleware, MiddlewareFn Route middleware
|
|
156
|
-
registerServerFunctions Server function internals
|
|
157
|
-
connectSQLite, connectPostgres Data layer`}
|
|
158
|
-
/>
|
|
159
|
-
|
|
160
|
-
<div className="mt-16 flex flex-wrap gap-6 border-t border-border pt-8">
|
|
161
|
-
<a
|
|
162
|
-
href="/docs/packages/cli"
|
|
163
|
-
className="inline-flex items-center gap-1 text-sm font-medium text-primary transition-colors hover:text-primary/80"
|
|
164
|
-
>
|
|
165
|
-
@thexjs/cli <ArrowRight className="h-3.5 w-3.5" />
|
|
166
|
-
</a>
|
|
167
|
-
<a
|
|
168
|
-
href="/docs"
|
|
169
|
-
className="inline-flex items-center gap-1 text-sm text-muted-foreground transition-colors hover:text-foreground"
|
|
170
|
-
>
|
|
171
|
-
<ArrowRight className="h-3.5 w-3.5 rotate-180" /> Back to docs
|
|
172
|
-
</a>
|
|
173
|
-
</div>
|
|
174
|
-
</div>
|
|
175
|
-
);
|
|
176
|
-
}
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import type { RouteProps } from "@thexjs/core";
|
|
2
|
-
import { ArrowRight } from "lucide-react";
|
|
3
|
-
import { CodeBlock } from "../../../components/code-block";
|
|
4
|
-
|
|
5
|
-
export const mode = "static";
|
|
6
|
-
|
|
7
|
-
export default function DocPage(_props: RouteProps) {
|
|
8
|
-
return (
|
|
9
|
-
<div>
|
|
10
|
-
<p className="text-xs font-semibold uppercase tracking-[0.2em] text-primary">Packages</p>
|
|
11
|
-
<h1 className="mt-4 text-3xl font-bold tracking-tight sm:text-4xl">@thexjs/env</h1>
|
|
12
|
-
<p className="mt-4 text-lg text-muted-foreground">
|
|
13
|
-
Type-safe environment variable validation for x apps. Define a schema once, get parsed and
|
|
14
|
-
typed values back, and fail fast with a clear error if something is missing or malformed.
|
|
15
|
-
</p>
|
|
16
|
-
|
|
17
|
-
<CodeBlock label="terminal" lang="bash" code="bun add @thexjs/env" />
|
|
18
|
-
|
|
19
|
-
<h2 className="mt-12 text-xl font-bold tracking-tight">Quick start</h2>
|
|
20
|
-
<CodeBlock
|
|
21
|
-
label="env.ts"
|
|
22
|
-
code={`import { createEnv, str, num, bool, oneOf, url } from "@thexjs/env";
|
|
23
|
-
|
|
24
|
-
export const env = createEnv({
|
|
25
|
-
server: {
|
|
26
|
-
DATABASE_URL: url(),
|
|
27
|
-
PORT: num(),
|
|
28
|
-
NODE_ENV: oneOf(["development", "production", "test"]),
|
|
29
|
-
},
|
|
30
|
-
client: {
|
|
31
|
-
NEXT_PUBLIC_API_URL: url(),
|
|
32
|
-
},
|
|
33
|
-
clientPrefix: "NEXT_PUBLIC_",
|
|
34
|
-
runtimeEnv: process.env,
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
env.DATABASE_URL; // string, validated as a URL
|
|
38
|
-
env.PORT; // number
|
|
39
|
-
env.NODE_ENV; // "development" | "production" | "test"`}
|
|
40
|
-
/>
|
|
41
|
-
<p className="mt-4 text-muted-foreground">
|
|
42
|
-
If any variable is missing or fails validation,{" "}
|
|
43
|
-
<span className="text-foreground">createEnv</span> throws a single error listing every
|
|
44
|
-
failure:
|
|
45
|
-
</p>
|
|
46
|
-
<CodeBlock
|
|
47
|
-
label="validation error"
|
|
48
|
-
code={`Environment validation failed:
|
|
49
|
-
server.DATABASE_URL: Expected a valid URL, got "not-a-url"
|
|
50
|
-
server.PORT: Expected a number, got undefined`}
|
|
51
|
-
/>
|
|
52
|
-
|
|
53
|
-
<h2 className="mt-12 text-xl font-bold tracking-tight">Validators</h2>
|
|
54
|
-
<CodeBlock
|
|
55
|
-
label="built-in validators"
|
|
56
|
-
code={`Validator Accepts Notes
|
|
57
|
-
──────────────────────────────────────────────────────────────────────
|
|
58
|
-
str() any non-undefined string
|
|
59
|
-
num() numeric strings rejects NaN
|
|
60
|
-
bool() "true"/"1" → true, "false"/"0" → false
|
|
61
|
-
oneOf([...values]) one of the given string literals narrows return type
|
|
62
|
-
url() string parseable by new URL(...)`}
|
|
63
|
-
/>
|
|
64
|
-
|
|
65
|
-
<h2 className="mt-12 text-xl font-bold tracking-tight">Custom validators</h2>
|
|
66
|
-
<p className="mt-3 text-muted-foreground">
|
|
67
|
-
Each validator is{" "}
|
|
68
|
-
<span className="text-foreground">{"{ parse(input: string | undefined): T }"}</span> — write
|
|
69
|
-
your own for anything not covered:
|
|
70
|
-
</p>
|
|
71
|
-
<CodeBlock
|
|
72
|
-
label="custom validator"
|
|
73
|
-
code={`import type { EnvValidator } from "@thexjs/env";
|
|
74
|
-
|
|
75
|
-
function json<T>(): EnvValidator<T> {
|
|
76
|
-
return {
|
|
77
|
-
parse(input) {
|
|
78
|
-
if (input === undefined) throw new Error("Expected JSON, got undefined");
|
|
79
|
-
return JSON.parse(input) as T;
|
|
80
|
-
},
|
|
81
|
-
};
|
|
82
|
-
}`}
|
|
83
|
-
/>
|
|
84
|
-
|
|
85
|
-
<h2 className="mt-12 text-xl font-bold tracking-tight">client / clientPrefix</h2>
|
|
86
|
-
<p className="mt-3 text-muted-foreground">
|
|
87
|
-
The <span className="text-foreground">client</span> schema is for variables safe to expose
|
|
88
|
-
to the browser. <span className="text-foreground">clientPrefix</span> enforces that every
|
|
89
|
-
client key starts with that prefix (e.g.{" "}
|
|
90
|
-
<span className="text-foreground">NEXT_PUBLIC_</span>,{" "}
|
|
91
|
-
<span className="text-foreground">PUBLIC_</span>) — a key that does not match fails
|
|
92
|
-
validation, so you cannot accidentally leak a server-only variable through the client
|
|
93
|
-
schema.
|
|
94
|
-
</p>
|
|
95
|
-
|
|
96
|
-
<h2 className="mt-12 text-xl font-bold tracking-tight">Notes</h2>
|
|
97
|
-
<ul className="mt-3 list-inside list-disc space-y-2 text-muted-foreground">
|
|
98
|
-
<li>
|
|
99
|
-
Every field is currently required — no built-in{" "}
|
|
100
|
-
<span className="text-foreground">optional()</span> or{" "}
|
|
101
|
-
<span className="text-foreground">default()</span>. For optional vars, read from{" "}
|
|
102
|
-
<span className="text-foreground">process.env</span> directly or write a validator with a
|
|
103
|
-
fallback.
|
|
104
|
-
</li>
|
|
105
|
-
<li>
|
|
106
|
-
<span className="text-foreground">runtimeEnv</span> is passed explicitly so this works on
|
|
107
|
-
Bun, in bundlers that inline <span className="text-foreground">process.env.*</span> at
|
|
108
|
-
build time, or in tests with a mocked env object.
|
|
109
|
-
</li>
|
|
110
|
-
</ul>
|
|
111
|
-
|
|
112
|
-
<div className="mt-16 flex flex-wrap gap-6 border-t border-border pt-8">
|
|
113
|
-
<a
|
|
114
|
-
href="/docs/packages/core"
|
|
115
|
-
className="inline-flex items-center gap-1 text-sm font-medium text-primary transition-colors hover:text-primary/80"
|
|
116
|
-
>
|
|
117
|
-
@thexjs/core <ArrowRight className="h-3.5 w-3.5" />
|
|
118
|
-
</a>
|
|
119
|
-
<a
|
|
120
|
-
href="/docs"
|
|
121
|
-
className="inline-flex items-center gap-1 text-sm text-muted-foreground transition-colors hover:text-foreground"
|
|
122
|
-
>
|
|
123
|
-
<ArrowRight className="h-3.5 w-3.5 rotate-180" /> Back to docs
|
|
124
|
-
</a>
|
|
125
|
-
</div>
|
|
126
|
-
</div>
|
|
127
|
-
);
|
|
128
|
-
}
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import type { RouteProps } from "@thexjs/core";
|
|
2
|
-
import { ArrowRight } from "lucide-react";
|
|
3
|
-
import { CodeBlock } from "../../components/code-block";
|
|
4
|
-
|
|
5
|
-
export default function DocPage(_props: RouteProps) {
|
|
6
|
-
return (
|
|
7
|
-
<div>
|
|
8
|
-
<p className="text-xs font-semibold uppercase tracking-[0.2em] text-primary">Pages</p>
|
|
9
|
-
<h1 className="mt-4 text-3xl font-bold tracking-tight sm:text-4xl">Pages & loaders</h1>
|
|
10
|
-
<p className="mt-4 text-lg text-muted-foreground">
|
|
11
|
-
x supports two page modes — static prerendering and server-side rendering — both powered by
|
|
12
|
-
loaders.
|
|
13
|
-
</p>
|
|
14
|
-
|
|
15
|
-
<h2 className="mt-12 text-xl font-bold tracking-tight">Page modes</h2>
|
|
16
|
-
<p className="mt-3 text-muted-foreground">
|
|
17
|
-
By default, pages are server-rendered (SSR). Export{" "}
|
|
18
|
-
<span className="text-foreground">mode = "static"</span> to prerender at build time.
|
|
19
|
-
</p>
|
|
20
|
-
|
|
21
|
-
<h2 className="mt-12 text-xl font-bold tracking-tight">Static pages</h2>
|
|
22
|
-
<p className="mt-3 text-muted-foreground">
|
|
23
|
-
Static pages are rendered at build time and exported as HTML. Use this for marketing pages,
|
|
24
|
-
blog posts, or any content that doesn't need per-request rendering.
|
|
25
|
-
</p>
|
|
26
|
-
<CodeBlock
|
|
27
|
-
label="src/pages/about.tsx"
|
|
28
|
-
code={`import type { RouteProps } from "@thexjs/core";
|
|
29
|
-
|
|
30
|
-
export const mode = "static";
|
|
31
|
-
|
|
32
|
-
export default function About({}: RouteProps) {
|
|
33
|
-
return (
|
|
34
|
-
<div className="max-w-2xl mx-auto py-12">
|
|
35
|
-
<h1 className="text-4xl font-bold">About</h1>
|
|
36
|
-
<p className="mt-4 text-muted-foreground">
|
|
37
|
-
This page is prerendered at build time.
|
|
38
|
-
</p>
|
|
39
|
-
</div>
|
|
40
|
-
);
|
|
41
|
-
}`}
|
|
42
|
-
/>
|
|
43
|
-
|
|
44
|
-
<h2 className="mt-12 text-xl font-bold tracking-tight">Server pages with loaders</h2>
|
|
45
|
-
<p className="mt-3 text-muted-foreground">
|
|
46
|
-
Server pages (the default) run a <span className="text-foreground">loader</span> function on
|
|
47
|
-
every request. The loader can fetch data, query a database, or call an external API.
|
|
48
|
-
</p>
|
|
49
|
-
<CodeBlock
|
|
50
|
-
label="src/pages/products.tsx"
|
|
51
|
-
code={`import type { RouteProps, LoaderArgs } from "@thexjs/core";
|
|
52
|
-
|
|
53
|
-
export async function loader({ request }: LoaderArgs) {
|
|
54
|
-
const res = await fetch("https://api.example.com/products");
|
|
55
|
-
const products = await res.json();
|
|
56
|
-
return { products };
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export default function Products({ loaderData }: RouteProps<typeof loader>) {
|
|
60
|
-
return (
|
|
61
|
-
<div>
|
|
62
|
-
<h1 className="text-3xl font-bold">Products</h1>
|
|
63
|
-
<ul className="mt-6 space-y-4">
|
|
64
|
-
{loaderData.products.map((p: any) => (
|
|
65
|
-
<li key={p.id} className="rounded-xl border border-border bg-card p-4">
|
|
66
|
-
<h2 className="font-semibold">{p.name}</h2>
|
|
67
|
-
<p className="text-sm text-muted-foreground">{p.price}</p>
|
|
68
|
-
</li>
|
|
69
|
-
))}
|
|
70
|
-
</ul>
|
|
71
|
-
</div>
|
|
72
|
-
);
|
|
73
|
-
}`}
|
|
74
|
-
/>
|
|
75
|
-
|
|
76
|
-
<h2 className="mt-12 text-xl font-bold tracking-tight">Loader with dynamic params</h2>
|
|
77
|
-
<p className="mt-3 text-muted-foreground">
|
|
78
|
-
Combined with dynamic routing, loaders receive{" "}
|
|
79
|
-
<span className="text-foreground">params</span> parsed from the URL path.
|
|
80
|
-
</p>
|
|
81
|
-
<CodeBlock
|
|
82
|
-
label="src/pages/products/[id].tsx"
|
|
83
|
-
code={`import type { RouteProps, LoaderArgs } from "@thexjs/core";
|
|
84
|
-
|
|
85
|
-
export async function loader({ params }: LoaderArgs) {
|
|
86
|
-
const product = await db.query(
|
|
87
|
-
"SELECT * FROM products WHERE id = ?", [params.id]
|
|
88
|
-
);
|
|
89
|
-
if (!product) throw new Response(null, { status: 404 });
|
|
90
|
-
return { product };
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export default function ProductDetail({ loaderData }: RouteProps<typeof loader>) {
|
|
94
|
-
const { product } = loaderData;
|
|
95
|
-
return (
|
|
96
|
-
<div>
|
|
97
|
-
<h1 className="text-3xl font-bold">{product.name}</h1>
|
|
98
|
-
<p className="mt-2 text-muted-foreground">{product.description}</p>
|
|
99
|
-
<p className="mt-4 text-2xl font-bold text-primary">${"$"}{product.price}</p>
|
|
100
|
-
</div>
|
|
101
|
-
);
|
|
102
|
-
}`}
|
|
103
|
-
/>
|
|
104
|
-
|
|
105
|
-
<h2 className="mt-12 text-xl font-bold tracking-tight">RouteProps type</h2>
|
|
106
|
-
<p className="mt-3 text-muted-foreground">
|
|
107
|
-
The <span className="text-foreground">RouteProps</span> type provides typed access to{" "}
|
|
108
|
-
<span className="text-foreground">loaderData</span>,{" "}
|
|
109
|
-
<span className="text-foreground">params</span>, and{" "}
|
|
110
|
-
<span className="text-foreground">request</span>. Pass your loader function as the type
|
|
111
|
-
parameter for full type safety.
|
|
112
|
-
</p>
|
|
113
|
-
<CodeBlock
|
|
114
|
-
label="type usage"
|
|
115
|
-
code={`import type { RouteProps } from "@thexjs/core";
|
|
116
|
-
|
|
117
|
-
// loaderData is automatically typed via the generic
|
|
118
|
-
export default function Page({ loaderData, params, request }: RouteProps<typeof loader>) {
|
|
119
|
-
// loaderData has the return type of loader()
|
|
120
|
-
// params has the dynamic segment types
|
|
121
|
-
// request is the standard Request object
|
|
122
|
-
}`}
|
|
123
|
-
/>
|
|
124
|
-
|
|
125
|
-
<div className="mt-16 border-t border-border pt-8">
|
|
126
|
-
<a
|
|
127
|
-
href="/docs"
|
|
128
|
-
className="inline-flex items-center gap-1 text-sm text-muted-foreground transition-colors hover:text-foreground"
|
|
129
|
-
>
|
|
130
|
-
<ArrowRight className="h-3.5 w-3.5 rotate-180" /> Back to docs
|
|
131
|
-
</a>
|
|
132
|
-
</div>
|
|
133
|
-
</div>
|
|
134
|
-
);
|
|
135
|
-
}
|