create-thexjs-app 0.1.0 → 0.1.2
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 +6 -4
- package/dist/index.js +23 -2
- package/package.json +36 -1
- package/templates/default/components.json +19 -0
- package/templates/default/src/layouts/main.tsx +28 -0
- package/templates/default/src/pages/index.tsx +66 -0
- package/templates/default/src/styles/globals.css +55 -0
- package/templates/default/src/x-routes.ts +17 -0
- package/templates/default/tsconfig.json +5 -0
- package/templates/default/x.config.ts +6 -0
- package/templates/landing/src/pages/docs/_layout.tsx +62 -44
- package/templates/landing/src/pages/docs/getting-started.tsx +19 -9
- package/templates/landing/src/pages/docs/index.tsx +86 -22
- package/templates/landing/src/pages/docs/installation.tsx +147 -0
- package/templates/landing/src/pages/docs/introduction.tsx +117 -0
- package/templates/landing/src/pages/docs/packages/cli.tsx +130 -0
- package/templates/landing/src/pages/docs/packages/core.tsx +172 -0
- package/templates/landing/src/pages/docs/packages/env.tsx +128 -0
- package/templates/landing/src/pages/index.tsx +51 -32
|
@@ -0,0 +1,147 @@
|
|
|
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({}: RouteProps) {
|
|
8
|
+
return (
|
|
9
|
+
<div>
|
|
10
|
+
<p className="text-xs font-semibold uppercase tracking-[0.2em] text-primary">Installation</p>
|
|
11
|
+
<h1 className="mt-4 text-3xl font-bold tracking-tight sm:text-4xl">Install x</h1>
|
|
12
|
+
<p className="mt-4 text-lg text-muted-foreground">
|
|
13
|
+
x requires the Bun runtime. Scaffold a new project with the create command, or add the
|
|
14
|
+
packages manually to an existing app.
|
|
15
|
+
</p>
|
|
16
|
+
|
|
17
|
+
<h2 className="mt-12 text-xl font-bold tracking-tight">Prerequisites</h2>
|
|
18
|
+
<p className="mt-3 text-muted-foreground">
|
|
19
|
+
Install{" "}
|
|
20
|
+
<a href="https://bun.sh" className="text-primary underline underline-offset-2">
|
|
21
|
+
Bun
|
|
22
|
+
</a>{" "}
|
|
23
|
+
— x uses <span className="text-foreground">Bun.serve</span>,{" "}
|
|
24
|
+
<span className="text-foreground">Bun.file</span>, and other Bun-only APIs. Verify with:
|
|
25
|
+
</p>
|
|
26
|
+
<CodeBlock label="terminal" lang="bash" code="bun --version" />
|
|
27
|
+
|
|
28
|
+
<h2 className="mt-12 text-xl font-bold tracking-tight">Create a new project</h2>
|
|
29
|
+
<p className="mt-3 text-muted-foreground">
|
|
30
|
+
The fastest path is the project scaffolder. It copies a template, generates{" "}
|
|
31
|
+
<span className="text-foreground">package.json</span>, resolves the latest{" "}
|
|
32
|
+
<span className="text-foreground">@thexjs/core</span> and{" "}
|
|
33
|
+
<span className="text-foreground">@thexjs/cli</span> versions, and runs{" "}
|
|
34
|
+
<span className="text-foreground">bun install</span>.
|
|
35
|
+
</p>
|
|
36
|
+
<CodeBlock
|
|
37
|
+
label="terminal"
|
|
38
|
+
lang="bash"
|
|
39
|
+
code={`bun create thexjs-app@latest my-app
|
|
40
|
+
cd my-app
|
|
41
|
+
bun run dev`}
|
|
42
|
+
/>
|
|
43
|
+
<p className="mt-4 text-muted-foreground">
|
|
44
|
+
When prompted for a template, press Enter to accept{" "}
|
|
45
|
+
<span className="text-foreground">default</span> (recommended) — a single home page to
|
|
46
|
+
start from. Other templates include <span className="text-foreground">basic</span>,{" "}
|
|
47
|
+
<span className="text-foreground">blog</span>, <span className="text-foreground">saas</span>
|
|
48
|
+
, and <span className="text-foreground">landing</span>.
|
|
49
|
+
</p>
|
|
50
|
+
<CodeBlock
|
|
51
|
+
label="template selection"
|
|
52
|
+
lang="bash"
|
|
53
|
+
code={`Available templates:
|
|
54
|
+
|
|
55
|
+
default Blank slate with a single home page — the fastest way to start. (recommended)
|
|
56
|
+
basic Minimal starter: pages, an API route, auth, and a dashboard.
|
|
57
|
+
blog Markdown content collections, post listing, and post pages.
|
|
58
|
+
saas Dashboard, settings, pricing, auth, and a data layer example.
|
|
59
|
+
landing Marketing site with docs pages, styled with shadcn/Tailwind.
|
|
60
|
+
|
|
61
|
+
Choose a template (default/basic/blog/saas/landing) (default):`}
|
|
62
|
+
/>
|
|
63
|
+
<p className="mt-4 text-muted-foreground">
|
|
64
|
+
Pass a template explicitly with{" "}
|
|
65
|
+
<span className="text-foreground">--template</span> or{" "}
|
|
66
|
+
<span className="text-foreground">-t</span>:
|
|
67
|
+
</p>
|
|
68
|
+
<CodeBlock
|
|
69
|
+
label="terminal"
|
|
70
|
+
lang="bash"
|
|
71
|
+
code="bun create thexjs-app@latest my-app --template default"
|
|
72
|
+
/>
|
|
73
|
+
|
|
74
|
+
<h2 className="mt-12 text-xl font-bold tracking-tight">Add to an existing project</h2>
|
|
75
|
+
<p className="mt-3 text-muted-foreground">
|
|
76
|
+
Install the core packages and wire up scripts in{" "}
|
|
77
|
+
<span className="text-foreground">package.json</span>:
|
|
78
|
+
</p>
|
|
79
|
+
<CodeBlock
|
|
80
|
+
label="terminal"
|
|
81
|
+
lang="bash"
|
|
82
|
+
code={`bun add @thexjs/core
|
|
83
|
+
bun add -d @thexjs/cli`}
|
|
84
|
+
/>
|
|
85
|
+
<CodeBlock
|
|
86
|
+
label="package.json"
|
|
87
|
+
code={`{
|
|
88
|
+
"scripts": {
|
|
89
|
+
"dev": "x dev",
|
|
90
|
+
"build": "x build",
|
|
91
|
+
"start": "x start"
|
|
92
|
+
}
|
|
93
|
+
}`}
|
|
94
|
+
/>
|
|
95
|
+
<p className="mt-4 text-muted-foreground">
|
|
96
|
+
Create <span className="text-foreground">x.config.ts</span> at the project root:
|
|
97
|
+
</p>
|
|
98
|
+
<CodeBlock
|
|
99
|
+
label="x.config.ts"
|
|
100
|
+
code={`import { defineConfig } from "@thexjs/core";
|
|
101
|
+
|
|
102
|
+
export default defineConfig({
|
|
103
|
+
pagesDir: "./src/pages",
|
|
104
|
+
port: 3000,
|
|
105
|
+
});`}
|
|
106
|
+
/>
|
|
107
|
+
|
|
108
|
+
<h2 className="mt-12 text-xl font-bold tracking-tight">Optional: environment validation</h2>
|
|
109
|
+
<p className="mt-3 text-muted-foreground">
|
|
110
|
+
Add <span className="text-foreground">@thexjs/env</span> when you want typed, validated
|
|
111
|
+
environment variables:
|
|
112
|
+
</p>
|
|
113
|
+
<CodeBlock label="terminal" lang="bash" code="bun add @thexjs/env" />
|
|
114
|
+
<p className="mt-4 text-muted-foreground">
|
|
115
|
+
See the{" "}
|
|
116
|
+
<a href="/docs/packages/env" className="text-primary underline underline-offset-2">
|
|
117
|
+
@thexjs/env docs
|
|
118
|
+
</a>{" "}
|
|
119
|
+
for the full API.
|
|
120
|
+
</p>
|
|
121
|
+
|
|
122
|
+
<h2 className="mt-12 text-xl font-bold tracking-tight">Verify the install</h2>
|
|
123
|
+
<CodeBlock
|
|
124
|
+
label="terminal"
|
|
125
|
+
lang="bash"
|
|
126
|
+
code={`x dev
|
|
127
|
+
compiling Tailwind CSS...
|
|
128
|
+
dev server running at http://localhost:3000`}
|
|
129
|
+
/>
|
|
130
|
+
|
|
131
|
+
<div className="mt-16 flex flex-wrap gap-6 border-t border-border pt-8">
|
|
132
|
+
<a
|
|
133
|
+
href="/docs/getting-started"
|
|
134
|
+
className="inline-flex items-center gap-1 text-sm font-medium text-primary transition-colors hover:text-primary/80"
|
|
135
|
+
>
|
|
136
|
+
Getting started <ArrowRight className="h-3.5 w-3.5" />
|
|
137
|
+
</a>
|
|
138
|
+
<a
|
|
139
|
+
href="/docs"
|
|
140
|
+
className="inline-flex items-center gap-1 text-sm text-muted-foreground transition-colors hover:text-foreground"
|
|
141
|
+
>
|
|
142
|
+
<ArrowRight className="h-3.5 w-3.5 rotate-180" /> Back to docs
|
|
143
|
+
</a>
|
|
144
|
+
</div>
|
|
145
|
+
</div>
|
|
146
|
+
);
|
|
147
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
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({}: RouteProps) {
|
|
8
|
+
return (
|
|
9
|
+
<div>
|
|
10
|
+
<p className="text-xs font-semibold uppercase tracking-[0.2em] text-primary">Introduction</p>
|
|
11
|
+
<h1 className="mt-4 text-3xl font-bold tracking-tight sm:text-4xl">What is x?</h1>
|
|
12
|
+
<p className="mt-4 text-lg text-muted-foreground">
|
|
13
|
+
x is a full-stack React framework built on{" "}
|
|
14
|
+
<a href="https://bun.sh" className="text-primary underline underline-offset-2">
|
|
15
|
+
Bun
|
|
16
|
+
</a>
|
|
17
|
+
. File-based routing, SSR, static generation, API routes, server functions, islands, and a
|
|
18
|
+
content layer — all in one process, zero orchestration.
|
|
19
|
+
</p>
|
|
20
|
+
|
|
21
|
+
<h2 className="mt-12 text-xl font-bold tracking-tight">Why x exists</h2>
|
|
22
|
+
<p className="mt-3 text-muted-foreground">
|
|
23
|
+
Most stacks split concerns across multiple tools: a bundler, a server, a static host, a
|
|
24
|
+
separate API layer. x keeps everything in one Bun process. Drop a file in{" "}
|
|
25
|
+
<span className="text-foreground">src/pages</span>, get a route. Mark a page{" "}
|
|
26
|
+
<span className="text-foreground">static</span> and it prerenders at build time. Leave it
|
|
27
|
+
as server mode and it renders per request. API routes and server functions live alongside
|
|
28
|
+
your pages — same types, same runtime.
|
|
29
|
+
</p>
|
|
30
|
+
|
|
31
|
+
<h2 className="mt-12 text-xl font-bold tracking-tight">The package ecosystem</h2>
|
|
32
|
+
<p className="mt-3 text-muted-foreground">
|
|
33
|
+
x ships as three focused npm packages. You typically install{" "}
|
|
34
|
+
<span className="text-foreground">@thexjs/cli</span> and{" "}
|
|
35
|
+
<span className="text-foreground">@thexjs/core</span> through the project scaffolder; add{" "}
|
|
36
|
+
<span className="text-foreground">@thexjs/env</span> when you need validated environment
|
|
37
|
+
variables.
|
|
38
|
+
</p>
|
|
39
|
+
<div className="mt-6 space-y-3">
|
|
40
|
+
{[
|
|
41
|
+
{
|
|
42
|
+
name: "@thexjs/core",
|
|
43
|
+
href: "/docs/packages/core",
|
|
44
|
+
desc: "Rendering engine — routing, SSR/SSG, islands, server functions, content, data layer.",
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: "@thexjs/cli",
|
|
48
|
+
href: "/docs/packages/cli",
|
|
49
|
+
desc: "The x command — dev server, production build, and start.",
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
name: "@thexjs/env",
|
|
53
|
+
href: "/docs/packages/env",
|
|
54
|
+
desc: "Type-safe environment variable validation with fail-fast errors.",
|
|
55
|
+
},
|
|
56
|
+
].map((pkg) => (
|
|
57
|
+
<a
|
|
58
|
+
key={pkg.name}
|
|
59
|
+
href={pkg.href}
|
|
60
|
+
className="block rounded-xl border border-border bg-card p-5 transition-colors hover:border-primary/30 hover:bg-card/80"
|
|
61
|
+
>
|
|
62
|
+
<p className="font-mono text-sm font-semibold text-primary">{pkg.name}</p>
|
|
63
|
+
<p className="mt-1 text-sm text-muted-foreground">{pkg.desc}</p>
|
|
64
|
+
</a>
|
|
65
|
+
))}
|
|
66
|
+
</div>
|
|
67
|
+
|
|
68
|
+
<h2 className="mt-12 text-xl font-bold tracking-tight">A minimal page</h2>
|
|
69
|
+
<p className="mt-3 text-muted-foreground">
|
|
70
|
+
Every x app starts with file-based routes. Here is the simplest possible page:
|
|
71
|
+
</p>
|
|
72
|
+
<CodeBlock
|
|
73
|
+
label="src/pages/index.tsx"
|
|
74
|
+
code={`import type { RouteProps } from "@thexjs/core";
|
|
75
|
+
|
|
76
|
+
export const mode = "static";
|
|
77
|
+
|
|
78
|
+
export default function HomePage({}: RouteProps) {
|
|
79
|
+
return <h1>Hello from x</h1>;
|
|
80
|
+
}`}
|
|
81
|
+
/>
|
|
82
|
+
<p className="mt-4 text-muted-foreground">
|
|
83
|
+
Run <span className="text-foreground">x dev</span> and visit{" "}
|
|
84
|
+
<span className="text-foreground">http://localhost:3000</span>. That is the entire loop.
|
|
85
|
+
</p>
|
|
86
|
+
|
|
87
|
+
<h2 className="mt-12 text-xl font-bold tracking-tight">Static vs server</h2>
|
|
88
|
+
<p className="mt-3 text-muted-foreground">
|
|
89
|
+
Pages default to server-rendered (SSR). Opt into build-time prerendering per page:
|
|
90
|
+
</p>
|
|
91
|
+
<CodeBlock
|
|
92
|
+
label="route mode"
|
|
93
|
+
code={`export const mode: "static" | "server" = "static";`}
|
|
94
|
+
/>
|
|
95
|
+
<p className="mt-4 text-muted-foreground">
|
|
96
|
+
Static pages ship as plain HTML in{" "}
|
|
97
|
+
<span className="text-foreground">.x/client/</span> — deployable to any static host.
|
|
98
|
+
Server pages need a running Bun process via <span className="text-foreground">x start</span>.
|
|
99
|
+
</p>
|
|
100
|
+
|
|
101
|
+
<div className="mt-16 flex flex-wrap gap-6 border-t border-border pt-8">
|
|
102
|
+
<a
|
|
103
|
+
href="/docs/installation"
|
|
104
|
+
className="inline-flex items-center gap-1 text-sm font-medium text-primary transition-colors hover:text-primary/80"
|
|
105
|
+
>
|
|
106
|
+
Install x <ArrowRight className="h-3.5 w-3.5" />
|
|
107
|
+
</a>
|
|
108
|
+
<a
|
|
109
|
+
href="/docs"
|
|
110
|
+
className="inline-flex items-center gap-1 text-sm text-muted-foreground transition-colors hover:text-foreground"
|
|
111
|
+
>
|
|
112
|
+
<ArrowRight className="h-3.5 w-3.5 rotate-180" /> Back to docs
|
|
113
|
+
</a>
|
|
114
|
+
</div>
|
|
115
|
+
</div>
|
|
116
|
+
);
|
|
117
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
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({}: 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 <span className="text-foreground">bun</span>{" "}
|
|
20
|
+
and uses Bun-only APIs (<span className="text-foreground">Bun.serve</span>,{" "}
|
|
21
|
+
<span className="text-foreground">Bun.argv</span>).
|
|
22
|
+
</p>
|
|
23
|
+
|
|
24
|
+
<h2 className="mt-12 text-xl font-bold tracking-tight">Commands</h2>
|
|
25
|
+
<CodeBlock
|
|
26
|
+
label="commands"
|
|
27
|
+
code={`x dev # start the dev server with hot reload
|
|
28
|
+
x build # build for production -> .x/
|
|
29
|
+
x start # run the production server (run x build first)
|
|
30
|
+
|
|
31
|
+
x run dev # "run" is optional — alias for npm/bun muscle memory
|
|
32
|
+
|
|
33
|
+
-h, --help # show help
|
|
34
|
+
-v, --version # print installed @thexjs/cli version
|
|
35
|
+
--cwd <dir> # run as if started inside <dir>`}
|
|
36
|
+
/>
|
|
37
|
+
|
|
38
|
+
<h2 className="mt-12 text-xl font-bold tracking-tight">package.json scripts</h2>
|
|
39
|
+
<CodeBlock
|
|
40
|
+
label="package.json"
|
|
41
|
+
code={`{
|
|
42
|
+
"scripts": {
|
|
43
|
+
"dev": "x dev",
|
|
44
|
+
"build": "x build",
|
|
45
|
+
"start": "x start"
|
|
46
|
+
}
|
|
47
|
+
}`}
|
|
48
|
+
/>
|
|
49
|
+
|
|
50
|
+
<h2 className="mt-12 text-xl font-bold tracking-tight">Configuration</h2>
|
|
51
|
+
<p className="mt-3 text-muted-foreground">
|
|
52
|
+
The CLI reads <span className="text-foreground">x.config.ts</span> (or{" "}
|
|
53
|
+
<span className="text-foreground">.js</span> / <span className="text-foreground">.mjs</span>
|
|
54
|
+
) and passes its <span className="text-foreground">defineConfig(...)</span> export to{" "}
|
|
55
|
+
<span className="text-foreground">@thexjs/core</span>:
|
|
56
|
+
</p>
|
|
57
|
+
<CodeBlock
|
|
58
|
+
label="x.config.ts"
|
|
59
|
+
code={`import { defineConfig } from "@thexjs/core";
|
|
60
|
+
|
|
61
|
+
export default defineConfig({
|
|
62
|
+
pagesDir: "./src/pages",
|
|
63
|
+
contentDir: "./src/content",
|
|
64
|
+
port: 3000,
|
|
65
|
+
});`}
|
|
66
|
+
/>
|
|
67
|
+
<p className="mt-4 text-muted-foreground">
|
|
68
|
+
Without a config file, defaults apply: <span className="text-foreground">src/pages</span> for
|
|
69
|
+
pages, <span className="text-foreground">content</span> for content collections if present,
|
|
70
|
+
port <span className="text-foreground">3000</span>.
|
|
71
|
+
</p>
|
|
72
|
+
|
|
73
|
+
<h2 className="mt-12 text-xl font-bold tracking-tight">What each command does</h2>
|
|
74
|
+
|
|
75
|
+
<h3 className="mt-8 text-lg font-semibold">x dev</h3>
|
|
76
|
+
<p className="mt-2 text-muted-foreground">
|
|
77
|
+
Auto-compiles <span className="text-foreground">src/styles/globals.css</span> via{" "}
|
|
78
|
+
<span className="text-foreground">bunx tailwindcss</span> when that file exists, watches{" "}
|
|
79
|
+
<span className="text-foreground">src/styles</span>, then starts{" "}
|
|
80
|
+
<span className="text-foreground">createApp()</span> under{" "}
|
|
81
|
+
<span className="text-foreground">Bun.serve</span>. If the port is taken, tries up to 20
|
|
82
|
+
ports upward.
|
|
83
|
+
</p>
|
|
84
|
+
|
|
85
|
+
<h3 className="mt-8 text-lg font-semibold">x build</h3>
|
|
86
|
+
<p className="mt-2 text-muted-foreground">Compiles Tailwind in production mode, then writes:</p>
|
|
87
|
+
<ul className="mt-3 list-inside list-disc space-y-2 text-muted-foreground">
|
|
88
|
+
<li>
|
|
89
|
+
<span className="text-foreground">.x/client/</span> — prerendered HTML for static pages,
|
|
90
|
+
plus <span className="text-foreground">public/</span> assets. Deployable to any static
|
|
91
|
+
host.
|
|
92
|
+
</li>
|
|
93
|
+
<li>
|
|
94
|
+
<span className="text-foreground">.x/server/index.ts</span> — server entry for SSR pages
|
|
95
|
+
and API routes. Requires a Bun-capable host.
|
|
96
|
+
</li>
|
|
97
|
+
</ul>
|
|
98
|
+
|
|
99
|
+
<h3 className="mt-8 text-lg font-semibold">x start</h3>
|
|
100
|
+
<p className="mt-2 text-muted-foreground">
|
|
101
|
+
Runs <span className="text-foreground">.x/server/index.ts</span> with{" "}
|
|
102
|
+
<span className="text-foreground">NODE_ENV=production</span>. Exits with an error if the
|
|
103
|
+
build output is missing.
|
|
104
|
+
</p>
|
|
105
|
+
|
|
106
|
+
<h2 className="mt-12 text-xl font-bold tracking-tight">Deployment</h2>
|
|
107
|
+
<p className="mt-3 text-muted-foreground">
|
|
108
|
+
If every page uses <span className="text-foreground">mode = "static"</span> and you have no
|
|
109
|
+
API routes, deploy <span className="text-foreground">.x/client/</span> to any static host.
|
|
110
|
+
Server-mode pages need a host that keeps a Bun process running (Fly.io, Railway, Docker,
|
|
111
|
+
VPS) and runs <span className="text-foreground">x start</span>.
|
|
112
|
+
</p>
|
|
113
|
+
|
|
114
|
+
<div className="mt-16 flex flex-wrap gap-6 border-t border-border pt-8">
|
|
115
|
+
<a
|
|
116
|
+
href="/docs/packages/env"
|
|
117
|
+
className="inline-flex items-center gap-1 text-sm font-medium text-primary transition-colors hover:text-primary/80"
|
|
118
|
+
>
|
|
119
|
+
@thexjs/env <ArrowRight className="h-3.5 w-3.5" />
|
|
120
|
+
</a>
|
|
121
|
+
<a
|
|
122
|
+
href="/docs"
|
|
123
|
+
className="inline-flex items-center gap-1 text-sm text-muted-foreground transition-colors hover:text-foreground"
|
|
124
|
+
>
|
|
125
|
+
<ArrowRight className="h-3.5 w-3.5 rotate-180" /> Back to docs
|
|
126
|
+
</a>
|
|
127
|
+
</div>
|
|
128
|
+
</div>
|
|
129
|
+
);
|
|
130
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
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({}: 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 label="src/pages/index.tsx" code={`export const mode: "static" | "server" = "static";`} />
|
|
73
|
+
<ul className="mt-4 list-inside list-disc space-y-2 text-muted-foreground">
|
|
74
|
+
<li>
|
|
75
|
+
<span className="text-foreground">static</span> — rendered once at build time to HTML in{" "}
|
|
76
|
+
<span className="text-foreground">.x/client/</span>
|
|
77
|
+
</li>
|
|
78
|
+
<li>
|
|
79
|
+
<span className="text-foreground">server</span> — rendered per request via{" "}
|
|
80
|
+
<span className="text-foreground">x start</span> or <span className="text-foreground">x dev</span>
|
|
81
|
+
</li>
|
|
82
|
+
</ul>
|
|
83
|
+
|
|
84
|
+
<h2 className="mt-12 text-xl font-bold tracking-tight">Loaders</h2>
|
|
85
|
+
<CodeBlock
|
|
86
|
+
label="loader example"
|
|
87
|
+
code={`import type { RouteProps } from "@thexjs/core";
|
|
88
|
+
|
|
89
|
+
export async function loader({ params }: { params: Record<string, string> }) {
|
|
90
|
+
return { user: await getUser(params.id) };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export default function UserPage({ loaderData }: RouteProps<typeof loader>) {
|
|
94
|
+
return <p>{loaderData.user.name}</p>;
|
|
95
|
+
}`}
|
|
96
|
+
/>
|
|
97
|
+
|
|
98
|
+
<h2 className="mt-12 text-xl font-bold tracking-tight">Islands</h2>
|
|
99
|
+
<p className="mt-3 text-muted-foreground">
|
|
100
|
+
Wrap interactive pieces in <span className="text-foreground"><Island></span> for
|
|
101
|
+
selective hydration:
|
|
102
|
+
</p>
|
|
103
|
+
<CodeBlock
|
|
104
|
+
label="island"
|
|
105
|
+
code={`import { Island } from "@thexjs/core";
|
|
106
|
+
|
|
107
|
+
<Island name="like-button" client="visible">
|
|
108
|
+
<LikeButton />
|
|
109
|
+
</Island>`}
|
|
110
|
+
/>
|
|
111
|
+
<p className="mt-4 text-muted-foreground">
|
|
112
|
+
<span className="text-foreground">client</span> accepts{" "}
|
|
113
|
+
<span className="text-foreground">"idle"</span>,{" "}
|
|
114
|
+
<span className="text-foreground">"visible"</span>, or{" "}
|
|
115
|
+
<span className="text-foreground">"load"</span>.
|
|
116
|
+
</p>
|
|
117
|
+
|
|
118
|
+
<h2 className="mt-12 text-xl font-bold tracking-tight">Content collections</h2>
|
|
119
|
+
<CodeBlock
|
|
120
|
+
label="markdown"
|
|
121
|
+
code={`import { scanContent, renderMarkdown } from "@thexjs/core";
|
|
122
|
+
|
|
123
|
+
const posts = scanContent("./src/content/blog");
|
|
124
|
+
const html = renderMarkdown(posts[0].body);`}
|
|
125
|
+
/>
|
|
126
|
+
|
|
127
|
+
<h2 className="mt-12 text-xl font-bold tracking-tight">Data layer</h2>
|
|
128
|
+
<CodeBlock
|
|
129
|
+
label="sqlite"
|
|
130
|
+
code={`import { connectSQLite, runSQLiteMigrations } from "@thexjs/core";
|
|
131
|
+
|
|
132
|
+
const db = connectSQLite({ filename: "./data/dev.db" });
|
|
133
|
+
await runSQLiteMigrations(db, "./data/migrations");`}
|
|
134
|
+
/>
|
|
135
|
+
<CodeBlock
|
|
136
|
+
label="postgres"
|
|
137
|
+
code={`import { connectPostgres, runPostgresMigrations } from "@thexjs/core";
|
|
138
|
+
|
|
139
|
+
const sql = connectPostgres({ url: process.env.DATABASE_URL! });
|
|
140
|
+
await runPostgresMigrations(sql, "./data/migrations");`}
|
|
141
|
+
/>
|
|
142
|
+
|
|
143
|
+
<h2 className="mt-12 text-xl font-bold tracking-tight">Key exports</h2>
|
|
144
|
+
<CodeBlock
|
|
145
|
+
label="exports"
|
|
146
|
+
code={`defineConfig, createApp, build App setup & build
|
|
147
|
+
renderPage, renderStaticPage Lower-level rendering
|
|
148
|
+
scanRoutes, scanPages, scanApiDir Routing internals
|
|
149
|
+
Island, IslandProvider Selective hydration
|
|
150
|
+
scanContent, renderMarkdown Markdown content
|
|
151
|
+
composeMiddleware, MiddlewareFn Route middleware
|
|
152
|
+
registerServerFunctions Server function internals
|
|
153
|
+
connectSQLite, connectPostgres Data layer`}
|
|
154
|
+
/>
|
|
155
|
+
|
|
156
|
+
<div className="mt-16 flex flex-wrap gap-6 border-t border-border pt-8">
|
|
157
|
+
<a
|
|
158
|
+
href="/docs/packages/cli"
|
|
159
|
+
className="inline-flex items-center gap-1 text-sm font-medium text-primary transition-colors hover:text-primary/80"
|
|
160
|
+
>
|
|
161
|
+
@thexjs/cli <ArrowRight className="h-3.5 w-3.5" />
|
|
162
|
+
</a>
|
|
163
|
+
<a
|
|
164
|
+
href="/docs"
|
|
165
|
+
className="inline-flex items-center gap-1 text-sm text-muted-foreground transition-colors hover:text-foreground"
|
|
166
|
+
>
|
|
167
|
+
<ArrowRight className="h-3.5 w-3.5 rotate-180" /> Back to docs
|
|
168
|
+
</a>
|
|
169
|
+
</div>
|
|
170
|
+
</div>
|
|
171
|
+
);
|
|
172
|
+
}
|