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
package/dist/index.js CHANGED
@@ -2,153 +2,140 @@
2
2
 
3
3
  // src/index.ts
4
4
  import { spawnSync } from "child_process";
5
- import { cpSync, existsSync, mkdirSync, readdirSync, writeFileSync } from "fs";
5
+ import { cpSync, existsSync, mkdirSync, readdirSync, statSync, writeFileSync } from "fs";
6
6
  import { dirname, join, resolve } from "path";
7
- import { createInterface } from "readline/promises";
8
7
  import { fileURLToPath } from "url";
8
+ import {
9
+ cancel,
10
+ confirm,
11
+ intro,
12
+ isCancel,
13
+ log,
14
+ multiselect,
15
+ note,
16
+ outro,
17
+ spinner,
18
+ text
19
+ } from "@clack/prompts";
9
20
 
10
21
  // src/templates.ts
11
- var DEFAULT_TEMPLATE = "default";
12
- var TEMPLATES = {
13
- default: {
14
- label: "Default",
15
- description: "Blank slate with a single home page \u2014 the fastest way to start.",
16
- recommended: true,
22
+ var FEATURES = [
23
+ {
24
+ id: "tailwind",
25
+ label: "Tailwind CSS",
26
+ hint: "Utility-first styling + the x dev build pipeline",
27
+ default: true,
17
28
  dependencies: {
18
- react: "^19.1.0",
19
- "react-dom": "^19.1.0"
20
- },
21
- devDependencies: {
22
29
  "@tailwindcss/cli": "^4.3.3",
23
- "@types/react": "^19.1.0",
24
- "@types/react-dom": "^19.1.0",
25
- tailwindcss: "^4.3.3",
26
- typescript: "^5.8.0"
27
- }
30
+ tailwindcss: "^4.3.3"
31
+ },
32
+ devDependencies: {}
28
33
  },
29
- basic: {
30
- label: "Basic",
31
- description: "Minimal starter: pages, an API route, auth, and a dashboard.",
34
+ {
35
+ id: "shadcn",
36
+ label: "shadcn/ui",
37
+ hint: "Accessible React components (requires Tailwind)",
38
+ default: false,
39
+ requires: ["tailwind"],
32
40
  dependencies: {
33
41
  "@base-ui/react": "^1.6.0",
34
- "@tailwindcss/cli": "^4.3.3",
35
42
  "class-variance-authority": "^0.7.1",
36
43
  clsx: "^2.1.1",
37
44
  "lucide-react": "^1.27.0",
38
- react: "^19.0.0",
39
- "react-dom": "^19.0.0",
40
- shadcn: "^4.15.0",
41
45
  "tailwind-merge": "^3.6.0",
42
- tailwindcss: "^4.3.3",
43
46
  "tw-animate-css": "^1.4.0"
44
47
  },
45
48
  devDependencies: {
46
- "@types/react": "^19.0.0",
47
- "@types/react-dom": "^19.0.0"
48
- }
49
- },
50
- blog: {
51
- label: "Blog",
52
- description: "Markdown content collections, post listing, and post pages.",
53
- dependencies: {
54
- react: "^19.1.0",
55
- "react-dom": "^19.1.0",
56
- shadcn: "^4.2.0",
57
- "class-variance-authority": "^0.7.1",
58
- clsx: "^2.1.1",
59
- "tailwind-merge": "^3.2.0",
60
- "lucide-react": "^0.511.0",
61
- "tw-animate-css": "^1.2.0",
62
- "@base-ui/react": "^1.6.0"
63
- },
64
- devDependencies: {
65
- "@tailwindcss/cli": "^4.3.3",
66
- "@types/react": "^19.1.0",
67
- "@types/react-dom": "^19.1.0",
68
- tailwindcss: "^4.3.3",
69
- typescript: "^5.8.0"
49
+ shadcn: "^4.17.0"
70
50
  }
71
51
  },
72
- saas: {
73
- label: "SaaS",
74
- description: "Dashboard, settings, pricing, auth, and a data layer example.",
75
- dependencies: {
76
- react: "^19.1.0",
77
- "react-dom": "^19.1.0",
78
- shadcn: "^4.2.0",
79
- "class-variance-authority": "^0.7.1",
80
- clsx: "^2.1.1",
81
- "tailwind-merge": "^3.2.0",
82
- "lucide-react": "^0.511.0",
83
- "tw-animate-css": "^1.2.0",
84
- "@base-ui/react": "^1.6.0"
85
- },
86
- devDependencies: {
87
- "@tailwindcss/cli": "^4.3.3",
88
- "@types/react": "^19.1.0",
89
- "@types/react-dom": "^19.1.0",
90
- tailwindcss: "^4.3.3",
91
- typescript: "^5.8.0"
92
- }
52
+ {
53
+ id: "auth",
54
+ label: "Auth (sessions + login)",
55
+ hint: "SQLite-backed demo sessions, /login and a protected /dashboard",
56
+ default: false,
57
+ dependencies: {},
58
+ devDependencies: {}
93
59
  },
94
- landing: {
95
- label: "Landing",
96
- description: "Marketing site with docs pages, styled with shadcn/Tailwind.",
97
- dependencies: {
98
- react: "^19.1.0",
99
- "react-dom": "^19.1.0",
100
- shadcn: "^4.2.0",
101
- "class-variance-authority": "^0.7.1",
102
- clsx: "^2.1.1",
103
- "tailwind-merge": "^3.2.0",
104
- "lucide-react": "^0.511.0",
105
- "tw-animate-css": "^1.2.0",
106
- "@base-ui/react": "^1.6.0"
107
- },
108
- devDependencies: {
109
- "@tailwindcss/cli": "^4.3.3",
110
- "@types/react": "^19.1.0",
111
- "@types/react-dom": "^19.1.0",
112
- tailwindcss: "^4.3.3",
113
- typescript: "^5.8.0"
114
- }
60
+ {
61
+ id: "content",
62
+ label: "Content collections",
63
+ hint: "Markdown/MDX with frontmatter, auto-routed from content/",
64
+ default: false,
65
+ dependencies: {},
66
+ devDependencies: {}
115
67
  }
68
+ ];
69
+ var BASE_DEPENDENCIES = {
70
+ react: "^19.1.0",
71
+ "react-dom": "^19.1.0"
72
+ };
73
+ var BASE_DEV_DEPENDENCIES = {
74
+ "@types/react": "^19.1.0",
75
+ "@types/react-dom": "^19.1.0",
76
+ typescript: "^5.8.0"
116
77
  };
117
- var TEMPLATE_NAMES = Object.keys(TEMPLATES);
118
-
119
- // src/terminal.ts
120
- var reset = "\x1B[0m";
121
- var muted = "\x1B[2m";
122
- var bold = "\x1B[1m";
123
- var amber = "\x1B[38;2;232;149;47m";
124
- var cyan = "\x1B[38;2;61;214;198m";
125
- var green = "\x1B[38;2;78;201;120m";
126
- function banner() {
127
- console.log("");
128
- console.log(` ${amber}${bold}create-thexjs-app${reset}`);
129
- console.log(` ${muted}Scaffold a new x project${reset}`);
130
- console.log("");
131
- }
132
- function step(message) {
133
- console.log(`${amber}\u2192${reset} ${message}`);
134
- }
135
- function success(message) {
136
- console.log(`${green}\u2713${reset} ${message}`);
137
- }
138
- function command(cmd) {
139
- console.log(` ${cyan}${cmd}${reset}`);
140
- }
141
- function dim(message) {
142
- console.log(`${muted}${message}${reset}`);
143
- }
144
- function dimText(message) {
145
- return `${muted}${message}${reset}`;
146
- }
147
78
 
148
79
  // src/index.ts
80
+ function abort(message) {
81
+ cancel(message);
82
+ process.exit(1);
83
+ }
149
84
  var __dirname = dirname(fileURLToPath(import.meta.url));
150
85
  var TEMPLATES_ROOT = join(__dirname, "..", "templates");
86
+ var BASE_TEMPLATE = join(TEMPLATES_ROOT, "base");
87
+ var ADDONS_ROOT = join(TEMPLATES_ROOT, "addons");
151
88
  var FALLBACK_CORE_VERSION = "0.1.0";
89
+ function parseArgs(argv) {
90
+ const options = {
91
+ features: [],
92
+ install: true,
93
+ git: true,
94
+ runDev: false
95
+ };
96
+ const positional = [];
97
+ const nonInteractive = [];
98
+ for (let i = 0; i < argv.length; i++) {
99
+ const arg = argv[i];
100
+ switch (arg) {
101
+ case "--template":
102
+ case "-t":
103
+ i++;
104
+ break;
105
+ case "--no-install":
106
+ options.install = false;
107
+ break;
108
+ case "--no-git":
109
+ options.git = false;
110
+ break;
111
+ case "--dev":
112
+ options.runDev = true;
113
+ break;
114
+ case "--tailwind":
115
+ nonInteractive.push("tailwind");
116
+ break;
117
+ case "--shadcn":
118
+ nonInteractive.push("shadcn");
119
+ break;
120
+ case "--auth":
121
+ nonInteractive.push("auth");
122
+ break;
123
+ case "--content":
124
+ nonInteractive.push("content");
125
+ break;
126
+ default:
127
+ if (arg && !arg.startsWith("--")) positional.push(arg);
128
+ }
129
+ }
130
+ const firstPositional = positional[0];
131
+ if (firstPositional) {
132
+ options.projectName = firstPositional;
133
+ }
134
+ if (nonInteractive.length > 0) {
135
+ options.features = Array.from(/* @__PURE__ */ new Set([...options.features, ...nonInteractive]));
136
+ }
137
+ return options;
138
+ }
152
139
  function slugify(name) {
153
140
  return name.trim().toLowerCase().replace(/[^a-z0-9-]+/g, "-").replace(/^-+|-+$/g, "") || "thexjs-app";
154
141
  }
@@ -167,102 +154,184 @@ async function fetchLatestVersion(pkg) {
167
154
  return null;
168
155
  }
169
156
  }
170
- async function prompt(question, fallback) {
171
- const rl = createInterface({ input: process.stdin, output: process.stdout });
172
- const suffix = fallback ? ` (${fallback})` : "";
173
- const answer = await rl.question(`${question}${suffix}: `);
174
- rl.close();
175
- return answer.trim() || fallback || "";
157
+ function ensureDir(path) {
158
+ if (!existsSync(path)) mkdirSync(path, { recursive: true });
159
+ }
160
+ function mergeTree(src, dest) {
161
+ ensureDir(dest);
162
+ for (const entry of readdirSync(src)) {
163
+ const from = join(src, entry);
164
+ const to = join(dest, entry);
165
+ const stat = statSync(from);
166
+ if (stat.isDirectory()) {
167
+ mergeTree(from, to);
168
+ } else {
169
+ cpSync(from, to);
170
+ }
171
+ }
176
172
  }
177
- function printBanner() {
178
- banner();
173
+ function copyAddon(addon, targetDir) {
174
+ const src = join(ADDONS_ROOT, addon);
175
+ if (!existsSync(src)) return;
176
+ mergeTree(src, targetDir);
179
177
  }
180
- function printTemplateList() {
181
- for (const name of TEMPLATE_NAMES) {
182
- const meta = TEMPLATES[name];
178
+ function buildPackageJson(name, features, coreVersion, cliVersion) {
179
+ const dependencies = {
180
+ ...BASE_DEPENDENCIES,
181
+ "@thexjs/core": `^${coreVersion}`
182
+ };
183
+ const devDependencies = {
184
+ ...BASE_DEV_DEPENDENCIES,
185
+ "@thexjs/cli": `^${cliVersion}`
186
+ };
187
+ for (const feature of features) {
188
+ const meta = FEATURES.find((f) => f.id === feature);
183
189
  if (!meta) continue;
184
- const tag = meta.recommended ? dimText(" (recommended)") : "";
185
- console.log(` ${name.padEnd(8)} ${meta.description}${tag}`);
190
+ Object.assign(dependencies, meta.dependencies);
191
+ Object.assign(devDependencies, meta.devDependencies);
192
+ }
193
+ const pkg = {
194
+ name,
195
+ private: true,
196
+ type: "module",
197
+ scripts: {
198
+ dev: "x dev",
199
+ build: "x build",
200
+ start: "x start"
201
+ },
202
+ dependencies,
203
+ devDependencies
204
+ };
205
+ return `${JSON.stringify(pkg, null, 2)}
206
+ `;
207
+ }
208
+ function buildXConfig(features) {
209
+ const lines = [];
210
+ lines.push('import { defineConfig } from "@thexjs/core";');
211
+ lines.push("");
212
+ lines.push("export default defineConfig({");
213
+ lines.push(' pagesDir: "src/pages",');
214
+ lines.push(' layoutsDir: "src/layouts",');
215
+ lines.push(' apiDir: "src/api",');
216
+ if (features.includes("content")) {
217
+ lines.push(' contentDir: "content",');
186
218
  }
219
+ lines.push(" port: 3000,");
220
+ lines.push("});");
221
+ lines.push("");
222
+ return lines.join("\n");
187
223
  }
224
+ var FEATURE_SELECT_OPTIONS = FEATURES.map((feature) => ({
225
+ value: feature.id,
226
+ label: `${feature.label}${feature.requires ? ` (requires ${feature.requires.join(", ")})` : ""}`,
227
+ hint: feature.hint
228
+ }));
188
229
  async function main() {
189
- printBanner();
190
- const argv = process.argv.slice(2);
191
- const positional = argv.filter((a) => !a.startsWith("--"));
192
- const templateFlagIndex = argv.findIndex((a) => a === "--template" || a === "-t");
193
- let templateArg = templateFlagIndex !== -1 ? argv[templateFlagIndex + 1] : void 0;
194
- let projectName = positional[0];
230
+ const options = parseArgs(process.argv.slice(2));
231
+ const interactive = !options.projectName || options.features.length === 0;
232
+ intro("create thexjs-app");
233
+ let projectName = options.projectName;
234
+ let features = options.features;
195
235
  if (!projectName) {
196
- projectName = await prompt("Project name", "my-thexjs-app");
236
+ const input = await text({
237
+ message: "What should your project be called?",
238
+ placeholder: "my-thexjs-app",
239
+ defaultValue: "my-thexjs-app",
240
+ validate: (value) => {
241
+ if (!value || value.trim().length === 0) return "Project name is required.";
242
+ }
243
+ });
244
+ if (isCancel(input)) return abort("Cancelled.");
245
+ projectName = input;
197
246
  }
198
247
  const slug = slugify(projectName);
199
248
  const targetDir = resolve(process.cwd(), slug);
200
249
  if (existsSync(targetDir) && readdirSync(targetDir).length > 0) {
201
- console.error(`
202
- [create-thexjs-app] Directory "${slug}" already exists and is not empty.`);
203
- process.exit(1);
250
+ return abort(`Directory "${slug}" already exists and is not empty.`);
204
251
  }
205
- if (!templateArg || !TEMPLATES[templateArg]) {
206
- console.log("\n Available templates:\n");
207
- printTemplateList();
208
- console.log("");
209
- templateArg = await prompt(`Choose a template (${TEMPLATE_NAMES.join("/")})`, DEFAULT_TEMPLATE);
252
+ if (features.length === 0) {
253
+ const selected = await multiselect({
254
+ message: "Which features do you want?",
255
+ options: FEATURE_SELECT_OPTIONS,
256
+ required: false,
257
+ initialValues: FEATURES.filter((f) => f.default).map((f) => f.id)
258
+ });
259
+ if (isCancel(selected)) return abort("Cancelled.");
260
+ features = selected;
261
+ }
262
+ if (!features.includes("tailwind") && features.includes("shadcn")) {
263
+ features = ["tailwind", ...features.filter((f) => f !== "shadcn").sort()];
264
+ log.warn("shadcn/ui requires Tailwind \u2014 enabled Tailwind for you.");
265
+ }
266
+ if (interactive && options.install) {
267
+ const installOk = await confirm({
268
+ message: "Install dependencies and initialize a git repo?",
269
+ initialValue: true
270
+ });
271
+ if (isCancel(installOk)) return abort("Cancelled.");
272
+ if (!installOk) {
273
+ options.install = false;
274
+ options.git = false;
275
+ }
210
276
  }
211
- if (!TEMPLATES[templateArg]) {
212
- console.error(`
213
- [create-thexjs-app] Unknown template "${templateArg}".`);
214
- process.exit(1);
277
+ const spin = spinner();
278
+ spin.start(`Scaffolding "${slug}"`);
279
+ ensureDir(targetDir);
280
+ mergeTree(BASE_TEMPLATE, targetDir);
281
+ for (const feature of features) {
282
+ copyAddon(feature, targetDir);
215
283
  }
216
- const meta = TEMPLATES[templateArg];
217
- const templateDir = join(TEMPLATES_ROOT, templateArg);
218
- step(`Scaffolding "${slug}" from the "${templateArg}" template...`);
219
- mkdirSync(targetDir, { recursive: true });
220
- cpSync(templateDir, targetDir, { recursive: true });
221
- step("Resolving latest @thexjs package versions...");
284
+ spin.message("Resolving latest @thexjs versions");
222
285
  const coreVersion = await fetchLatestVersion("@thexjs/core") ?? FALLBACK_CORE_VERSION;
223
286
  const cliVersion = await fetchLatestVersion("@thexjs/cli") ?? FALLBACK_CORE_VERSION;
224
- const pkgJson = {
225
- name: slug,
226
- private: true,
227
- type: "module",
228
- scripts: {
229
- dev: "x dev",
230
- build: "x build",
231
- start: "x start"
232
- },
233
- dependencies: {
234
- "@thexjs/core": `^${coreVersion}`,
235
- ...meta.dependencies
236
- },
237
- devDependencies: {
238
- "@thexjs/cli": `^${cliVersion}`,
239
- ...meta.devDependencies
287
+ writeFileSync(
288
+ join(targetDir, "package.json"),
289
+ buildPackageJson(slug, features, coreVersion, cliVersion)
290
+ );
291
+ writeFileSync(join(targetDir, "x.config.ts"), buildXConfig(features));
292
+ spin.stop(`Created ${slug}/`);
293
+ if (options.git) {
294
+ const initSpin = spinner();
295
+ initSpin.start("Initializing git repository");
296
+ const result = spawnSync("git", ["init", "-q"], { cwd: targetDir, stdio: "ignore" });
297
+ if (result.status === 0) {
298
+ initSpin.stop("Git repository initialized");
299
+ } else {
300
+ initSpin.stop("Git could not be initialized (is git installed?)");
240
301
  }
241
- };
242
- writeFileSync(join(targetDir, "package.json"), `${JSON.stringify(pkgJson, null, 2)}
243
- `);
244
- success(`Created ${slug}/`);
245
- const hasBun = spawnSync("bun", ["--version"], { stdio: "ignore" }).status === 0;
246
- if (hasBun) {
247
- step("Installing dependencies with bun install...");
248
- const result = spawnSync("bun", ["install"], { cwd: targetDir, stdio: "inherit" });
302
+ }
303
+ let installed = false;
304
+ if (options.install) {
305
+ const hasBun = spawnSync("bun", ["--version"], { stdio: "ignore" }).status === 0;
306
+ if (hasBun) {
307
+ const installSpin = spinner();
308
+ installSpin.start("Installing dependencies (bun install)");
309
+ const result = spawnSync("bun", ["install"], { cwd: targetDir, stdio: "inherit" });
310
+ if (result.status === 0) {
311
+ installSpin.stop("Dependencies installed");
312
+ installed = true;
313
+ } else {
314
+ installSpin.stop("bun install failed \u2014 you can retry manually");
315
+ }
316
+ } else {
317
+ log.warn(
318
+ "Bun was not found on your PATH. Install it from https://bun.sh, then run `bun install` inside the project."
319
+ );
320
+ }
321
+ }
322
+ const summary = ["", `cd ${slug}`, !installed ? "bun install" : "", "bun run dev"].filter(Boolean).join("\n");
323
+ note(summary, "Next steps");
324
+ outro("Your x app is ready!");
325
+ if (options.runDev && installed) {
326
+ const devSpin = spinner();
327
+ devSpin.start("Starting development server");
328
+ const result = spawnSync("bun", ["run", "dev"], { cwd: targetDir, stdio: "inherit" });
249
329
  if (result.status !== 0) {
250
- console.warn("[create-thexjs-app] bun install failed \u2014 you can retry manually.");
330
+ devSpin.stop("Dev server exited");
251
331
  }
252
- } else {
253
- console.warn(
254
- "[create-thexjs-app] Bun was not found on your PATH. Install it from https://bun.sh, then run `bun install` inside the project \u2014 the x framework requires Bun to run."
255
- );
256
332
  }
257
- console.log("");
258
- dim("Done! Next steps:");
259
- console.log("");
260
- command(`cd ${slug}`);
261
- if (!hasBun) command("bun install");
262
- command("bun run dev");
263
- console.log("");
264
333
  }
265
334
  main().catch((err) => {
266
- console.error(err);
335
+ cancel(`Unexpected error: ${err}`);
267
336
  process.exit(1);
268
337
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-thexjs-app",
3
- "version": "0.1.4",
3
+ "version": "1.1.0",
4
4
  "description": "Scaffold a new x framework app (npm create thexjs-app@latest).",
5
5
  "keywords": [
6
6
  "react",
@@ -48,11 +48,15 @@
48
48
  },
49
49
  "scripts": {
50
50
  "build": "tsup src/index.ts --format esm --clean --target node18 --shims false --no-splitting",
51
+ "build:watch": "tsup src/index.ts --format esm --target node18 --shims false --no-splitting --watch",
51
52
  "prepublishOnly": "bun run build"
52
53
  },
53
54
  "engines": {
54
55
  "node": ">=18"
55
56
  },
57
+ "dependencies": {
58
+ "@clack/prompts": "^1.7.0"
59
+ },
56
60
  "devDependencies": {
57
61
  "@types/node": "^22.0.0",
58
62
  "tsup": "^8.3.0"
@@ -1,4 +1,3 @@
1
- import type { RouteProps } from "@thexjs/core";
2
1
  import { createSession, setSessionCookie } from "../../lib/auth";
3
2
 
4
3
  export async function POST(req: Request): Promise<Response> {
@@ -15,12 +14,11 @@ export async function POST(req: Request): Promise<Response> {
15
14
  }
16
15
 
17
16
  const session = createSession(username);
18
- const cookie = setSessionCookie(session.token);
19
17
  return new Response(JSON.stringify({ user: { username: session.username } }), {
20
18
  status: 200,
21
19
  headers: {
22
20
  "Content-Type": "application/json",
23
- "Set-Cookie": cookie,
21
+ "Set-Cookie": setSessionCookie(session.token),
24
22
  },
25
23
  });
26
24
  } catch (err) {
@@ -1,7 +1,11 @@
1
+ // Minimal demo auth backed by a local SQLite database.
2
+ //
3
+ // This is intentionally simple (plaintext "admin"/"admin" credentials, no
4
+ // password hashing, no session expiry). It exists to show the wiring for
5
+ // sessions + protected routes. Replace it with a real auth strategy
6
+ // (hashed passwords, OAuth, etc.) before shipping anything production.
7
+
1
8
  import type { Database } from "bun:sqlite";
2
- // DEMO ONLY: hardcoded admin/admin credentials, plaintext password comparison,
3
- // no session expiry. This auth is a placeholder for demos — replace with real
4
- // credential storage (hashed passwords) before shipping anything production.
5
9
  import { randomUUID } from "node:crypto";
6
10
  import { mkdirSync } from "node:fs";
7
11
  import { dirname, join } from "node:path";
@@ -29,12 +33,12 @@ function getDb(): Database {
29
33
  }
30
34
 
31
35
  export function createSession(username: string): Session {
32
- const db = getDb();
36
+ const database = getDb();
33
37
  const id = randomUUID();
34
38
  const token = randomUUID();
35
39
  const userId = `user_${randomUUID().slice(0, 8)}`;
36
40
 
37
- db.run("INSERT INTO sessions (id, token, user_id, username) VALUES (?1, ?2, ?3, ?4)", [
41
+ database.run("INSERT INTO sessions (id, token, user_id, username) VALUES (?1, ?2, ?3, ?4)", [
38
42
  id,
39
43
  token,
40
44
  userId,
@@ -46,8 +50,8 @@ export function createSession(username: string): Session {
46
50
 
47
51
  export function getSession(token: string | undefined): Session | null {
48
52
  if (!token) return null;
49
- const db = getDb();
50
- const row = db
53
+ const database = getDb();
54
+ const row = database
51
55
  .prepare("SELECT id, token, user_id, username FROM sessions WHERE token = ?1")
52
56
  .get(token) as { id: string; token: string; user_id: string; username: string } | null;
53
57
  if (!row) return null;
@@ -55,8 +59,8 @@ export function getSession(token: string | undefined): Session | null {
55
59
  }
56
60
 
57
61
  export function deleteSession(token: string): void {
58
- const db = getDb();
59
- db.run("DELETE FROM sessions WHERE token = ?1", [token] as unknown as string[]);
62
+ const database = getDb();
63
+ database.run("DELETE FROM sessions WHERE token = ?1", [token] as unknown as string[]);
60
64
  }
61
65
 
62
66
  export function parseSessionCookie(cookieHeader: string | null): string | undefined {
@@ -3,7 +3,5 @@ CREATE TABLE IF NOT EXISTS sessions (
3
3
  token TEXT NOT NULL UNIQUE,
4
4
  user_id TEXT NOT NULL,
5
5
  username TEXT NOT NULL,
6
- created_at TEXT DEFAULT (datetime('now'))
6
+ created_at TEXT NOT NULL DEFAULT (datetime('now'))
7
7
  );
8
-
9
- CREATE INDEX IF NOT EXISTS idx_sessions_token ON sessions(token);
@@ -0,0 +1,39 @@
1
+ export const metadata = {
2
+ title: "Dashboard",
3
+ };
4
+
5
+ export default function Dashboard() {
6
+ return (
7
+ <main style={{ maxWidth: 680, margin: "0 auto", padding: "4rem 1.5rem" }}>
8
+ <h1 style={{ fontSize: "2rem", marginBottom: "0.5rem" }}>Dashboard</h1>
9
+ <p style={{ color: "#64748b", marginBottom: "2rem" }}>
10
+ You're signed in. This page is protected by <code>src/pages/dashboard/_middleware.ts</code>.
11
+ </p>
12
+ <form
13
+ method="POST"
14
+ action="/api/auth/logout"
15
+ onSubmit={(e) => {
16
+ e.preventDefault();
17
+ fetch("/api/auth/logout", { method: "POST" }).then(() => {
18
+ window.location.href = "/login";
19
+ });
20
+ }}
21
+ >
22
+ <button type="submit" style={btn}>
23
+ Sign out
24
+ </button>
25
+ </form>
26
+ </main>
27
+ );
28
+ }
29
+
30
+ const btn: React.CSSProperties = {
31
+ padding: "0.6rem 1.1rem",
32
+ background: "#0f172a",
33
+ color: "#fff",
34
+ border: "none",
35
+ borderRadius: 8,
36
+ fontSize: "0.9rem",
37
+ fontWeight: 600,
38
+ cursor: "pointer",
39
+ };