create-thexjs-app 1.2.1 → 1.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,18 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/index.ts
4
- import { spawnSync } from "child_process";
5
- import {
6
- cpSync,
7
- existsSync,
8
- mkdirSync,
9
- readdirSync,
10
- renameSync,
11
- statSync,
12
- writeFileSync
13
- } from "fs";
14
- import { dirname, join, resolve } from "path";
15
- import { fileURLToPath } from "url";
4
+ import { spawnSync as spawnSync2 } from "child_process";
5
+ import { cpSync as cpSync2, existsSync as existsSync2, readdirSync as readdirSync2, renameSync, rmSync, writeFileSync } from "fs";
6
+ import { join as join2, resolve } from "path";
16
7
  import {
17
8
  cancel,
18
9
  confirm,
@@ -26,7 +17,32 @@ import {
26
17
  text
27
18
  } from "@clack/prompts";
28
19
 
20
+ // src/git.ts
21
+ import { spawnSync } from "child_process";
22
+ var GENERIC_FAILURE = "Git could not be initialized (is git installed?)";
23
+ function initGitRepo(cwd, env) {
24
+ const result = spawnSync("git", ["init", "-q", "-b", "main"], {
25
+ cwd,
26
+ stdio: ["ignore", "ignore", "pipe"],
27
+ env: env ?? process.env
28
+ });
29
+ if (result.status === 0) {
30
+ return { ok: true, message: "Git repository initialized on main" };
31
+ }
32
+ const stderr = result.stderr?.toString().trim() ?? "";
33
+ const firstLine = stderr.split("\n").map((line) => line.trim()).find((line) => line.length > 0) ?? "";
34
+ if (!firstLine) return { ok: false, message: GENERIC_FAILURE };
35
+ return { ok: false, message: `Git could not be initialized: ${firstLine}` };
36
+ }
37
+
29
38
  // src/templates.ts
39
+ import { cpSync, existsSync, mkdirSync, readdirSync, statSync } from "fs";
40
+ import { dirname, join } from "path";
41
+ import { fileURLToPath } from "url";
42
+ var __dirname = dirname(fileURLToPath(import.meta.url));
43
+ var TEMPLATES_ROOT = join(__dirname, "..", "templates");
44
+ var BASE_TEMPLATE = join(TEMPLATES_ROOT, "base");
45
+ var ADDONS_ROOT = join(TEMPLATES_ROOT, "addons");
30
46
  var FEATURES = [
31
47
  {
32
48
  id: "tailwind",
@@ -92,6 +108,52 @@ var BASE_DEV_DEPENDENCIES = {
92
108
  "@types/react-dom": "^19.1.0",
93
109
  typescript: "^5.8.0"
94
110
  };
111
+ function featureLabel(id) {
112
+ return FEATURES.find((f) => f.id === id)?.label ?? id;
113
+ }
114
+ function normalizeFeatures(selected) {
115
+ const set = new Set(selected);
116
+ const autoEnabled = [];
117
+ let changed = true;
118
+ while (changed) {
119
+ changed = false;
120
+ for (const feature of FEATURES) {
121
+ if (!set.has(feature.id)) continue;
122
+ for (const req of feature.requires ?? []) {
123
+ if (set.has(req)) continue;
124
+ set.add(req);
125
+ autoEnabled.push({ added: req, because: feature.id });
126
+ changed = true;
127
+ }
128
+ }
129
+ }
130
+ const order = new Map(FEATURES.map((f, i) => [f.id, i]));
131
+ const features = [...set].sort(
132
+ (a, b) => (order.get(a) ?? Number.MAX_SAFE_INTEGER) - (order.get(b) ?? Number.MAX_SAFE_INTEGER)
133
+ );
134
+ return { features, autoEnabled };
135
+ }
136
+ function ensureDir(path) {
137
+ if (!existsSync(path)) mkdirSync(path, { recursive: true });
138
+ }
139
+ function mergeTree(src, dest) {
140
+ ensureDir(dest);
141
+ for (const entry of readdirSync(src)) {
142
+ const from = join(src, entry);
143
+ const to = join(dest, entry);
144
+ const stat = statSync(from);
145
+ if (stat.isDirectory()) {
146
+ mergeTree(from, to);
147
+ } else {
148
+ cpSync(from, to);
149
+ }
150
+ }
151
+ }
152
+ function copyAddon(addon, targetDir) {
153
+ const src = join(ADDONS_ROOT, addon);
154
+ if (!existsSync(src)) return;
155
+ mergeTree(src, targetDir);
156
+ }
95
157
 
96
158
  // src/package-json.ts
97
159
  var FALLBACK_CORE_VERSION = "1.6.0";
@@ -157,10 +219,6 @@ function abort(message) {
157
219
  cancel(message);
158
220
  process.exit(1);
159
221
  }
160
- var __dirname = dirname(fileURLToPath(import.meta.url));
161
- var TEMPLATES_ROOT = join(__dirname, "..", "templates");
162
- var BASE_TEMPLATE = join(TEMPLATES_ROOT, "base");
163
- var ADDONS_ROOT = join(TEMPLATES_ROOT, "addons");
164
222
  function parseArgs(argv) {
165
223
  const options = {
166
224
  features: [],
@@ -217,33 +275,30 @@ function parseArgs(argv) {
217
275
  function slugify(name) {
218
276
  return name.trim().toLowerCase().replace(/[^a-z0-9-]+/g, "-").replace(/^-+|-+$/g, "") || "thexjs-app";
219
277
  }
220
- function ensureDir(path) {
221
- if (!existsSync(path)) mkdirSync(path, { recursive: true });
278
+ function finalizeGitignore(targetDir) {
279
+ const from = join2(targetDir, "_gitignore");
280
+ if (!existsSync2(from)) return;
281
+ const to = join2(targetDir, ".gitignore");
282
+ renameSync(from, to);
222
283
  }
223
- function mergeTree(src, dest) {
224
- ensureDir(dest);
225
- for (const entry of readdirSync(src)) {
226
- const from = join(src, entry);
227
- const to = join(dest, entry);
228
- const stat = statSync(from);
229
- if (stat.isDirectory()) {
230
- mergeTree(from, to);
284
+ function finalizeAgentConfigs(targetDir) {
285
+ const mcpFrom = join2(targetDir, "_mcp.json");
286
+ if (existsSync2(mcpFrom)) {
287
+ renameSync(mcpFrom, join2(targetDir, ".mcp.json"));
288
+ }
289
+ const cursorFrom = join2(targetDir, "_cursor");
290
+ if (existsSync2(cursorFrom)) {
291
+ const cursorTo = join2(targetDir, ".cursor");
292
+ if (!existsSync2(cursorTo)) {
293
+ renameSync(cursorFrom, cursorTo);
231
294
  } else {
232
- cpSync(from, to);
295
+ for (const entry of readdirSync2(cursorFrom)) {
296
+ cpSync2(join2(cursorFrom, entry), join2(cursorTo, entry));
297
+ }
298
+ rmSync(cursorFrom, { recursive: true, force: true });
233
299
  }
234
300
  }
235
301
  }
236
- function copyAddon(addon, targetDir) {
237
- const src = join(ADDONS_ROOT, addon);
238
- if (!existsSync(src)) return;
239
- mergeTree(src, targetDir);
240
- }
241
- function finalizeGitignore(targetDir) {
242
- const from = join(targetDir, "_gitignore");
243
- if (!existsSync(from)) return;
244
- const to = join(targetDir, ".gitignore");
245
- renameSync(from, to);
246
- }
247
302
  function buildXConfig(features) {
248
303
  const lines = [];
249
304
  lines.push('import { defineConfig } from "@thexjs/core";');
@@ -285,7 +340,7 @@ async function main() {
285
340
  }
286
341
  const slug = slugify(projectName);
287
342
  const targetDir = resolve(process.cwd(), slug);
288
- if (existsSync(targetDir) && readdirSync(targetDir).length > 0) {
343
+ if (existsSync2(targetDir) && readdirSync2(targetDir).length > 0) {
289
344
  return abort(`Directory "${slug}" already exists and is not empty.`);
290
345
  }
291
346
  if (features.length === 0) {
@@ -298,9 +353,12 @@ async function main() {
298
353
  if (isCancel(selected)) return abort("Cancelled.");
299
354
  features = selected;
300
355
  }
301
- if (!features.includes("tailwind") && features.includes("shadcn")) {
302
- features = ["tailwind", ...features.filter((f) => f !== "shadcn").sort()];
303
- log.warn("shadcn/ui requires Tailwind \u2014 enabled Tailwind for you.");
356
+ const { features: normalized, autoEnabled } = normalizeFeatures(features);
357
+ features = normalized;
358
+ for (const { added, because } of autoEnabled) {
359
+ log.warn(
360
+ `${featureLabel(because)} requires ${featureLabel(added)} \u2014 enabled ${featureLabel(added)} for you.`
361
+ );
304
362
  }
305
363
  if (interactive && options.install) {
306
364
  const installOk = await confirm({
@@ -318,37 +376,36 @@ async function main() {
318
376
  ensureDir(targetDir);
319
377
  mergeTree(BASE_TEMPLATE, targetDir);
320
378
  finalizeGitignore(targetDir);
379
+ finalizeAgentConfigs(targetDir);
321
380
  for (const feature of features) {
322
381
  copyAddon(feature, targetDir);
323
382
  }
324
383
  spin.message("Resolving latest @thexjs versions");
325
384
  const { coreVersion, cliVersion, hooksVersion } = await resolveVersions(features);
326
385
  writeFileSync(
327
- join(targetDir, "package.json"),
386
+ join2(targetDir, "package.json"),
328
387
  buildPackageJson(slug, features, coreVersion, cliVersion, hooksVersion)
329
388
  );
330
- writeFileSync(join(targetDir, "x.config.ts"), buildXConfig(features));
389
+ writeFileSync(join2(targetDir, "x.config.ts"), buildXConfig(features));
331
390
  spin.stop(`Created ${slug}/`);
332
391
  if (options.git) {
333
392
  const initSpin = spinner();
334
393
  initSpin.start("Initializing git repository (main branch)");
335
- const result = spawnSync("git", ["init", "-q", "-b", "main"], {
336
- cwd: targetDir,
337
- stdio: "ignore"
338
- });
339
- if (result.status === 0) {
340
- initSpin.stop("Git repository initialized on main");
394
+ const result = initGitRepo(targetDir);
395
+ if (result.ok) {
396
+ initSpin.stop(result.message);
341
397
  } else {
342
- initSpin.stop("Git could not be initialized (is git installed?)");
398
+ initSpin.stop("Git repository not initialized");
399
+ log.warn(result.message);
343
400
  }
344
401
  }
345
402
  let installed = false;
346
403
  if (options.install) {
347
- const hasBun = spawnSync("bun", ["--version"], { stdio: "ignore" }).status === 0;
404
+ const hasBun = spawnSync2("bun", ["--version"], { stdio: "ignore" }).status === 0;
348
405
  if (hasBun) {
349
406
  const installSpin = spinner();
350
407
  installSpin.start("Installing dependencies (bun install)");
351
- const result = spawnSync("bun", ["install"], { cwd: targetDir, stdio: "inherit" });
408
+ const result = spawnSync2("bun", ["install"], { cwd: targetDir, stdio: "inherit" });
352
409
  if (result.status === 0) {
353
410
  installSpin.stop("Dependencies installed");
354
411
  installed = true;
@@ -367,7 +424,7 @@ async function main() {
367
424
  if (options.runDev && installed) {
368
425
  const devSpin = spinner();
369
426
  devSpin.start("Starting development server");
370
- const result = spawnSync("bun", ["run", "dev"], { cwd: targetDir, stdio: "inherit" });
427
+ const result = spawnSync2("bun", ["run", "dev"], { cwd: targetDir, stdio: "inherit" });
371
428
  if (result.status !== 0) {
372
429
  devSpin.stop("Dev server exited");
373
430
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-thexjs-app",
3
- "version": "1.2.1",
3
+ "version": "1.2.3",
4
4
  "description": "Scaffold a new x framework app (npm create thexjs-app@latest).",
5
5
  "keywords": [
6
6
  "react",
@@ -63,7 +63,7 @@
63
63
  "@clack/prompts": "^1.7.0"
64
64
  },
65
65
  "devDependencies": {
66
- "@types/node": "^26.2.0",
66
+ "@types/node": "^26.3.0",
67
67
  "tsup": "^8.3.0"
68
68
  }
69
69
  }
@@ -0,0 +1,103 @@
1
+ # AGENTS.md
2
+
3
+ This project is built with **x**, a full-stack React framework on Bun. It
4
+ looks similar to Next.js / Remix / Astro / TanStack Start in places but is
5
+ NOT any of them — several conventions below are different on purpose.
6
+
7
+ **This project also ships an MCP server** (`@thexjs/mcp`, wired up in
8
+ `.mcp.json` / `.cursor/mcp.json`). If you're an agent with MCP tool access,
9
+ call `list_topics` / `get_docs` / `scaffold_file` from the `thexjs` server
10
+ before writing framework code — it returns grounded docs and ready-to-paste
11
+ snippets instead of you guessing from Next.js/Remix training data. This file
12
+ is the fallback for agents without MCP access.
13
+
14
+ ## Routing
15
+
16
+ Files under `src/pages/` are routes:
17
+
18
+ ```text
19
+ pages/index.tsx -> /
20
+ pages/about.tsx -> /about
21
+ pages/blog/[slug].tsx -> /blog/:slug
22
+ pages/_404.tsx -> 404 page
23
+ pages/_layout.tsx -> layout wrapping this folder + children
24
+ pages/_middleware.ts -> middleware for this folder + children
25
+ ```
26
+
27
+ The underscore prefix is load-bearing — there's no `app/` directory and no
28
+ `layout.tsx`/`page.tsx` (App Router) naming.
29
+
30
+ ## Loaders
31
+
32
+ ```tsx
33
+ import type { LoaderArgs, RouteProps } from "@thexjs/core";
34
+
35
+ export async function loader({ params, request }: LoaderArgs) {
36
+ return { title: "..." };
37
+ }
38
+
39
+ export default function Page({ loaderData }: RouteProps) {
40
+ return <h1>{String(loaderData?.title)}</h1>;
41
+ }
42
+ ```
43
+
44
+ Args are `{ params, request }` — not `{ context }`, and not a route-tree
45
+ config object. Return a plain object (becomes `loaderData`) or a `Response`
46
+ for redirects/status.
47
+
48
+ ## Static rendering
49
+
50
+ `export const mode = "static";` prerenders at build time. Default is SSR on
51
+ every request. `export const revalidate = <seconds>;` for ISR — only
52
+ honored on static-mode pages (ignored on the default SSR path).
53
+
54
+ ## API routes
55
+
56
+ `src/api/*.ts` exports Fetch API handlers:
57
+
58
+ ```ts
59
+ export async function GET(req: Request) {
60
+ return Response.json({ ok: true });
61
+ }
62
+ ```
63
+
64
+ ## Server functions (actions) — read this before writing one
65
+
66
+ `src/actions/*.ts` exports plain async functions. **No `"use server"`
67
+ directive.** Import and call them directly from a component; the client
68
+ import is rewritten to a fetch wrapper at build time automatically, and the
69
+ real function body (db calls, secrets) never reaches the client bundle:
70
+
71
+ ```ts
72
+ // src/actions/greet.ts
73
+ export async function greet(name: string) {
74
+ return `Hello, ${name}!`;
75
+ }
76
+ ```
77
+
78
+ ```tsx
79
+ import { greet } from "../actions/greet";
80
+ await greet("world");
81
+ ```
82
+
83
+ ## Env vars
84
+
85
+ Only `THEXJS_PUBLIC_*` prefixed vars reach the browser (enforced at build
86
+ time). NOT `NEXT_PUBLIC_` / `VITE_`. Everything else is server-only.
87
+
88
+ ## Config
89
+
90
+ `x.config.ts` at the project root, all fields optional (`pagesDir`,
91
+ `layoutsDir`, `apiDir`, `actionsDir`, `contentDir`, `port`).
92
+
93
+ ## CLI
94
+
95
+ ```bash
96
+ bun run dev # x dev
97
+ bun run build # x build -> .x/
98
+ bun run start # x start, serves .x/
99
+ ```
100
+
101
+ ## Full docs
102
+
103
+ https://thexjs.vercel.app/docs · https://thexjs.vercel.app/llms.txt
@@ -0,0 +1,3 @@
1
+ See [AGENTS.md](./AGENTS.md) for x framework conventions, and use the
2
+ `thexjs` MCP server (configured in `.mcp.json`) for grounded docs and
3
+ scaffolding before writing routing/loader/action code.
@@ -0,0 +1,8 @@
1
+ {
2
+ "mcpServers": {
3
+ "thexjs": {
4
+ "command": "bunx",
5
+ "args": ["@thexjs/mcp"]
6
+ }
7
+ }
8
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "mcpServers": {
3
+ "thexjs": {
4
+ "command": "bunx",
5
+ "args": ["@thexjs/mcp"]
6
+ }
7
+ }
8
+ }