create-thexjs-app 0.1.4 → 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.
Files changed (138) hide show
  1. package/README.md +56 -985
  2. package/dist/index.js +265 -196
  3. package/package.json +5 -1
  4. package/templates/{basic → addons/auth}/src/api/auth/login.ts +1 -3
  5. package/templates/{basic → addons/auth}/src/lib/auth.ts +13 -9
  6. package/templates/{basic → addons/auth}/src/lib/migrations/001_create_sessions.sql +1 -3
  7. package/templates/addons/auth/src/pages/dashboard/index.tsx +39 -0
  8. package/templates/addons/auth/src/pages/login.tsx +72 -0
  9. package/templates/addons/content/content/hello-world.md +13 -0
  10. package/templates/addons/content/src/pages/blog.tsx +29 -0
  11. package/templates/{basic → addons/shadcn}/components.json +1 -1
  12. package/templates/addons/shadcn/src/components/ui/badge.tsx +17 -0
  13. package/templates/addons/shadcn/src/components/ui/button.tsx +36 -0
  14. package/templates/addons/shadcn/src/components/ui/card.tsx +33 -0
  15. package/templates/addons/shadcn/src/components/ui/input.tsx +18 -0
  16. package/templates/addons/tailwind/src/styles/globals.css +32 -0
  17. package/templates/base/src/pages/index.tsx +29 -0
  18. package/templates/base/src/styles/globals.css +22 -0
  19. package/templates/base/tsconfig.json +24 -0
  20. package/templates/basic/content/blog/hello.md +0 -8
  21. package/templates/basic/public/favicon.ico +0 -0
  22. package/templates/basic/src/actions/dashboard/greet.ts +0 -3
  23. package/templates/basic/src/api/placeholder/comments.ts +0 -17
  24. package/templates/basic/src/api/placeholder/posts.ts +0 -20
  25. package/templates/basic/src/api/placeholder/todos.ts +0 -21
  26. package/templates/basic/src/api/placeholder/users.ts +0 -12
  27. package/templates/basic/src/components/Head.tsx +0 -21
  28. package/templates/basic/src/components/Image.tsx +0 -27
  29. package/templates/basic/src/components/Link.tsx +0 -10
  30. package/templates/basic/src/components/ui/badge.tsx +0 -49
  31. package/templates/basic/src/components/ui/button.tsx +0 -58
  32. package/templates/basic/src/components/ui/card.tsx +0 -88
  33. package/templates/basic/src/components/ui/input.tsx +0 -20
  34. package/templates/basic/src/layouts/main.tsx +0 -38
  35. package/templates/basic/src/lib/placeholder-data.ts +0 -176
  36. package/templates/basic/src/pages/_404.tsx +0 -17
  37. package/templates/basic/src/pages/about.tsx +0 -22
  38. package/templates/basic/src/pages/blog.tsx +0 -41
  39. package/templates/basic/src/pages/dashboard/index.tsx +0 -84
  40. package/templates/basic/src/pages/index.tsx +0 -54
  41. package/templates/basic/src/pages/login.tsx +0 -92
  42. package/templates/basic/src/pages/placeholder.tsx +0 -203
  43. package/templates/basic/src/pages/posts/[id].tsx +0 -17
  44. package/templates/basic/src/styles/globals.css +0 -90
  45. package/templates/basic/src/x-routes.ts +0 -29
  46. package/templates/basic/tsconfig.json +0 -11
  47. package/templates/basic/x.config.ts +0 -10
  48. package/templates/blog/components.json +0 -20
  49. package/templates/blog/content/posts/getting-started.md +0 -38
  50. package/templates/blog/content/posts/hello-world.md +0 -21
  51. package/templates/blog/content/posts/tailwind-v4.md +0 -31
  52. package/templates/blog/public/favicon.ico +0 -0
  53. package/templates/blog/src/components/ui/avatar.tsx +0 -91
  54. package/templates/blog/src/components/ui/badge.tsx +0 -49
  55. package/templates/blog/src/components/ui/button.tsx +0 -58
  56. package/templates/blog/src/components/ui/card.tsx +0 -88
  57. package/templates/blog/src/components/ui/input.tsx +0 -20
  58. package/templates/blog/src/layouts/blog.tsx +0 -46
  59. package/templates/blog/src/layouts/main.tsx +0 -32
  60. package/templates/blog/src/lib/utils.ts +0 -5
  61. package/templates/blog/src/pages/about.tsx +0 -36
  62. package/templates/blog/src/pages/blog/[slug].tsx +0 -56
  63. package/templates/blog/src/pages/blog/index.tsx +0 -70
  64. package/templates/blog/src/pages/index.tsx +0 -73
  65. package/templates/blog/src/styles/globals.css +0 -90
  66. package/templates/blog/src/x-routes.ts +0 -20
  67. package/templates/blog/tsconfig.json +0 -5
  68. package/templates/blog/x.config.ts +0 -6
  69. package/templates/default/components.json +0 -19
  70. package/templates/default/src/layouts/main.tsx +0 -28
  71. package/templates/default/src/pages/index.tsx +0 -66
  72. package/templates/default/src/styles/globals.css +0 -55
  73. package/templates/default/src/x-routes.ts +0 -17
  74. package/templates/default/tsconfig.json +0 -5
  75. package/templates/default/x.config.ts +0 -6
  76. package/templates/landing/components.json +0 -20
  77. package/templates/landing/public/favicon.ico +0 -0
  78. package/templates/landing/src/components/code-block.tsx +0 -118
  79. package/templates/landing/src/components/ui/avatar.tsx +0 -91
  80. package/templates/landing/src/components/ui/badge.tsx +0 -49
  81. package/templates/landing/src/components/ui/button.tsx +0 -58
  82. package/templates/landing/src/components/ui/card.tsx +0 -88
  83. package/templates/landing/src/components/ui/input.tsx +0 -20
  84. package/templates/landing/src/layouts/main.tsx +0 -78
  85. package/templates/landing/src/lib/syntax.tsx +0 -366
  86. package/templates/landing/src/lib/utils.ts +0 -5
  87. package/templates/landing/src/pages/docs/_layout.tsx +0 -139
  88. package/templates/landing/src/pages/docs/api-routes.tsx +0 -113
  89. package/templates/landing/src/pages/docs/build-deploy.tsx +0 -124
  90. package/templates/landing/src/pages/docs/configuration.tsx +0 -121
  91. package/templates/landing/src/pages/docs/content-collections.tsx +0 -130
  92. package/templates/landing/src/pages/docs/data-layer.tsx +0 -142
  93. package/templates/landing/src/pages/docs/getting-started.tsx +0 -129
  94. package/templates/landing/src/pages/docs/index.tsx +0 -187
  95. package/templates/landing/src/pages/docs/installation.tsx +0 -143
  96. package/templates/landing/src/pages/docs/introduction.tsx +0 -114
  97. package/templates/landing/src/pages/docs/layouts.tsx +0 -114
  98. package/templates/landing/src/pages/docs/middleware.tsx +0 -124
  99. package/templates/landing/src/pages/docs/packages/cli.tsx +0 -133
  100. package/templates/landing/src/pages/docs/packages/core.tsx +0 -176
  101. package/templates/landing/src/pages/docs/packages/env.tsx +0 -128
  102. package/templates/landing/src/pages/docs/pages.tsx +0 -135
  103. package/templates/landing/src/pages/docs/routing.tsx +0 -123
  104. package/templates/landing/src/pages/docs/server-functions.tsx +0 -177
  105. package/templates/landing/src/pages/features.tsx +0 -129
  106. package/templates/landing/src/pages/index.tsx +0 -159
  107. package/templates/landing/src/styles/globals.css +0 -136
  108. package/templates/landing/src/x-routes.ts +0 -31
  109. package/templates/landing/tsconfig.json +0 -10
  110. package/templates/landing/x.config.ts +0 -2
  111. package/templates/saas/components.json +0 -20
  112. package/templates/saas/public/favicon.ico +0 -0
  113. package/templates/saas/src/actions/dashboard.ts +0 -3
  114. package/templates/saas/src/api/auth/login.ts +0 -31
  115. package/templates/saas/src/components/ui/avatar.tsx +0 -91
  116. package/templates/saas/src/components/ui/badge.tsx +0 -49
  117. package/templates/saas/src/components/ui/button.tsx +0 -58
  118. package/templates/saas/src/components/ui/card.tsx +0 -88
  119. package/templates/saas/src/components/ui/input.tsx +0 -20
  120. package/templates/saas/src/layouts/dashboard.tsx +0 -67
  121. package/templates/saas/src/layouts/main.tsx +0 -38
  122. package/templates/saas/src/lib/auth.ts +0 -91
  123. package/templates/saas/src/lib/migrations/001_create_sessions.sql +0 -9
  124. package/templates/saas/src/lib/utils.ts +0 -5
  125. package/templates/saas/src/pages/dashboard/_middleware.ts +0 -9
  126. package/templates/saas/src/pages/dashboard/analytics.tsx +0 -68
  127. package/templates/saas/src/pages/dashboard/index.tsx +0 -86
  128. package/templates/saas/src/pages/dashboard/settings.tsx +0 -111
  129. package/templates/saas/src/pages/index.tsx +0 -110
  130. package/templates/saas/src/pages/login.tsx +0 -140
  131. package/templates/saas/src/pages/pricing.tsx +0 -121
  132. package/templates/saas/src/styles/globals.css +0 -90
  133. package/templates/saas/src/x-routes.ts +0 -22
  134. package/templates/saas/tsconfig.json +0 -5
  135. package/templates/saas/x.config.ts +0 -7
  136. /package/templates/{basic → addons/auth}/src/api/auth/logout.ts +0 -0
  137. /package/templates/{basic → addons/auth}/src/pages/dashboard/_middleware.ts +0 -0
  138. /package/templates/{basic → addons/shadcn}/src/lib/utils.ts +0 -0
@@ -1,124 +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">
9
- Build &amp; Deploy
10
- </p>
11
- <h1 className="mt-4 text-3xl font-bold tracking-tight sm:text-4xl">Build &amp; 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
- }
@@ -1,121 +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">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
- }
@@ -1,130 +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">
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
- }
@@ -1,142 +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">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/data";
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/data";
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
- }
@@ -1,129 +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">
11
- Getting Started
12
- </p>
13
- <h1 className="mt-4 text-3xl font-bold tracking-tight sm:text-4xl">Get started with x</h1>
14
- <p className="mt-4 text-lg text-muted-foreground">
15
- Create a new x project, learn the project structure, and build your first page.
16
- </p>
17
-
18
- <h2 className="mt-12 text-xl font-bold tracking-tight">Create a project</h2>
19
- <p className="mt-3 text-muted-foreground">
20
- The fastest way to start is with the project scaffolder. See{" "}
21
- <a href="/docs/installation" className="text-primary underline underline-offset-2">
22
- Installation
23
- </a>{" "}
24
- for prerequisites and template options. Quick version:
25
- </p>
26
- <CodeBlock
27
- label="terminal"
28
- lang="bash"
29
- code={`bun create thexjs-app@latest my-app
30
- cd my-app
31
- bun run dev`}
32
- />
33
- <p className="mt-4 text-muted-foreground">
34
- Press Enter at the template prompt to use <span className="text-foreground">default</span>{" "}
35
- (recommended) — a single home page. Your app will be running at{" "}
36
- <span className="text-foreground">http://localhost:3000</span>.
37
- </p>
38
-
39
- <h2 className="mt-12 text-xl font-bold tracking-tight">Manual setup</h2>
40
- <p className="mt-3 text-muted-foreground">
41
- If you prefer to set up manually, create a directory and add x:
42
- </p>
43
- <CodeBlock
44
- label="terminal"
45
- lang="bash"
46
- code={`mkdir my-app && cd my-app
47
- bun init -y
48
- bun add @thexjs/core
49
- cat << EOF > x.config.ts
50
- import { defineConfig } from "@thexjs/core";
51
- export default defineConfig({
52
- pagesDir: "src/pages",
53
- });
54
- EOF`}
55
- />
56
-
57
- <h2 className="mt-12 text-xl font-bold tracking-tight">Project structure</h2>
58
- <p className="mt-3 text-muted-foreground">A typical x project looks like this:</p>
59
- <CodeBlock
60
- label="file tree"
61
- lang="tree"
62
- code={`my-app/
63
- x.config.ts
64
- src/
65
- pages/ // File-based routes
66
- index.tsx
67
- about.tsx
68
- _404.tsx
69
- blog/
70
- [slug].tsx
71
- layouts/ // Nested layouts
72
- main.tsx
73
- api/ // API routes
74
- hello.ts
75
- actions/ // Server functions
76
- greet.ts
77
- content/ // Markdown content
78
- posts/
79
- hello-world.md`}
80
- />
81
-
82
- <h2 className="mt-12 text-xl font-bold tracking-tight">Your first page</h2>
83
- <p className="mt-3 text-muted-foreground">
84
- Create <span className="text-foreground">src/pages/index.tsx</span> with a simple component:
85
- </p>
86
- <CodeBlock
87
- label="src/pages/index.tsx"
88
- code={`export default function Home() {
89
- return (
90
- <div>
91
- <h1 className="text-4xl font-bold">Hello x!</h1>
92
- <p className="text-muted-foreground">Welcome to your new app.</p>
93
- </div>
94
- );
95
- }`}
96
- />
97
-
98
- <h2 className="mt-12 text-xl font-bold tracking-tight">Running the dev server</h2>
99
- <p className="mt-3 text-muted-foreground">Start the development server with hot reload:</p>
100
- <CodeBlock
101
- label="terminal"
102
- lang="bash"
103
- code={`x dev
104
- [x] resolving routes...
105
- [x] found 3 routes in 12ms
106
- [x] dev server running at http://localhost:3000`}
107
- />
108
- <p className="mt-4 text-muted-foreground">
109
- The dev server watches your <span className="text-foreground">src/</span> directory and
110
- automatically reloads when files change.
111
- </p>
112
-
113
- <div className="mt-16 flex flex-wrap gap-6 border-t border-border pt-8">
114
- <a
115
- href="/docs/routing"
116
- className="inline-flex items-center gap-1 text-sm font-medium text-primary transition-colors hover:text-primary/80"
117
- >
118
- Routing <ArrowRight className="h-3.5 w-3.5" />
119
- </a>
120
- <a
121
- href="/docs"
122
- className="inline-flex items-center gap-1 text-sm text-muted-foreground transition-colors hover:text-foreground"
123
- >
124
- <ArrowRight className="h-3.5 w-3.5 rotate-180" /> Back to docs
125
- </a>
126
- </div>
127
- </div>
128
- );
129
- }