create-thexjs-app 0.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/LICENSE +21 -0
- package/README.md +1026 -0
- package/dist/index.js +224 -0
- package/package.json +30 -0
- package/templates/basic/components.json +21 -0
- package/templates/basic/content/blog/hello.md +8 -0
- package/templates/basic/public/favicon.ico +0 -0
- package/templates/basic/src/actions/dashboard/greet.ts +3 -0
- package/templates/basic/src/api/auth/login.ts +30 -0
- package/templates/basic/src/api/auth/logout.ts +12 -0
- package/templates/basic/src/api/placeholder/comments.ts +17 -0
- package/templates/basic/src/api/placeholder/posts.ts +20 -0
- package/templates/basic/src/api/placeholder/todos.ts +21 -0
- package/templates/basic/src/api/placeholder/users.ts +12 -0
- package/templates/basic/src/components/Head.tsx +21 -0
- package/templates/basic/src/components/Image.tsx +27 -0
- package/templates/basic/src/components/Link.tsx +16 -0
- package/templates/basic/src/components/ui/badge.tsx +49 -0
- package/templates/basic/src/components/ui/button.tsx +58 -0
- package/templates/basic/src/components/ui/card.tsx +88 -0
- package/templates/basic/src/components/ui/input.tsx +20 -0
- package/templates/basic/src/layouts/main.tsx +38 -0
- package/templates/basic/src/lib/auth.ts +70 -0
- package/templates/basic/src/lib/migrations/001_create_sessions.sql +9 -0
- package/templates/basic/src/lib/placeholder-data.ts +176 -0
- package/templates/basic/src/lib/utils.ts +6 -0
- package/templates/basic/src/pages/_404.tsx +17 -0
- package/templates/basic/src/pages/about.tsx +22 -0
- package/templates/basic/src/pages/blog.tsx +41 -0
- package/templates/basic/src/pages/dashboard/_middleware.ts +16 -0
- package/templates/basic/src/pages/dashboard/index.tsx +84 -0
- package/templates/basic/src/pages/index.tsx +54 -0
- package/templates/basic/src/pages/login.tsx +85 -0
- package/templates/basic/src/pages/placeholder.tsx +194 -0
- package/templates/basic/src/pages/posts/[id].tsx +17 -0
- package/templates/basic/src/styles/globals.css +90 -0
- package/templates/basic/src/x-routes.ts +29 -0
- package/templates/basic/tsconfig.json +11 -0
- package/templates/basic/x.config.ts +10 -0
- package/templates/blog/components.json +20 -0
- package/templates/blog/content/posts/getting-started.md +38 -0
- package/templates/blog/content/posts/hello-world.md +21 -0
- package/templates/blog/content/posts/tailwind-v4.md +31 -0
- package/templates/blog/public/favicon.ico +0 -0
- package/templates/blog/src/components/ui/avatar.tsx +91 -0
- package/templates/blog/src/components/ui/badge.tsx +49 -0
- package/templates/blog/src/components/ui/button.tsx +58 -0
- package/templates/blog/src/components/ui/card.tsx +88 -0
- package/templates/blog/src/components/ui/input.tsx +20 -0
- package/templates/blog/src/layouts/blog.tsx +46 -0
- package/templates/blog/src/layouts/main.tsx +32 -0
- package/templates/blog/src/lib/utils.ts +5 -0
- package/templates/blog/src/pages/about.tsx +36 -0
- package/templates/blog/src/pages/blog/[slug].tsx +56 -0
- package/templates/blog/src/pages/blog/index.tsx +70 -0
- package/templates/blog/src/pages/index.tsx +70 -0
- package/templates/blog/src/styles/globals.css +90 -0
- package/templates/blog/src/x-routes.ts +20 -0
- package/templates/blog/tsconfig.json +5 -0
- package/templates/blog/x.config.ts +6 -0
- package/templates/landing/components.json +20 -0
- package/templates/landing/public/favicon.ico +0 -0
- package/templates/landing/src/components/code-block.tsx +24 -0
- package/templates/landing/src/components/ui/avatar.tsx +91 -0
- package/templates/landing/src/components/ui/badge.tsx +49 -0
- package/templates/landing/src/components/ui/button.tsx +58 -0
- package/templates/landing/src/components/ui/card.tsx +88 -0
- package/templates/landing/src/components/ui/input.tsx +20 -0
- package/templates/landing/src/layouts/main.tsx +48 -0
- package/templates/landing/src/lib/syntax.tsx +366 -0
- package/templates/landing/src/lib/utils.ts +5 -0
- package/templates/landing/src/pages/contact.tsx +95 -0
- package/templates/landing/src/pages/docs/_layout.tsx +109 -0
- package/templates/landing/src/pages/docs/api-routes.tsx +113 -0
- package/templates/landing/src/pages/docs/build-deploy.tsx +124 -0
- package/templates/landing/src/pages/docs/configuration.tsx +121 -0
- package/templates/landing/src/pages/docs/content-collections.tsx +130 -0
- package/templates/landing/src/pages/docs/data-layer.tsx +142 -0
- package/templates/landing/src/pages/docs/getting-started.tsx +119 -0
- package/templates/landing/src/pages/docs/index.tsx +123 -0
- package/templates/landing/src/pages/docs/layouts.tsx +114 -0
- package/templates/landing/src/pages/docs/middleware.tsx +124 -0
- package/templates/landing/src/pages/docs/pages.tsx +135 -0
- package/templates/landing/src/pages/docs/routing.tsx +123 -0
- package/templates/landing/src/pages/docs/server-functions.tsx +123 -0
- package/templates/landing/src/pages/features.tsx +129 -0
- package/templates/landing/src/pages/index.tsx +175 -0
- package/templates/landing/src/styles/globals.css +100 -0
- package/templates/landing/src/x-routes.ts +31 -0
- package/templates/landing/tsconfig.json +5 -0
- package/templates/landing/x.config.ts +2 -0
- package/templates/saas/components.json +20 -0
- package/templates/saas/public/favicon.ico +0 -0
- package/templates/saas/src/actions/dashboard.ts +3 -0
- package/templates/saas/src/components/ui/avatar.tsx +91 -0
- package/templates/saas/src/components/ui/badge.tsx +49 -0
- package/templates/saas/src/components/ui/button.tsx +58 -0
- package/templates/saas/src/components/ui/card.tsx +88 -0
- package/templates/saas/src/components/ui/input.tsx +20 -0
- package/templates/saas/src/layouts/dashboard.tsx +67 -0
- package/templates/saas/src/layouts/main.tsx +38 -0
- package/templates/saas/src/lib/auth.ts +70 -0
- package/templates/saas/src/lib/migrations/001_create_sessions.sql +9 -0
- package/templates/saas/src/lib/utils.ts +5 -0
- package/templates/saas/src/pages/dashboard/_middleware.ts +9 -0
- package/templates/saas/src/pages/dashboard/analytics.tsx +68 -0
- package/templates/saas/src/pages/dashboard/index.tsx +86 -0
- package/templates/saas/src/pages/dashboard/settings.tsx +105 -0
- package/templates/saas/src/pages/index.tsx +110 -0
- package/templates/saas/src/pages/login.tsx +67 -0
- package/templates/saas/src/pages/pricing.tsx +121 -0
- package/templates/saas/src/styles/globals.css +90 -0
- package/templates/saas/src/x-routes.ts +22 -0
- package/templates/saas/tsconfig.json +5 -0
- package/templates/saas/x.config.ts +7 -0
|
@@ -0,0 +1,124 @@
|
|
|
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({}: RouteProps) {
|
|
6
|
+
return (
|
|
7
|
+
<div>
|
|
8
|
+
<p className="text-xs font-semibold uppercase tracking-[0.2em] text-primary">
|
|
9
|
+
Build & Deploy
|
|
10
|
+
</p>
|
|
11
|
+
<h1 className="mt-4 text-3xl font-bold tracking-tight sm:text-4xl">Build & deploy</h1>
|
|
12
|
+
<p className="mt-4 text-lg text-muted-foreground">
|
|
13
|
+
x produces optimized production builds with static HTML export, a server entry point, and
|
|
14
|
+
content collection rendering — all in a single command.
|
|
15
|
+
</p>
|
|
16
|
+
|
|
17
|
+
<h2 className="mt-12 text-xl font-bold tracking-tight">Build command</h2>
|
|
18
|
+
<p className="mt-3 text-muted-foreground">
|
|
19
|
+
Run <span className="text-foreground">x build</span> to produce a production build. The
|
|
20
|
+
build output goes to a <span className="text-foreground">.x/</span> directory.
|
|
21
|
+
</p>
|
|
22
|
+
<CodeBlock
|
|
23
|
+
label="terminal"
|
|
24
|
+
lang="bash"
|
|
25
|
+
code={`x build
|
|
26
|
+
[x] resolving routes...
|
|
27
|
+
[x] found 12 routes
|
|
28
|
+
[x] building static pages...
|
|
29
|
+
[x] building server bundle...
|
|
30
|
+
[x] rendering content collections...
|
|
31
|
+
[x] build complete in 1.2s`}
|
|
32
|
+
/>
|
|
33
|
+
|
|
34
|
+
<h2 className="mt-12 text-xl font-bold tracking-tight">Output structure</h2>
|
|
35
|
+
<p className="mt-3 text-muted-foreground">
|
|
36
|
+
The <span className="text-foreground">.x/</span> directory contains everything needed to
|
|
37
|
+
deploy — static files, server bundle, and assets.
|
|
38
|
+
</p>
|
|
39
|
+
<CodeBlock
|
|
40
|
+
label="output tree"
|
|
41
|
+
lang="tree"
|
|
42
|
+
code={`.x/
|
|
43
|
+
client/ // Client-side assets
|
|
44
|
+
assets/
|
|
45
|
+
*.js // Bundled JS
|
|
46
|
+
*.css // Extracted CSS
|
|
47
|
+
server/ // Server entry point
|
|
48
|
+
index.js // Bun server bundle
|
|
49
|
+
static/ // Prerendered HTML pages
|
|
50
|
+
index.html
|
|
51
|
+
about/index.html
|
|
52
|
+
blog/
|
|
53
|
+
hello-world/index.html
|
|
54
|
+
x.json // Build manifest`}
|
|
55
|
+
/>
|
|
56
|
+
|
|
57
|
+
<h2 className="mt-12 text-xl font-bold tracking-tight">Static page export</h2>
|
|
58
|
+
<p className="mt-3 text-muted-foreground">
|
|
59
|
+
Pages with <span className="text-foreground">mode = "static"</span> are exported as HTML
|
|
60
|
+
files in <span className="text-foreground">.x/static/</span>. Each page is fully rendered at
|
|
61
|
+
build time, including its loader output. For dynamic-static pages (static pages with dynamic
|
|
62
|
+
params), x generates one HTML file per unique path.
|
|
63
|
+
</p>
|
|
64
|
+
|
|
65
|
+
<h2 className="mt-12 text-xl font-bold tracking-tight">Server entry</h2>
|
|
66
|
+
<p className="mt-3 text-muted-foreground">
|
|
67
|
+
Server-rendered pages are bundled into{" "}
|
|
68
|
+
<span className="text-foreground">.x/server/index.js</span>. This file contains all server
|
|
69
|
+
routes, API handlers, server functions, and middleware — everything needed to run the
|
|
70
|
+
dynamic parts of your app.
|
|
71
|
+
</p>
|
|
72
|
+
|
|
73
|
+
<h2 className="mt-12 text-xl font-bold tracking-tight">Production server</h2>
|
|
74
|
+
<p className="mt-3 text-muted-foreground">
|
|
75
|
+
Use <span className="text-foreground">x start</span> to run the production server. It serves
|
|
76
|
+
static files from <span className="text-foreground">.x/static/</span> and handles dynamic
|
|
77
|
+
routes via the server bundle.
|
|
78
|
+
</p>
|
|
79
|
+
<CodeBlock
|
|
80
|
+
label="terminal"
|
|
81
|
+
lang="bash"
|
|
82
|
+
code={`x start
|
|
83
|
+
[x] production server running at http://localhost:3000`}
|
|
84
|
+
/>
|
|
85
|
+
|
|
86
|
+
<h2 className="mt-12 text-xl font-bold tracking-tight">Docker deployment</h2>
|
|
87
|
+
<p className="mt-3 text-muted-foreground">
|
|
88
|
+
Deploy with a minimal Docker image using the official Bun runtime. The build output is
|
|
89
|
+
self-contained.
|
|
90
|
+
</p>
|
|
91
|
+
<CodeBlock
|
|
92
|
+
label="Dockerfile"
|
|
93
|
+
code={`FROM oven/bun:1 AS build
|
|
94
|
+
WORKDIR /app
|
|
95
|
+
COPY package.json bun.lock .
|
|
96
|
+
RUN bun install
|
|
97
|
+
COPY . .
|
|
98
|
+
RUN x build
|
|
99
|
+
|
|
100
|
+
FROM oven/bun:1-slim
|
|
101
|
+
WORKDIR /app
|
|
102
|
+
COPY --from=build /app/.x .x
|
|
103
|
+
EXPOSE 3000
|
|
104
|
+
CMD ["x", "start"]`}
|
|
105
|
+
/>
|
|
106
|
+
|
|
107
|
+
<h2 className="mt-12 text-xl font-bold tracking-tight">Content collections in builds</h2>
|
|
108
|
+
<p className="mt-3 text-muted-foreground">
|
|
109
|
+
During <span className="text-foreground">x build</span>, content collections are scanned and
|
|
110
|
+
rendered. Each markdown file becomes a static HTML page if its route uses static mode, or is
|
|
111
|
+
available for server-rendered routes to consume.
|
|
112
|
+
</p>
|
|
113
|
+
|
|
114
|
+
<div className="mt-16 border-t border-border pt-8">
|
|
115
|
+
<a
|
|
116
|
+
href="/docs"
|
|
117
|
+
className="inline-flex items-center gap-1 text-sm text-muted-foreground transition-colors hover:text-foreground"
|
|
118
|
+
>
|
|
119
|
+
<ArrowRight className="h-3.5 w-3.5 rotate-180" /> Back to docs
|
|
120
|
+
</a>
|
|
121
|
+
</div>
|
|
122
|
+
</div>
|
|
123
|
+
);
|
|
124
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
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({}: RouteProps) {
|
|
6
|
+
return (
|
|
7
|
+
<div>
|
|
8
|
+
<p className="text-xs font-semibold uppercase tracking-[0.2em] text-primary">Configuration</p>
|
|
9
|
+
<h1 className="mt-4 text-3xl font-bold tracking-tight sm:text-4xl">Configuration</h1>
|
|
10
|
+
<p className="mt-4 text-lg text-muted-foreground">
|
|
11
|
+
Configure x via <span className="text-foreground">x.config.ts</span> at your project root.
|
|
12
|
+
Use <span className="text-foreground">defineConfig</span> from{" "}
|
|
13
|
+
<span className="text-foreground">@thexjs/core</span> for type-safe configuration.
|
|
14
|
+
</p>
|
|
15
|
+
|
|
16
|
+
<h2 className="mt-12 text-xl font-bold tracking-tight">defineConfig</h2>
|
|
17
|
+
<p className="mt-3 text-muted-foreground">
|
|
18
|
+
All configuration options are optional. x provides sensible defaults so you can start with
|
|
19
|
+
zero configuration and add settings as needed.
|
|
20
|
+
</p>
|
|
21
|
+
<CodeBlock
|
|
22
|
+
label="x.config.ts"
|
|
23
|
+
code={`import { defineConfig } from "@thexjs/core";
|
|
24
|
+
|
|
25
|
+
export default defineConfig({
|
|
26
|
+
// Page routes
|
|
27
|
+
pagesDir: "src/pages",
|
|
28
|
+
|
|
29
|
+
// Layout directory (for root layouts)
|
|
30
|
+
layoutsDir: "src/layouts",
|
|
31
|
+
|
|
32
|
+
// API routes
|
|
33
|
+
apiDir: "src/api",
|
|
34
|
+
|
|
35
|
+
// Server functions
|
|
36
|
+
actionsDir: "src/actions",
|
|
37
|
+
|
|
38
|
+
// Content collections (markdown)
|
|
39
|
+
contentDir: "content",
|
|
40
|
+
|
|
41
|
+
// Dev server port
|
|
42
|
+
port: 3000,
|
|
43
|
+
|
|
44
|
+
// Legacy routes directory
|
|
45
|
+
routesDir: "src/routes",
|
|
46
|
+
});`}
|
|
47
|
+
/>
|
|
48
|
+
|
|
49
|
+
<h2 className="mt-12 text-xl font-bold tracking-tight">All options reference</h2>
|
|
50
|
+
|
|
51
|
+
<CodeBlock
|
|
52
|
+
label="options table"
|
|
53
|
+
code={`Option Type Default Description
|
|
54
|
+
────────────────────────────────────────────────────────────
|
|
55
|
+
pagesDir string "src/pages" File-based page routes
|
|
56
|
+
layoutsDir string "src/layouts" Root layout directory
|
|
57
|
+
apiDir string "src/api" File-based API routes
|
|
58
|
+
actionsDir string "src/actions" Server functions
|
|
59
|
+
contentDir string "content" Markdown content collections
|
|
60
|
+
port number 3000 Dev server port
|
|
61
|
+
routesDir string undefined Legacy routes directory`}
|
|
62
|
+
/>
|
|
63
|
+
|
|
64
|
+
<h2 className="mt-12 text-xl font-bold tracking-tight">pagesDir</h2>
|
|
65
|
+
<p className="mt-3 text-muted-foreground">
|
|
66
|
+
The directory containing your page route files. Defaults to{" "}
|
|
67
|
+
<span className="text-foreground">src/pages</span>. Each{" "}
|
|
68
|
+
<span className="text-foreground">.tsx</span> file becomes a route based on its file path.
|
|
69
|
+
</p>
|
|
70
|
+
|
|
71
|
+
<h2 className="mt-12 text-xl font-bold tracking-tight">layoutsDir</h2>
|
|
72
|
+
<p className="mt-3 text-muted-foreground">
|
|
73
|
+
The directory for root layout components. Layouts wrap pages and can be nested using the{" "}
|
|
74
|
+
<span className="text-foreground">_layout.tsx</span> convention inside page directories.
|
|
75
|
+
</p>
|
|
76
|
+
|
|
77
|
+
<h2 className="mt-12 text-xl font-bold tracking-tight">apiDir</h2>
|
|
78
|
+
<p className="mt-3 text-muted-foreground">
|
|
79
|
+
The directory for API route files. Files here respond to HTTP methods (
|
|
80
|
+
<span className="text-foreground">GET</span>, <span className="text-foreground">POST</span>,
|
|
81
|
+
etc.) and are served under <span className="text-foreground">/api/...</span>.
|
|
82
|
+
</p>
|
|
83
|
+
|
|
84
|
+
<h2 className="mt-12 text-xl font-bold tracking-tight">actionsDir</h2>
|
|
85
|
+
<p className="mt-3 text-muted-foreground">
|
|
86
|
+
The directory for server functions. Exported async functions can be called from the browser
|
|
87
|
+
via <span className="text-foreground">fetch('/__x/actions/...')</span>.
|
|
88
|
+
</p>
|
|
89
|
+
|
|
90
|
+
<h2 className="mt-12 text-xl font-bold tracking-tight">contentDir</h2>
|
|
91
|
+
<p className="mt-3 text-muted-foreground">
|
|
92
|
+
The directory for markdown content collections. Files with frontmatter are scanned and can
|
|
93
|
+
be loaded via <span className="text-foreground">scanContent</span> and{" "}
|
|
94
|
+
<span className="text-foreground">renderMarkdown</span>.
|
|
95
|
+
</p>
|
|
96
|
+
|
|
97
|
+
<h2 className="mt-12 text-xl font-bold tracking-tight">port</h2>
|
|
98
|
+
<p className="mt-3 text-muted-foreground">
|
|
99
|
+
The port number for the dev server. Defaults to{" "}
|
|
100
|
+
<span className="text-foreground">3000</span>. Set to a different value if the default port
|
|
101
|
+
is in use.
|
|
102
|
+
</p>
|
|
103
|
+
|
|
104
|
+
<h2 className="mt-12 text-xl font-bold tracking-tight">routesDir (legacy)</h2>
|
|
105
|
+
<p className="mt-3 text-muted-foreground">
|
|
106
|
+
A legacy option for projects migrating from earlier versions of x. Maps to the same
|
|
107
|
+
file-based routing convention. Prefer <span className="text-foreground">pagesDir</span> for
|
|
108
|
+
new projects.
|
|
109
|
+
</p>
|
|
110
|
+
|
|
111
|
+
<div className="mt-16 border-t border-border pt-8">
|
|
112
|
+
<a
|
|
113
|
+
href="/docs"
|
|
114
|
+
className="inline-flex items-center gap-1 text-sm text-muted-foreground transition-colors hover:text-foreground"
|
|
115
|
+
>
|
|
116
|
+
<ArrowRight className="h-3.5 w-3.5 rotate-180" /> Back to docs
|
|
117
|
+
</a>
|
|
118
|
+
</div>
|
|
119
|
+
</div>
|
|
120
|
+
);
|
|
121
|
+
}
|
|
@@ -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 default function DocPage({}: RouteProps) {
|
|
6
|
+
return (
|
|
7
|
+
<div>
|
|
8
|
+
<p className="text-xs font-semibold uppercase tracking-[0.2em] text-primary">
|
|
9
|
+
Content Collections
|
|
10
|
+
</p>
|
|
11
|
+
<h1 className="mt-4 text-3xl font-bold tracking-tight sm:text-4xl">Content collections</h1>
|
|
12
|
+
<p className="mt-4 text-lg text-muted-foreground">
|
|
13
|
+
Write content in Markdown with frontmatter, and x automatically turns it into pages. Perfect
|
|
14
|
+
for blogs, documentation, and any content-driven site.
|
|
15
|
+
</p>
|
|
16
|
+
|
|
17
|
+
<h2 className="mt-12 text-xl font-bold tracking-tight">Configuration</h2>
|
|
18
|
+
<p className="mt-3 text-muted-foreground">
|
|
19
|
+
Point the content directory in <span className="text-foreground">x.config.ts</span> to a
|
|
20
|
+
folder with your markdown files.
|
|
21
|
+
</p>
|
|
22
|
+
<CodeBlock
|
|
23
|
+
label="x.config.ts"
|
|
24
|
+
code={`import { defineConfig } from "@thexjs/core";
|
|
25
|
+
|
|
26
|
+
export default defineConfig({
|
|
27
|
+
contentDir: "content",
|
|
28
|
+
});`}
|
|
29
|
+
/>
|
|
30
|
+
|
|
31
|
+
<h2 className="mt-12 text-xl font-bold tracking-tight">Markdown with frontmatter</h2>
|
|
32
|
+
<p className="mt-3 text-muted-foreground">
|
|
33
|
+
Each markdown file starts with frontmatter (YAML between{" "}
|
|
34
|
+
<span className="text-foreground">---</span> delimiters) followed by markdown content.
|
|
35
|
+
</p>
|
|
36
|
+
<CodeBlock
|
|
37
|
+
label="content/posts/hello-world.md"
|
|
38
|
+
lang="markdown"
|
|
39
|
+
code={`---
|
|
40
|
+
title: Hello World
|
|
41
|
+
date: 2026-03-15
|
|
42
|
+
tags: [getting-started, tutorial]
|
|
43
|
+
author: Jane Doe
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## Welcome to x!
|
|
47
|
+
|
|
48
|
+
This is your first post using x's content collection system.
|
|
49
|
+
|
|
50
|
+
You can write **markdown** with all the usual syntax:
|
|
51
|
+
|
|
52
|
+
- Lists
|
|
53
|
+
- **Bold** and *italic* text
|
|
54
|
+
- \`inline code\` and code blocks
|
|
55
|
+
|
|
56
|
+
\`\`\`ts
|
|
57
|
+
const greeting = "Hello from x!";
|
|
58
|
+
console.log(greeting);
|
|
59
|
+
\`\`\``}
|
|
60
|
+
/>
|
|
61
|
+
|
|
62
|
+
<h2 className="mt-12 text-xl font-bold tracking-tight">Reading content in a loader</h2>
|
|
63
|
+
<p className="mt-3 text-muted-foreground">
|
|
64
|
+
Use <span className="text-foreground">scanContent</span> to discover files and{" "}
|
|
65
|
+
<span className="text-foreground">renderMarkdown</span> to convert markdown to HTML in your
|
|
66
|
+
loaders.
|
|
67
|
+
</p>
|
|
68
|
+
<CodeBlock
|
|
69
|
+
label="src/pages/blog/[slug].tsx"
|
|
70
|
+
code={`import type { RouteProps, LoaderArgs } from "@thexjs/core";
|
|
71
|
+
import { scanContent, renderMarkdown } from "@thexjs/core";
|
|
72
|
+
|
|
73
|
+
export async function loader({ params }: LoaderArgs) {
|
|
74
|
+
const posts = await scanContent("posts");
|
|
75
|
+
const post = posts.find((p) => p.slug === params.slug);
|
|
76
|
+
if (!post) throw new Response(null, { status: 404 });
|
|
77
|
+
const html = await renderMarkdown(post.body);
|
|
78
|
+
return { post: { ...post, html } };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export default function BlogPost({ loaderData }: RouteProps<typeof loader>) {
|
|
82
|
+
return (
|
|
83
|
+
<article className="prose max-w-none">
|
|
84
|
+
<h1 className="text-4xl font-bold">{loaderData.post.title}</h1>
|
|
85
|
+
<p className="text-sm text-muted-foreground">
|
|
86
|
+
{loaderData.post.date} — {loaderData.post.author}
|
|
87
|
+
</p>
|
|
88
|
+
<div className="mt-6 flex gap-2">
|
|
89
|
+
{loaderData.post.tags?.map((tag: string) => (
|
|
90
|
+
<span key={tag} className="rounded-full bg-primary/10 px-3 py-1 text-xs text-primary">
|
|
91
|
+
{tag}
|
|
92
|
+
</span>
|
|
93
|
+
))}
|
|
94
|
+
</div>
|
|
95
|
+
<div
|
|
96
|
+
className="mt-8 leading-relaxed"
|
|
97
|
+
dangerouslySetInnerHTML={{ __html: loaderData.post.html }}
|
|
98
|
+
/>
|
|
99
|
+
</article>
|
|
100
|
+
);
|
|
101
|
+
}`}
|
|
102
|
+
/>
|
|
103
|
+
|
|
104
|
+
<h2 className="mt-12 text-xl font-bold tracking-tight">scanContent API</h2>
|
|
105
|
+
<p className="mt-3 text-muted-foreground">
|
|
106
|
+
<span className="text-foreground">scanContent(directory)</span> scans a subdirectory of your
|
|
107
|
+
content folder and returns an array of content entries. Each entry includes{" "}
|
|
108
|
+
<span className="text-foreground">slug</span>,{" "}
|
|
109
|
+
<span className="text-foreground">frontmatter</span>, and{" "}
|
|
110
|
+
<span className="text-foreground">content</span>.
|
|
111
|
+
</p>
|
|
112
|
+
|
|
113
|
+
<h2 className="mt-12 text-xl font-bold tracking-tight">renderMarkdown API</h2>
|
|
114
|
+
<p className="mt-3 text-muted-foreground">
|
|
115
|
+
<span className="text-foreground">renderMarkdown(markdownString)</span> converts markdown to
|
|
116
|
+
an HTML string. It supports syntax highlighting via Shiki and handles all standard markdown
|
|
117
|
+
features.
|
|
118
|
+
</p>
|
|
119
|
+
|
|
120
|
+
<div className="mt-16 border-t border-border pt-8">
|
|
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,142 @@
|
|
|
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({}: RouteProps) {
|
|
6
|
+
return (
|
|
7
|
+
<div>
|
|
8
|
+
<p className="text-xs font-semibold uppercase tracking-[0.2em] text-primary">Data Layer</p>
|
|
9
|
+
<h1 className="mt-4 text-3xl font-bold tracking-tight sm:text-4xl">Data layer</h1>
|
|
10
|
+
<p className="mt-4 text-lg text-muted-foreground">
|
|
11
|
+
x provides built-in SQLite and PostgreSQL integrations. Connect to a database, run
|
|
12
|
+
migrations, and query data directly from loaders and server functions.
|
|
13
|
+
</p>
|
|
14
|
+
|
|
15
|
+
<h2 className="mt-12 text-xl font-bold tracking-tight">SQLite</h2>
|
|
16
|
+
<p className="mt-3 text-muted-foreground">
|
|
17
|
+
Use <span className="text-foreground">connectSQLite</span> to connect to a local SQLite
|
|
18
|
+
database file. SQLite requires zero configuration and is perfect for development and
|
|
19
|
+
single-server deployments.
|
|
20
|
+
</p>
|
|
21
|
+
<CodeBlock
|
|
22
|
+
label="src/lib/db.ts"
|
|
23
|
+
code={`import { connectSQLite, runSQLiteMigrations } from "@thexjs/core";
|
|
24
|
+
|
|
25
|
+
const db = connectSQLite("data/app.db");
|
|
26
|
+
|
|
27
|
+
await runSQLiteMigrations(db, [
|
|
28
|
+
{
|
|
29
|
+
version: 1,
|
|
30
|
+
sql: \`
|
|
31
|
+
CREATE TABLE IF NOT EXISTS users (
|
|
32
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
33
|
+
name TEXT NOT NULL,
|
|
34
|
+
email TEXT UNIQUE NOT NULL,
|
|
35
|
+
created_at TEXT DEFAULT (datetime('now'))
|
|
36
|
+
)
|
|
37
|
+
\`,
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
version: 2,
|
|
41
|
+
sql: \`
|
|
42
|
+
CREATE TABLE IF NOT EXISTS posts (
|
|
43
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
44
|
+
user_id INTEGER REFERENCES users(id),
|
|
45
|
+
title TEXT NOT NULL,
|
|
46
|
+
body TEXT,
|
|
47
|
+
created_at TEXT DEFAULT (datetime('now'))
|
|
48
|
+
)
|
|
49
|
+
\`,
|
|
50
|
+
},
|
|
51
|
+
]);
|
|
52
|
+
|
|
53
|
+
export { db };`}
|
|
54
|
+
/>
|
|
55
|
+
|
|
56
|
+
<h2 className="mt-12 text-xl font-bold tracking-tight">Querying SQLite</h2>
|
|
57
|
+
<p className="mt-3 text-muted-foreground">
|
|
58
|
+
The database object supports prepared statements with{" "}
|
|
59
|
+
<span className="text-foreground">query</span> and{" "}
|
|
60
|
+
<span className="text-foreground">execute</span> methods.
|
|
61
|
+
</p>
|
|
62
|
+
<CodeBlock
|
|
63
|
+
label="src/pages/users.tsx"
|
|
64
|
+
code={`import type { RouteProps, LoaderArgs } from "@thexjs/core";
|
|
65
|
+
import { db } from "../lib/db";
|
|
66
|
+
|
|
67
|
+
export async function loader({}: LoaderArgs) {
|
|
68
|
+
const users = db.query(
|
|
69
|
+
"SELECT id, name, email FROM users ORDER BY created_at DESC"
|
|
70
|
+
).all();
|
|
71
|
+
return { users };
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export default function Users({ loaderData }: RouteProps<typeof loader>) {
|
|
75
|
+
return (
|
|
76
|
+
<div>
|
|
77
|
+
<h1 className="text-3xl font-bold">Users</h1>
|
|
78
|
+
<ul className="mt-6 space-y-3">
|
|
79
|
+
{loaderData.users.map((u: any) => (
|
|
80
|
+
<li key={u.id} className="rounded-xl border border-border bg-card p-4">
|
|
81
|
+
<p className="font-semibold">{u.name}</p>
|
|
82
|
+
<p className="text-sm text-muted-foreground">{u.email}</p>
|
|
83
|
+
</li>
|
|
84
|
+
))}
|
|
85
|
+
</ul>
|
|
86
|
+
</div>
|
|
87
|
+
);
|
|
88
|
+
}`}
|
|
89
|
+
/>
|
|
90
|
+
|
|
91
|
+
<h2 className="mt-12 text-xl font-bold tracking-tight">PostgreSQL</h2>
|
|
92
|
+
<p className="mt-3 text-muted-foreground">
|
|
93
|
+
For production deployments, use <span className="text-foreground">connectPostgres</span>{" "}
|
|
94
|
+
with a connection string. PostgreSQL provides concurrent access, connection pooling, and is
|
|
95
|
+
suitable for multi-server deployments.
|
|
96
|
+
</p>
|
|
97
|
+
<CodeBlock
|
|
98
|
+
label="src/lib/db.ts"
|
|
99
|
+
code={`import { connectPostgres, runPostgresMigrations } from "@thexjs/core";
|
|
100
|
+
|
|
101
|
+
const db = connectPostgres({
|
|
102
|
+
connectionString: process.env.DATABASE_URL,
|
|
103
|
+
max: 20, // connection pool size
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
await runPostgresMigrations(db, [
|
|
107
|
+
{
|
|
108
|
+
version: 1,
|
|
109
|
+
sql: \`
|
|
110
|
+
CREATE TABLE IF NOT EXISTS users (
|
|
111
|
+
id SERIAL PRIMARY KEY,
|
|
112
|
+
name VARCHAR(255) NOT NULL,
|
|
113
|
+
email VARCHAR(255) UNIQUE NOT NULL,
|
|
114
|
+
created_at TIMESTAMPTZ DEFAULT NOW()
|
|
115
|
+
)
|
|
116
|
+
\`,
|
|
117
|
+
},
|
|
118
|
+
]);
|
|
119
|
+
|
|
120
|
+
export { db };`}
|
|
121
|
+
/>
|
|
122
|
+
|
|
123
|
+
<h2 className="mt-12 text-xl font-bold tracking-tight">Migration API</h2>
|
|
124
|
+
<p className="mt-3 text-muted-foreground">
|
|
125
|
+
Both <span className="text-foreground">runSQLiteMigrations</span> and{" "}
|
|
126
|
+
<span className="text-foreground">runPostgresMigrations</span> take an array of migration
|
|
127
|
+
objects. Each migration has a <span className="text-foreground">version</span> number
|
|
128
|
+
(incrementing) and <span className="text-foreground">sql</span> string. Migrations are
|
|
129
|
+
tracked and only run once.
|
|
130
|
+
</p>
|
|
131
|
+
|
|
132
|
+
<div className="mt-16 border-t border-border pt-8">
|
|
133
|
+
<a
|
|
134
|
+
href="/docs"
|
|
135
|
+
className="inline-flex items-center gap-1 text-sm text-muted-foreground transition-colors hover:text-foreground"
|
|
136
|
+
>
|
|
137
|
+
<ArrowRight className="h-3.5 w-3.5 rotate-180" /> Back to docs
|
|
138
|
+
</a>
|
|
139
|
+
</div>
|
|
140
|
+
</div>
|
|
141
|
+
);
|
|
142
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
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({}: RouteProps) {
|
|
6
|
+
return (
|
|
7
|
+
<div>
|
|
8
|
+
<p className="text-xs font-semibold uppercase tracking-[0.2em] text-primary">
|
|
9
|
+
Getting Started
|
|
10
|
+
</p>
|
|
11
|
+
<h1 className="mt-4 text-3xl font-bold tracking-tight sm:text-4xl">Get started with x</h1>
|
|
12
|
+
<p className="mt-4 text-lg text-muted-foreground">
|
|
13
|
+
Create a new x project, learn the project structure, and build your first page.
|
|
14
|
+
</p>
|
|
15
|
+
|
|
16
|
+
<h2 className="mt-12 text-xl font-bold tracking-tight">Installation</h2>
|
|
17
|
+
<p className="mt-3 text-muted-foreground">
|
|
18
|
+
The fastest way to start is with the create-x CLI. Make sure you have{" "}
|
|
19
|
+
<a href="https://bun.sh" className="text-primary underline underline-offset-2">
|
|
20
|
+
Bun
|
|
21
|
+
</a>{" "}
|
|
22
|
+
installed, then run:
|
|
23
|
+
</p>
|
|
24
|
+
<CodeBlock
|
|
25
|
+
label="terminal"
|
|
26
|
+
lang="bash"
|
|
27
|
+
code={`bun create x my-app
|
|
28
|
+
cd my-app
|
|
29
|
+
x dev`}
|
|
30
|
+
/>
|
|
31
|
+
<p className="mt-4 text-muted-foreground">
|
|
32
|
+
Your app will be running at <span className="text-foreground">http://localhost:3000</span>.
|
|
33
|
+
</p>
|
|
34
|
+
|
|
35
|
+
<h2 className="mt-12 text-xl font-bold tracking-tight">Manual setup</h2>
|
|
36
|
+
<p className="mt-3 text-muted-foreground">
|
|
37
|
+
If you prefer to set up manually, create a directory and add x:
|
|
38
|
+
</p>
|
|
39
|
+
<CodeBlock
|
|
40
|
+
label="terminal"
|
|
41
|
+
lang="bash"
|
|
42
|
+
code={`mkdir my-app && cd my-app
|
|
43
|
+
bun init -y
|
|
44
|
+
bun add @thexjs/core
|
|
45
|
+
cat << EOF > x.config.ts
|
|
46
|
+
import { defineConfig } from "@thexjs/core";
|
|
47
|
+
export default defineConfig({
|
|
48
|
+
pagesDir: "src/pages",
|
|
49
|
+
});
|
|
50
|
+
EOF`}
|
|
51
|
+
/>
|
|
52
|
+
|
|
53
|
+
<h2 className="mt-12 text-xl font-bold tracking-tight">Project structure</h2>
|
|
54
|
+
<p className="mt-3 text-muted-foreground">A typical x project looks like this:</p>
|
|
55
|
+
<CodeBlock
|
|
56
|
+
label="file tree"
|
|
57
|
+
lang="tree"
|
|
58
|
+
code={`my-app/
|
|
59
|
+
x.config.ts
|
|
60
|
+
src/
|
|
61
|
+
pages/ // File-based routes
|
|
62
|
+
index.tsx
|
|
63
|
+
about.tsx
|
|
64
|
+
_404.tsx
|
|
65
|
+
blog/
|
|
66
|
+
[slug].tsx
|
|
67
|
+
layouts/ // Nested layouts
|
|
68
|
+
main.tsx
|
|
69
|
+
api/ // API routes
|
|
70
|
+
hello.ts
|
|
71
|
+
actions/ // Server functions
|
|
72
|
+
greet.ts
|
|
73
|
+
content/ // Markdown content
|
|
74
|
+
posts/
|
|
75
|
+
hello-world.md`}
|
|
76
|
+
/>
|
|
77
|
+
|
|
78
|
+
<h2 className="mt-12 text-xl font-bold tracking-tight">Your first page</h2>
|
|
79
|
+
<p className="mt-3 text-muted-foreground">
|
|
80
|
+
Create <span className="text-foreground">src/pages/index.tsx</span> with a simple component:
|
|
81
|
+
</p>
|
|
82
|
+
<CodeBlock
|
|
83
|
+
label="src/pages/index.tsx"
|
|
84
|
+
code={`export default function Home() {
|
|
85
|
+
return (
|
|
86
|
+
<div>
|
|
87
|
+
<h1 className="text-4xl font-bold">Hello x!</h1>
|
|
88
|
+
<p className="text-muted-foreground">Welcome to your new app.</p>
|
|
89
|
+
</div>
|
|
90
|
+
);
|
|
91
|
+
}`}
|
|
92
|
+
/>
|
|
93
|
+
|
|
94
|
+
<h2 className="mt-12 text-xl font-bold tracking-tight">Running the dev server</h2>
|
|
95
|
+
<p className="mt-3 text-muted-foreground">Start the development server with hot reload:</p>
|
|
96
|
+
<CodeBlock
|
|
97
|
+
label="terminal"
|
|
98
|
+
lang="bash"
|
|
99
|
+
code={`x dev
|
|
100
|
+
[x] resolving routes...
|
|
101
|
+
[x] found 3 routes in 12ms
|
|
102
|
+
[x] dev server running at http://localhost:3000`}
|
|
103
|
+
/>
|
|
104
|
+
<p className="mt-4 text-muted-foreground">
|
|
105
|
+
The dev server watches your <span className="text-foreground">src/</span> directory and
|
|
106
|
+
automatically reloads when files change.
|
|
107
|
+
</p>
|
|
108
|
+
|
|
109
|
+
<div className="mt-16 border-t border-border pt-8">
|
|
110
|
+
<a
|
|
111
|
+
href="/docs"
|
|
112
|
+
className="inline-flex items-center gap-1 text-sm text-muted-foreground transition-colors hover:text-foreground"
|
|
113
|
+
>
|
|
114
|
+
<ArrowRight className="h-3.5 w-3.5 rotate-180" /> Back to docs
|
|
115
|
+
</a>
|
|
116
|
+
</div>
|
|
117
|
+
</div>
|
|
118
|
+
);
|
|
119
|
+
}
|