create-thexjs-app 1.0.0 → 1.1.1

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 (139) hide show
  1. package/README.md +56 -915
  2. package/dist/index.js +283 -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/_gitignore +26 -0
  18. package/templates/base/src/pages/index.tsx +29 -0
  19. package/templates/base/src/styles/globals.css +22 -0
  20. package/templates/base/tsconfig.json +24 -0
  21. package/templates/basic/content/blog/hello.md +0 -8
  22. package/templates/basic/public/favicon.ico +0 -0
  23. package/templates/basic/src/actions/dashboard/greet.ts +0 -3
  24. package/templates/basic/src/api/placeholder/comments.ts +0 -17
  25. package/templates/basic/src/api/placeholder/posts.ts +0 -20
  26. package/templates/basic/src/api/placeholder/todos.ts +0 -21
  27. package/templates/basic/src/api/placeholder/users.ts +0 -12
  28. package/templates/basic/src/components/Head.tsx +0 -21
  29. package/templates/basic/src/components/Image.tsx +0 -27
  30. package/templates/basic/src/components/Link.tsx +0 -10
  31. package/templates/basic/src/components/ui/badge.tsx +0 -49
  32. package/templates/basic/src/components/ui/button.tsx +0 -58
  33. package/templates/basic/src/components/ui/card.tsx +0 -88
  34. package/templates/basic/src/components/ui/input.tsx +0 -20
  35. package/templates/basic/src/layouts/main.tsx +0 -38
  36. package/templates/basic/src/lib/placeholder-data.ts +0 -176
  37. package/templates/basic/src/pages/_404.tsx +0 -17
  38. package/templates/basic/src/pages/about.tsx +0 -22
  39. package/templates/basic/src/pages/blog.tsx +0 -41
  40. package/templates/basic/src/pages/dashboard/index.tsx +0 -84
  41. package/templates/basic/src/pages/index.tsx +0 -54
  42. package/templates/basic/src/pages/login.tsx +0 -92
  43. package/templates/basic/src/pages/placeholder.tsx +0 -203
  44. package/templates/basic/src/pages/posts/[id].tsx +0 -17
  45. package/templates/basic/src/styles/globals.css +0 -90
  46. package/templates/basic/src/x-routes.ts +0 -29
  47. package/templates/basic/tsconfig.json +0 -11
  48. package/templates/basic/x.config.ts +0 -10
  49. package/templates/blog/components.json +0 -20
  50. package/templates/blog/content/posts/getting-started.md +0 -38
  51. package/templates/blog/content/posts/hello-world.md +0 -21
  52. package/templates/blog/content/posts/tailwind-v4.md +0 -31
  53. package/templates/blog/public/favicon.ico +0 -0
  54. package/templates/blog/src/components/ui/avatar.tsx +0 -91
  55. package/templates/blog/src/components/ui/badge.tsx +0 -49
  56. package/templates/blog/src/components/ui/button.tsx +0 -58
  57. package/templates/blog/src/components/ui/card.tsx +0 -88
  58. package/templates/blog/src/components/ui/input.tsx +0 -20
  59. package/templates/blog/src/layouts/blog.tsx +0 -46
  60. package/templates/blog/src/layouts/main.tsx +0 -32
  61. package/templates/blog/src/lib/utils.ts +0 -5
  62. package/templates/blog/src/pages/about.tsx +0 -36
  63. package/templates/blog/src/pages/blog/[slug].tsx +0 -56
  64. package/templates/blog/src/pages/blog/index.tsx +0 -70
  65. package/templates/blog/src/pages/index.tsx +0 -73
  66. package/templates/blog/src/styles/globals.css +0 -90
  67. package/templates/blog/src/x-routes.ts +0 -20
  68. package/templates/blog/tsconfig.json +0 -5
  69. package/templates/blog/x.config.ts +0 -6
  70. package/templates/default/components.json +0 -19
  71. package/templates/default/src/layouts/main.tsx +0 -28
  72. package/templates/default/src/pages/index.tsx +0 -66
  73. package/templates/default/src/styles/globals.css +0 -55
  74. package/templates/default/src/x-routes.ts +0 -17
  75. package/templates/default/tsconfig.json +0 -5
  76. package/templates/default/x.config.ts +0 -6
  77. package/templates/landing/components.json +0 -20
  78. package/templates/landing/public/favicon.ico +0 -0
  79. package/templates/landing/src/components/code-block.tsx +0 -118
  80. package/templates/landing/src/components/ui/avatar.tsx +0 -91
  81. package/templates/landing/src/components/ui/badge.tsx +0 -49
  82. package/templates/landing/src/components/ui/button.tsx +0 -58
  83. package/templates/landing/src/components/ui/card.tsx +0 -88
  84. package/templates/landing/src/components/ui/input.tsx +0 -20
  85. package/templates/landing/src/layouts/main.tsx +0 -78
  86. package/templates/landing/src/lib/syntax.tsx +0 -366
  87. package/templates/landing/src/lib/utils.ts +0 -5
  88. package/templates/landing/src/pages/docs/_layout.tsx +0 -139
  89. package/templates/landing/src/pages/docs/api-routes.tsx +0 -113
  90. package/templates/landing/src/pages/docs/build-deploy.tsx +0 -124
  91. package/templates/landing/src/pages/docs/configuration.tsx +0 -121
  92. package/templates/landing/src/pages/docs/content-collections.tsx +0 -130
  93. package/templates/landing/src/pages/docs/data-layer.tsx +0 -142
  94. package/templates/landing/src/pages/docs/getting-started.tsx +0 -129
  95. package/templates/landing/src/pages/docs/index.tsx +0 -187
  96. package/templates/landing/src/pages/docs/installation.tsx +0 -143
  97. package/templates/landing/src/pages/docs/introduction.tsx +0 -114
  98. package/templates/landing/src/pages/docs/layouts.tsx +0 -114
  99. package/templates/landing/src/pages/docs/middleware.tsx +0 -124
  100. package/templates/landing/src/pages/docs/packages/cli.tsx +0 -133
  101. package/templates/landing/src/pages/docs/packages/core.tsx +0 -176
  102. package/templates/landing/src/pages/docs/packages/env.tsx +0 -128
  103. package/templates/landing/src/pages/docs/pages.tsx +0 -135
  104. package/templates/landing/src/pages/docs/routing.tsx +0 -123
  105. package/templates/landing/src/pages/docs/server-functions.tsx +0 -177
  106. package/templates/landing/src/pages/features.tsx +0 -129
  107. package/templates/landing/src/pages/index.tsx +0 -159
  108. package/templates/landing/src/styles/globals.css +0 -136
  109. package/templates/landing/src/x-routes.ts +0 -31
  110. package/templates/landing/tsconfig.json +0 -10
  111. package/templates/landing/x.config.ts +0 -2
  112. package/templates/saas/components.json +0 -20
  113. package/templates/saas/public/favicon.ico +0 -0
  114. package/templates/saas/src/actions/dashboard.ts +0 -3
  115. package/templates/saas/src/api/auth/login.ts +0 -31
  116. package/templates/saas/src/components/ui/avatar.tsx +0 -91
  117. package/templates/saas/src/components/ui/badge.tsx +0 -49
  118. package/templates/saas/src/components/ui/button.tsx +0 -58
  119. package/templates/saas/src/components/ui/card.tsx +0 -88
  120. package/templates/saas/src/components/ui/input.tsx +0 -20
  121. package/templates/saas/src/layouts/dashboard.tsx +0 -67
  122. package/templates/saas/src/layouts/main.tsx +0 -38
  123. package/templates/saas/src/lib/auth.ts +0 -91
  124. package/templates/saas/src/lib/migrations/001_create_sessions.sql +0 -9
  125. package/templates/saas/src/lib/utils.ts +0 -5
  126. package/templates/saas/src/pages/dashboard/_middleware.ts +0 -9
  127. package/templates/saas/src/pages/dashboard/analytics.tsx +0 -68
  128. package/templates/saas/src/pages/dashboard/index.tsx +0 -86
  129. package/templates/saas/src/pages/dashboard/settings.tsx +0 -111
  130. package/templates/saas/src/pages/index.tsx +0 -110
  131. package/templates/saas/src/pages/login.tsx +0 -140
  132. package/templates/saas/src/pages/pricing.tsx +0 -121
  133. package/templates/saas/src/styles/globals.css +0 -90
  134. package/templates/saas/src/x-routes.ts +0 -22
  135. package/templates/saas/tsconfig.json +0 -5
  136. package/templates/saas/x.config.ts +0 -7
  137. /package/templates/{basic → addons/auth}/src/api/auth/logout.ts +0 -0
  138. /package/templates/{basic → addons/auth}/src/pages/dashboard/_middleware.ts +0 -0
  139. /package/templates/{basic → addons/shadcn}/src/lib/utils.ts +0 -0
@@ -1,78 +0,0 @@
1
- import type { ReactNode } from "react";
2
-
3
- function LogoMark() {
4
- return (
5
- <svg viewBox="0 0 24 24" className="h-5 w-5" fill="none" aria-hidden="true">
6
- <title>x logo</title>
7
- <polygon points="3,5 5,3 21,19 19,21" fill="currentColor" />
8
- <polygon points="19,5 21,3 5,21 3,19" fill="currentColor" opacity="0.45" />
9
- </svg>
10
- );
11
- }
12
-
13
- export default function RootLayout({ children }: { children: ReactNode }) {
14
- return (
15
- <div className="flex min-h-screen flex-col bg-background">
16
- <header className="fixed top-0 z-[99] w-full border-b border-border/50 bg-background/70 backdrop-blur-xl">
17
- <div className="mx-auto flex h-14 max-w-6xl items-center justify-between px-6">
18
- <a
19
- href="/"
20
- className="group flex items-center gap-2.5 text-primary transition-opacity hover:opacity-90"
21
- aria-label="x home"
22
- >
23
- <span className="flex h-8 w-8 items-center justify-center rounded-lg border border-border bg-card">
24
- <LogoMark />
25
- </span>
26
- <span className="font-display text-sm font-bold tracking-tight text-foreground/90">
27
- x
28
- </span>
29
- </a>
30
- <nav className="flex items-center gap-6 text-sm font-medium text-muted-foreground">
31
- <a href="/docs" className="transition-colors hover:text-foreground">
32
- Docs
33
- </a>
34
- <a href="/features" className="transition-colors hover:text-foreground">
35
- Features
36
- </a>
37
- <a
38
- href="https://github.com/abdelkabirouadoukou/x"
39
- target="_blank"
40
- rel="noopener noreferrer"
41
- className="hidden items-center gap-1.5 transition-colors hover:text-foreground sm:flex"
42
- >
43
- GitHub
44
- </a>
45
- <a
46
- href="/docs/installation"
47
- className="inline-flex h-8 items-center rounded-lg bg-primary px-3.5 text-xs font-semibold text-primary-foreground transition-colors hover:bg-primary/90"
48
- >
49
- Install
50
- </a>
51
- </nav>
52
- </div>
53
- </header>
54
- <main className="flex-1 pt-14">{children}</main>
55
- <footer className="border-t border-border/50">
56
- <div className="mx-auto flex max-w-6xl flex-col items-center justify-between gap-3 px-6 py-10 text-sm text-muted-foreground sm:flex-row">
57
- <p>
58
- <span className="font-display font-bold text-foreground">x</span> — fullstack framework
59
- for Bun
60
- </p>
61
- <div className="flex gap-5">
62
- <a href="/docs" className="transition-colors hover:text-foreground">
63
- Documentation
64
- </a>
65
- <a
66
- href="https://github.com/abdelkabirouadoukou/x"
67
- target="_blank"
68
- rel="noopener noreferrer"
69
- className="transition-colors hover:text-foreground"
70
- >
71
- GitHub
72
- </a>
73
- </div>
74
- </div>
75
- </footer>
76
- </div>
77
- );
78
- }
@@ -1,366 +0,0 @@
1
- import type { ReactNode } from "react";
2
-
3
- const KEYWORDS = new Set([
4
- "export",
5
- "default",
6
- "function",
7
- "const",
8
- "let",
9
- "var",
10
- "return",
11
- "import",
12
- "from",
13
- "async",
14
- "await",
15
- "if",
16
- "else",
17
- "for",
18
- "while",
19
- "class",
20
- "interface",
21
- "type",
22
- "extends",
23
- "implements",
24
- "new",
25
- "this",
26
- "true",
27
- "false",
28
- "null",
29
- "undefined",
30
- "void",
31
- "throw",
32
- "try",
33
- "catch",
34
- "finally",
35
- "switch",
36
- "case",
37
- "break",
38
- "continue",
39
- "typeof",
40
- "instanceof",
41
- "in",
42
- "of",
43
- "import type",
44
- "import {",
45
- ]);
46
-
47
- export function highlight(code: string, lang = "tsx"): ReactNode {
48
- if (lang === "bash" || lang === "terminal") {
49
- return highlightBash(code);
50
- }
51
- if (lang === "tree") {
52
- return highlightTree(code);
53
- }
54
- return highlightCode(code);
55
- }
56
-
57
- function highlightBash(code: string): ReactNode {
58
- return code.split("\n").map((line, i) => {
59
- const trimmed = line.trimStart();
60
- if (trimmed.startsWith("$")) {
61
- const indent = line.slice(0, line.length - trimmed.length);
62
- const rest = trimmed.slice(1);
63
- return (
64
- <span key={i} className="block">
65
- {indent}
66
- <span className="text-[#7ee787]">$</span>
67
- {rest}
68
- </span>
69
- );
70
- }
71
- if (trimmed === "" || trimmed.startsWith("//")) {
72
- return (
73
- <span key={i} className="block text-[#848d97]">
74
- {line}
75
- </span>
76
- );
77
- }
78
- if (trimmed.startsWith(" ")) {
79
- return (
80
- <span key={i} className="block text-[#848d97]">
81
- {line}
82
- </span>
83
- );
84
- }
85
- return (
86
- <span key={i} className="block">
87
- {line}
88
- </span>
89
- );
90
- });
91
- }
92
-
93
- function highlightTree(code: string): ReactNode {
94
- return code.split("\n").map((line, i) => {
95
- const s = line.trimStart();
96
- if (s.endsWith("/")) {
97
- return (
98
- <span key={i} className="block text-[#79c0ff]">
99
- {line}
100
- </span>
101
- );
102
- }
103
- const commentIdx = s.indexOf("//");
104
- if (commentIdx !== -1) {
105
- const before = s.slice(0, commentIdx);
106
- const after = s.slice(commentIdx);
107
- return (
108
- <span key={i} className="block">
109
- {before}
110
- <span className="text-[#848d97]">{after}</span>
111
- </span>
112
- );
113
- }
114
- return (
115
- <span key={i} className="block">
116
- {line}
117
- </span>
118
- );
119
- });
120
- }
121
-
122
- function highlightCode(code: string): ReactNode {
123
- const lines = code.split("\n");
124
- const result: ReactNode[] = [];
125
-
126
- for (let i = 0; i < lines.length; i++) {
127
- const line = lines[i];
128
- if (line === undefined) continue;
129
- result.push(
130
- <span key={i} className="block">
131
- {tokenizeLine(line)}
132
- </span>,
133
- );
134
- }
135
-
136
- return result;
137
- }
138
-
139
- function tokenizeLine(line: string): ReactNode[] {
140
- const tokens: ReactNode[] = [];
141
- let i = 0;
142
- let key = 0;
143
-
144
- const flushText = (start: number, end: number) => {
145
- if (end > start) {
146
- tokens.push(<span key={key++}>{line.slice(start, end)}</span>);
147
- }
148
- };
149
-
150
- while (i < line.length) {
151
- if (line[i] === " " || line[i] === "\t") {
152
- const start = i;
153
- while (i < line.length && (line[i] === " " || line[i] === "\t")) i++;
154
- tokens.push(line.slice(start, i));
155
- continue;
156
- }
157
-
158
- if (line[i] === "/" && line[i + 1] === "/") {
159
- tokens.push(
160
- <span key={key++} className="text-[#848d97]">
161
- {line.slice(i)}
162
- </span>,
163
- );
164
- break;
165
- }
166
-
167
- if (line[i] === '"') {
168
- let str = '"';
169
- i++;
170
- while (i < line.length) {
171
- if (line[i] === "\\") {
172
- str += line[i];
173
- i++;
174
- if (i < line.length) {
175
- str += line[i];
176
- i++;
177
- }
178
- continue;
179
- }
180
- if (line[i] === '"') {
181
- str += '"';
182
- i++;
183
- break;
184
- }
185
- str += line[i];
186
- i++;
187
- }
188
- tokens.push(
189
- <span key={key++} className="text-[#a5d6ff]">
190
- {str}
191
- </span>,
192
- );
193
- continue;
194
- }
195
-
196
- if (line[i] === "'") {
197
- let str = "'";
198
- i++;
199
- while (i < line.length) {
200
- if (line[i] === "\\") {
201
- str += line[i];
202
- i++;
203
- if (i < line.length) {
204
- str += line[i];
205
- i++;
206
- }
207
- continue;
208
- }
209
- if (line[i] === "'") {
210
- str += "'";
211
- i++;
212
- break;
213
- }
214
- str += line[i];
215
- i++;
216
- }
217
- tokens.push(
218
- <span key={key++} className="text-[#a5d6ff]">
219
- {str}
220
- </span>,
221
- );
222
- continue;
223
- }
224
-
225
- if (line[i] === "`") {
226
- let str = "`";
227
- i++;
228
- while (i < line.length) {
229
- if (line[i] === "\\") {
230
- str += line[i];
231
- i++;
232
- if (i < line.length) {
233
- str += line[i];
234
- i++;
235
- }
236
- continue;
237
- }
238
- if (line[i] === "`") {
239
- str += "`";
240
- i++;
241
- break;
242
- }
243
- if (line[i] === "$" && line[i + 1] === "{") {
244
- str += "${";
245
- i += 2;
246
- continue;
247
- }
248
- str += line[i];
249
- i++;
250
- }
251
- tokens.push(
252
- <span key={key++} className="text-[#a5d6ff]">
253
- {str}
254
- </span>,
255
- );
256
- continue;
257
- }
258
-
259
- if (
260
- i < line.length &&
261
- /[0-9]/.test(line[i]!) &&
262
- (i === 0 || /[\s([,=*/%+\-!<>|&^~?:;]/.test(line[i - 1]!))
263
- ) {
264
- let num = "";
265
- while (i < line.length && /[0-9.]/.test(line[i]!)) {
266
- num += line[i]!;
267
- i++;
268
- }
269
- tokens.push(
270
- <span key={key++} className="text-[#79c0ff]">
271
- {num}
272
- </span>,
273
- );
274
- continue;
275
- }
276
-
277
- if (i < line.length && line[i]! === "<") {
278
- let tag = "<";
279
- i++;
280
- if (i < line.length && line[i]! === "/") {
281
- tag += "/";
282
- i++;
283
- }
284
- const nameStart = i;
285
- while (i < line.length && /[a-zA-Z0-9]/.test(line[i]!)) {
286
- i++;
287
- }
288
- const name = line.slice(nameStart, i);
289
- if (name) {
290
- tag += name;
291
- tokens.push(
292
- <span key={key++} className="text-[#ffa657]">
293
- {tag}
294
- </span>,
295
- );
296
- } else {
297
- tokens.push(
298
- <span key={key++} className="text-[#e6edf3]">
299
- {tag}
300
- </span>,
301
- );
302
- }
303
- continue;
304
- }
305
-
306
- if (i < line.length && line[i]! === "/" && i + 1 < line.length && line[i + 1]! === ">") {
307
- tokens.push(
308
- <span key={key++} className="text-[#ffa657]">
309
- {"/> "}
310
- </span>,
311
- );
312
- i += 1;
313
- continue;
314
- }
315
-
316
- if (i < line.length && /[a-zA-Z_$]/.test(line[i]!)) {
317
- let word = "";
318
- while (i < line.length && /[a-zA-Z0-9_$]/.test(line[i]!)) {
319
- word += line[i]!;
320
- i++;
321
- }
322
-
323
- const restTrimmed = line.slice(i).trimStart();
324
- if (
325
- restTrimmed.startsWith("=") &&
326
- !restTrimmed.startsWith("===") &&
327
- !restTrimmed.startsWith("=>")
328
- ) {
329
- tokens.push(
330
- <span key={key++} className="text-[#79c0ff]">
331
- {word}
332
- </span>,
333
- );
334
- const afterWord = line.slice(i);
335
- const eqIdx = afterWord.indexOf("=");
336
- if (eqIdx > 0) {
337
- tokens.push(<span key={key++}>{afterWord.slice(0, eqIdx)}</span>);
338
- i += eqIdx;
339
- }
340
- continue;
341
- }
342
-
343
- if (KEYWORDS.has(word)) {
344
- tokens.push(
345
- <span key={key++} className="text-[#ff7b72]">
346
- {word}
347
- </span>,
348
- );
349
- } else if (word.length > 0 && word[0]! >= "A" && word[0]! <= "Z") {
350
- tokens.push(
351
- <span key={key++} className="text-[#d2a8ff]">
352
- {word}
353
- </span>,
354
- );
355
- } else {
356
- tokens.push(<span key={key++}>{word}</span>);
357
- }
358
- continue;
359
- }
360
-
361
- tokens.push(<span key={key++}>{line[i]}</span>);
362
- i++;
363
- }
364
-
365
- return tokens;
366
- }
@@ -1,5 +0,0 @@
1
- import { type ClassValue, clsx } from "clsx";
2
- import { twMerge } from "tailwind-merge";
3
- export function cn(...inputs: ClassValue[]) {
4
- return twMerge(clsx(inputs));
5
- }
@@ -1,139 +0,0 @@
1
- import { Menu, X } from "lucide-react";
2
- import type { ReactNode } from "react";
3
-
4
- const sidebarSections = [
5
- {
6
- title: "Start here",
7
- links: [
8
- { href: "/docs", label: "Overview" },
9
- { href: "/docs/introduction", label: "Introduction" },
10
- { href: "/docs/installation", label: "Installation" },
11
- { href: "/docs/getting-started", label: "Getting Started" },
12
- ],
13
- },
14
- {
15
- title: "Packages",
16
- links: [
17
- { href: "/docs/packages/core", label: "@thexjs/core" },
18
- { href: "/docs/packages/cli", label: "@thexjs/cli" },
19
- { href: "/docs/packages/env", label: "@thexjs/env" },
20
- { href: "/docs/packages/adapter-vercel", label: "@thexjs/adapter-vercel" },
21
- ],
22
- },
23
- {
24
- title: "Guides",
25
- links: [
26
- { href: "/docs/routing", label: "Routing" },
27
- { href: "/docs/pages", label: "Pages & Loaders" },
28
- { href: "/docs/layouts", label: "Layouts" },
29
- { href: "/docs/api-routes", label: "API Routes" },
30
- { href: "/docs/server-functions", label: "Server Functions" },
31
- { href: "/docs/content-collections", label: "Content Collections" },
32
- { href: "/docs/middleware", label: "Middleware" },
33
- { href: "/docs/data-layer", label: "Data Layer" },
34
- { href: "/docs/build-deploy", label: "Build & Deploy" },
35
- { href: "/docs/configuration", label: "Configuration" },
36
- { href: "/docs/security", label: "Security" },
37
- { href: "/docs/observability", label: "Observability" },
38
- ],
39
- },
40
- ];
41
-
42
- function SidebarNav() {
43
- return (
44
- <>
45
- {sidebarSections.map((section) => (
46
- <div key={section.title} className="mb-7 last:mb-0">
47
- <p className="mb-2 font-mono text-[10px] uppercase tracking-[0.18em] text-primary/80">
48
- {section.title}
49
- </p>
50
- <ul className="space-y-0.5">
51
- {section.links.map((link) => (
52
- <li key={link.href}>
53
- <a
54
- href={link.href}
55
- data-doc-link={link.href}
56
- className="doc-nav-link block rounded-lg border border-transparent px-3 py-2 text-[13px] text-muted-foreground transition-colors hover:border-border/60 hover:bg-muted/50 hover:text-foreground"
57
- >
58
- {link.label}
59
- </a>
60
- </li>
61
- ))}
62
- </ul>
63
- </div>
64
- ))}
65
- </>
66
- );
67
- }
68
-
69
- export default function DocsLayout({ children }: { children: ReactNode }) {
70
- return (
71
- <div className="mx-auto flex min-h-[calc(100vh-3.5rem)] w-full max-w-6xl px-4 sm:px-6">
72
- <button
73
- id="sidebar-btn"
74
- type="button"
75
- className="fixed left-4 top-[4.25rem] z-50 flex h-8 w-8 items-center justify-center rounded-lg border border-border bg-background text-muted-foreground shadow-sm transition-colors hover:bg-muted hover:text-foreground lg:hidden"
76
- aria-label="Toggle sidebar"
77
- >
78
- <Menu className="h-4 w-4 btn-icon-open" />
79
- <X className="hidden h-4 w-4 btn-icon-close" />
80
- </button>
81
-
82
- <div id="sidebar-overlay" className="fixed inset-0 z-40 hidden bg-black/60 lg:hidden" />
83
-
84
- <aside
85
- id="sidebar-panel"
86
- className="fixed left-0 top-14 z-50 hidden h-[calc(100vh-3.5rem)] w-60 overflow-y-auto border-r border-border/50 bg-background lg:hidden"
87
- >
88
- <nav className="px-3 pb-6 pt-4">
89
- <SidebarNav />
90
- </nav>
91
- </aside>
92
-
93
- <aside className="hidden w-60 shrink-0 border-r border-border/50 lg:block">
94
- <nav className="sticky top-14 max-h-[calc(100vh-3.5rem)] overflow-y-auto px-3 pb-8 pt-2">
95
- <SidebarNav />
96
- </nav>
97
- </aside>
98
-
99
- <div className="min-w-0 flex-1">
100
- <div className="doc-content mx-auto max-w-3xl px-4 py-10 sm:px-8 sm:py-12">{children}</div>
101
- </div>
102
-
103
- <script
104
- dangerouslySetInnerHTML={{
105
- __html: `
106
- (function(){
107
- var path=location.pathname.replace(/\\/$/,"")||"/docs";
108
- document.querySelectorAll("[data-doc-link]").forEach(function(a){
109
- var href=a.getAttribute("data-doc-link").replace(/\\/$/,"")||"/docs";
110
- if(href===path||(path!=="/docs"&&href!=="/docs"&&path.indexOf(href)===0)){
111
- a.classList.add("border-primary/30","bg-primary/10","text-primary");
112
- }
113
- });
114
- var btn=document.getElementById("sidebar-btn");
115
- var panel=document.getElementById("sidebar-panel");
116
- var overlay=document.getElementById("sidebar-overlay");
117
- if(!btn||!panel||!overlay)return;
118
- function close(){btn.classList.remove("open");panel.classList.add("hidden");overlay.classList.add("hidden")}
119
- function openn(){btn.classList.add("open");panel.classList.remove("hidden");overlay.classList.remove("hidden")}
120
- btn.addEventListener("click",function(){if(panel.classList.contains("hidden"))openn();else close()});
121
- overlay.addEventListener("click",close);
122
- panel.querySelectorAll("a").forEach(function(a){a.addEventListener("click",close)});
123
- })();
124
- `.trim(),
125
- }}
126
- />
127
- <style
128
- dangerouslySetInnerHTML={{
129
- __html: `
130
- @media (max-width:1023px){
131
- #sidebar-btn.open .btn-icon-open{display:none}
132
- #sidebar-btn.open .btn-icon-close{display:block}
133
- }
134
- `.trim(),
135
- }}
136
- />
137
- </div>
138
- );
139
- }
@@ -1,113 +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">API Routes</p>
9
- <h1 className="mt-4 text-3xl font-bold tracking-tight sm:text-4xl">API routes</h1>
10
- <p className="mt-4 text-lg text-muted-foreground">
11
- Build REST endpoints alongside your frontend pages. API routes live in{" "}
12
- <span className="text-foreground">src/api/</span> and share the same process as your pages.
13
- </p>
14
-
15
- <h2 className="mt-12 text-xl font-bold tracking-tight">File-based API routing</h2>
16
- <p className="mt-3 text-muted-foreground">
17
- Like pages, API routes use the file system. A file at{" "}
18
- <span className="text-foreground">src/api/hello.ts</span> becomes{" "}
19
- <span className="text-foreground">/api/hello</span>.
20
- </p>
21
- <CodeBlock
22
- label="src/api/hello.ts"
23
- code={`import type { ApiHandler } from "@thexjs/core";
24
-
25
- export const GET: ApiHandler = ({ request }) => {
26
- return Response.json({ message: "Hello from x!" });
27
- };`}
28
- />
29
-
30
- <h2 className="mt-12 text-xl font-bold tracking-tight">Request &amp; response</h2>
31
- <p className="mt-3 text-muted-foreground">
32
- Each exported HTTP method receives the request and returns a standard{" "}
33
- <span className="text-foreground">Response</span> object. Dynamic segments work the same as
34
- pages: <span className="text-foreground">api/users/[id].ts</span> →{" "}
35
- <span className="text-foreground">/api/users/:id</span>.
36
- </p>
37
- <CodeBlock
38
- label="src/api/users.ts"
39
- code={`import type { ApiHandler } from "@thexjs/core";
40
-
41
- export const GET: ApiHandler = async ({ request }) => {
42
- const users = await db.query("SELECT * FROM users");
43
- return Response.json(users);
44
- };
45
-
46
- export const POST: ApiHandler = async ({ request }) => {
47
- const body = await request.json();
48
- const result = await db.query(
49
- "INSERT INTO users (name, email) VALUES (?, ?) RETURNING *",
50
- [body.name, body.email]
51
- );
52
- return Response.json(result, { status: 201 });
53
- };`}
54
- />
55
-
56
- <h2 className="mt-12 text-xl font-bold tracking-tight">POST endpoint example</h2>
57
- <CodeBlock
58
- label="src/api/contact.ts"
59
- code={`import type { ApiHandler } from "@thexjs/core";
60
-
61
- export const POST: ApiHandler = async ({ request }) => {
62
- const form = await request.formData();
63
- const email = form.get("email");
64
- const message = form.get("message");
65
-
66
- if (!email || !message) {
67
- return Response.json(
68
- { error: "Email and message are required" },
69
- { status: 400 }
70
- );
71
- }
72
-
73
- await sendEmail({ email, message });
74
- return Response.json({ success: true });
75
- };`}
76
- />
77
-
78
- <h2 className="mt-12 text-xl font-bold tracking-tight">API route tree</h2>
79
- <p className="mt-3 text-muted-foreground">
80
- API routes support the same file-tree conventions as pages — nested folders, dynamic
81
- segments, and index files.
82
- </p>
83
- <CodeBlock
84
- label="file tree"
85
- lang="tree"
86
- code={`src/api/
87
- hello.ts -> GET /api/hello
88
- users.ts -> GET, POST /api/users
89
- users/
90
- [id].ts -> GET, PUT, DELETE /api/users/:id
91
- auth/
92
- login.ts -> POST /api/auth/login
93
- register.ts -> POST /api/auth/register`}
94
- />
95
-
96
- <h2 className="mt-12 text-xl font-bold tracking-tip">Process sharing</h2>
97
- <p className="mt-3 text-muted-foreground">
98
- API routes run in the same Bun process as your pages and server functions. This means you
99
- can share database connections, in-memory caches, and configuration without any network
100
- overhead.
101
- </p>
102
-
103
- <div className="mt-16 border-t border-border pt-8">
104
- <a
105
- href="/docs"
106
- className="inline-flex items-center gap-1 text-sm text-muted-foreground transition-colors hover:text-foreground"
107
- >
108
- <ArrowRight className="h-3.5 w-3.5 rotate-180" /> Back to docs
109
- </a>
110
- </div>
111
- </div>
112
- );
113
- }