create-thexjs-app 1.2.0 → 1.2.2

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,18 +108,117 @@ 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
+ }
157
+
158
+ // src/package-json.ts
159
+ var FALLBACK_CORE_VERSION = "1.6.0";
160
+ var FALLBACK_CLI_VERSION = "1.1.2";
161
+ var FALLBACK_HOOKS_VERSION = "0.2.0";
162
+ async function resolveVersions(features, fetchVersion = fetchLatestVersion) {
163
+ const coreVersion = await fetchVersion("@thexjs/core") ?? FALLBACK_CORE_VERSION;
164
+ const cliVersion = await fetchVersion("@thexjs/cli") ?? FALLBACK_CLI_VERSION;
165
+ const hooksVersion = features.includes("hooks") ? await fetchVersion("@thexjs/hooks") ?? FALLBACK_HOOKS_VERSION : void 0;
166
+ return { coreVersion, cliVersion, ...hooksVersion !== void 0 ? { hooksVersion } : {} };
167
+ }
168
+ async function fetchLatestVersion(pkg) {
169
+ try {
170
+ const controller = new AbortController();
171
+ const timeout = setTimeout(() => controller.abort(), 3e3);
172
+ const res = await fetch(`https://registry.npmjs.org/${pkg}/latest`, {
173
+ signal: controller.signal
174
+ });
175
+ clearTimeout(timeout);
176
+ if (!res.ok) return null;
177
+ const data = await res.json();
178
+ return data.version ?? null;
179
+ } catch {
180
+ return null;
181
+ }
182
+ }
183
+ function buildPackageJson(name, features, coreVersion, cliVersion, hooksVersion) {
184
+ const dependencies = {
185
+ ...BASE_DEPENDENCIES,
186
+ "@thexjs/core": `^${coreVersion}`
187
+ };
188
+ const devDependencies = {
189
+ ...BASE_DEV_DEPENDENCIES,
190
+ "@thexjs/cli": `^${cliVersion}`
191
+ };
192
+ if (features.includes("hooks") && hooksVersion) {
193
+ dependencies["@thexjs/hooks"] = `^${hooksVersion}`;
194
+ }
195
+ for (const feature of features) {
196
+ const meta = FEATURES.find((f) => f.id === feature);
197
+ if (!meta) continue;
198
+ Object.assign(dependencies, meta.dependencies);
199
+ Object.assign(devDependencies, meta.devDependencies);
200
+ }
201
+ const pkg = {
202
+ name,
203
+ private: true,
204
+ type: "module",
205
+ scripts: {
206
+ dev: "x dev",
207
+ build: "x build",
208
+ start: "x start"
209
+ },
210
+ dependencies,
211
+ devDependencies
212
+ };
213
+ return `${JSON.stringify(pkg, null, 2)}
214
+ `;
215
+ }
95
216
 
96
217
  // src/index.ts
97
218
  function abort(message) {
98
219
  cancel(message);
99
220
  process.exit(1);
100
221
  }
101
- var __dirname = dirname(fileURLToPath(import.meta.url));
102
- var TEMPLATES_ROOT = join(__dirname, "..", "templates");
103
- var BASE_TEMPLATE = join(TEMPLATES_ROOT, "base");
104
- var ADDONS_ROOT = join(TEMPLATES_ROOT, "addons");
105
- var FALLBACK_CORE_VERSION = "1.2.2";
106
- var FALLBACK_HOOKS_VERSION = "0.1.0";
107
222
  function parseArgs(argv) {
108
223
  const options = {
109
224
  features: [],
@@ -160,80 +275,29 @@ function parseArgs(argv) {
160
275
  function slugify(name) {
161
276
  return name.trim().toLowerCase().replace(/[^a-z0-9-]+/g, "-").replace(/^-+|-+$/g, "") || "thexjs-app";
162
277
  }
163
- async function fetchLatestVersion(pkg) {
164
- try {
165
- const controller = new AbortController();
166
- const timeout = setTimeout(() => controller.abort(), 3e3);
167
- const res = await fetch(`https://registry.npmjs.org/${pkg}/latest`, {
168
- signal: controller.signal
169
- });
170
- clearTimeout(timeout);
171
- if (!res.ok) return null;
172
- const data = await res.json();
173
- return data.version ?? null;
174
- } catch {
175
- return null;
176
- }
177
- }
178
- function ensureDir(path) {
179
- if (!existsSync(path)) mkdirSync(path, { recursive: true });
180
- }
181
- function mergeTree(src, dest) {
182
- ensureDir(dest);
183
- for (const entry of readdirSync(src)) {
184
- const from = join(src, entry);
185
- const to = join(dest, entry);
186
- const stat = statSync(from);
187
- if (stat.isDirectory()) {
188
- mergeTree(from, to);
189
- } else {
190
- cpSync(from, to);
191
- }
192
- }
193
- }
194
- function copyAddon(addon, targetDir) {
195
- const src = join(ADDONS_ROOT, addon);
196
- if (!existsSync(src)) return;
197
- mergeTree(src, targetDir);
198
- }
199
278
  function finalizeGitignore(targetDir) {
200
- const from = join(targetDir, "_gitignore");
201
- if (!existsSync(from)) return;
202
- const to = join(targetDir, ".gitignore");
279
+ const from = join2(targetDir, "_gitignore");
280
+ if (!existsSync2(from)) return;
281
+ const to = join2(targetDir, ".gitignore");
203
282
  renameSync(from, to);
204
283
  }
205
- function buildPackageJson(name, features, coreVersion, cliVersion, hooksVersion) {
206
- const dependencies = {
207
- ...BASE_DEPENDENCIES,
208
- "@thexjs/core": `^${coreVersion}`
209
- };
210
- const devDependencies = {
211
- ...BASE_DEV_DEPENDENCIES,
212
- "@thexjs/cli": `^${cliVersion}`
213
- };
214
- if (features.includes("hooks") && hooksVersion) {
215
- dependencies["@thexjs/hooks"] = `^${hooksVersion}`;
284
+ function finalizeAgentConfigs(targetDir) {
285
+ const mcpFrom = join2(targetDir, "_mcp.json");
286
+ if (existsSync2(mcpFrom)) {
287
+ renameSync(mcpFrom, join2(targetDir, ".mcp.json"));
216
288
  }
217
- for (const feature of features) {
218
- const meta = FEATURES.find((f) => f.id === feature);
219
- if (!meta) continue;
220
- Object.assign(dependencies, meta.dependencies);
221
- Object.assign(devDependencies, meta.devDependencies);
289
+ const cursorFrom = join2(targetDir, "_cursor");
290
+ if (existsSync2(cursorFrom)) {
291
+ const cursorTo = join2(targetDir, ".cursor");
292
+ if (!existsSync2(cursorTo)) {
293
+ renameSync(cursorFrom, cursorTo);
294
+ } else {
295
+ for (const entry of readdirSync2(cursorFrom)) {
296
+ cpSync2(join2(cursorFrom, entry), join2(cursorTo, entry));
297
+ }
298
+ rmSync(cursorFrom, { recursive: true, force: true });
299
+ }
222
300
  }
223
- const pkg = {
224
- name,
225
- private: true,
226
- type: "module",
227
- scripts: {
228
- dev: "x dev",
229
- build: "x build",
230
- start: "x start"
231
- },
232
- dependencies,
233
- devDependencies
234
- };
235
- return `${JSON.stringify(pkg, null, 2)}
236
- `;
237
301
  }
238
302
  function buildXConfig(features) {
239
303
  const lines = [];
@@ -276,7 +340,7 @@ async function main() {
276
340
  }
277
341
  const slug = slugify(projectName);
278
342
  const targetDir = resolve(process.cwd(), slug);
279
- if (existsSync(targetDir) && readdirSync(targetDir).length > 0) {
343
+ if (existsSync2(targetDir) && readdirSync2(targetDir).length > 0) {
280
344
  return abort(`Directory "${slug}" already exists and is not empty.`);
281
345
  }
282
346
  if (features.length === 0) {
@@ -289,9 +353,12 @@ async function main() {
289
353
  if (isCancel(selected)) return abort("Cancelled.");
290
354
  features = selected;
291
355
  }
292
- if (!features.includes("tailwind") && features.includes("shadcn")) {
293
- features = ["tailwind", ...features.filter((f) => f !== "shadcn").sort()];
294
- 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
+ );
295
362
  }
296
363
  if (interactive && options.install) {
297
364
  const installOk = await confirm({
@@ -309,39 +376,36 @@ async function main() {
309
376
  ensureDir(targetDir);
310
377
  mergeTree(BASE_TEMPLATE, targetDir);
311
378
  finalizeGitignore(targetDir);
379
+ finalizeAgentConfigs(targetDir);
312
380
  for (const feature of features) {
313
381
  copyAddon(feature, targetDir);
314
382
  }
315
383
  spin.message("Resolving latest @thexjs versions");
316
- const coreVersion = await fetchLatestVersion("@thexjs/core") ?? FALLBACK_CORE_VERSION;
317
- const cliVersion = await fetchLatestVersion("@thexjs/cli") ?? FALLBACK_CORE_VERSION;
318
- const hooksVersion = features.includes("hooks") ? await fetchLatestVersion("@thexjs/hooks") ?? FALLBACK_HOOKS_VERSION : void 0;
384
+ const { coreVersion, cliVersion, hooksVersion } = await resolveVersions(features);
319
385
  writeFileSync(
320
- join(targetDir, "package.json"),
386
+ join2(targetDir, "package.json"),
321
387
  buildPackageJson(slug, features, coreVersion, cliVersion, hooksVersion)
322
388
  );
323
- writeFileSync(join(targetDir, "x.config.ts"), buildXConfig(features));
389
+ writeFileSync(join2(targetDir, "x.config.ts"), buildXConfig(features));
324
390
  spin.stop(`Created ${slug}/`);
325
391
  if (options.git) {
326
392
  const initSpin = spinner();
327
393
  initSpin.start("Initializing git repository (main branch)");
328
- const result = spawnSync("git", ["init", "-q", "-b", "main"], {
329
- cwd: targetDir,
330
- stdio: "ignore"
331
- });
332
- if (result.status === 0) {
333
- initSpin.stop("Git repository initialized on main");
394
+ const result = initGitRepo(targetDir);
395
+ if (result.ok) {
396
+ initSpin.stop(result.message);
334
397
  } else {
335
- initSpin.stop("Git could not be initialized (is git installed?)");
398
+ initSpin.stop("Git repository not initialized");
399
+ log.warn(result.message);
336
400
  }
337
401
  }
338
402
  let installed = false;
339
403
  if (options.install) {
340
- const hasBun = spawnSync("bun", ["--version"], { stdio: "ignore" }).status === 0;
404
+ const hasBun = spawnSync2("bun", ["--version"], { stdio: "ignore" }).status === 0;
341
405
  if (hasBun) {
342
406
  const installSpin = spinner();
343
407
  installSpin.start("Installing dependencies (bun install)");
344
- const result = spawnSync("bun", ["install"], { cwd: targetDir, stdio: "inherit" });
408
+ const result = spawnSync2("bun", ["install"], { cwd: targetDir, stdio: "inherit" });
345
409
  if (result.status === 0) {
346
410
  installSpin.stop("Dependencies installed");
347
411
  installed = true;
@@ -360,7 +424,7 @@ async function main() {
360
424
  if (options.runDev && installed) {
361
425
  const devSpin = spinner();
362
426
  devSpin.start("Starting development server");
363
- const result = spawnSync("bun", ["run", "dev"], { cwd: targetDir, stdio: "inherit" });
427
+ const result = spawnSync2("bun", ["run", "dev"], { cwd: targetDir, stdio: "inherit" });
364
428
  if (result.status !== 0) {
365
429
  devSpin.stop("Dev server exited");
366
430
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-thexjs-app",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "description": "Scaffold a new x framework app (npm create thexjs-app@latest).",
5
5
  "keywords": [
6
6
  "react",
@@ -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
+ }