create-thexjs-app 1.1.3 → 1.2.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.
- package/README.md +3 -1
- package/dist/index.js +72 -49
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -27,7 +27,7 @@ bun create thexjs-app@latest
|
|
|
27
27
|
You'll be guided through interactive prompts:
|
|
28
28
|
|
|
29
29
|
- **Project name** — e.g. `my-app`
|
|
30
|
-
- **Features** — choose from Tailwind CSS, shadcn/ui, Auth,
|
|
30
|
+
- **Features** — choose from Tailwind CSS, shadcn/ui, Auth, Content collections, and Hooks
|
|
31
31
|
- **Install & git** — confirm dependency install and `git init`
|
|
32
32
|
|
|
33
33
|
```bash
|
|
@@ -49,6 +49,7 @@ selected at prompt time (or via CLI flags).
|
|
|
49
49
|
| **shadcn/ui** | Accessible React components in `src/components/ui` (requires Tailwind) |
|
|
50
50
|
| **Auth** | SQLite-backed demo sessions, `/login` and a protected `/dashboard` with middleware |
|
|
51
51
|
| **Content** | Markdown/MDX with frontmatter in `content/`, auto-routed and indexed on `/blog` |
|
|
52
|
+
| **Hooks** | `@thexjs/hooks` dependency — SSR-safe React hooks (debounce, media query, localStorage, forms, server actions) |
|
|
52
53
|
|
|
53
54
|
Enabling **shadcn/ui** automatically enables **Tailwind CSS**.
|
|
54
55
|
|
|
@@ -70,6 +71,7 @@ bun create thexjs-app@latest my-app --tailwind --auth --content --shadcn
|
|
|
70
71
|
| `--shadcn` | Include shadcn/ui (implies `--tailwind`) |
|
|
71
72
|
| `--auth` | Include demo auth |
|
|
72
73
|
| `--content` | Include content collections |
|
|
74
|
+
| `--hooks` | Include the `@thexjs/hooks` package |
|
|
73
75
|
| `--no-install` | Skip `bun install` |
|
|
74
76
|
| `--no-git` | Skip `git init` |
|
|
75
77
|
| `--dev` | Start the dev server after install |
|
package/dist/index.js
CHANGED
|
@@ -72,6 +72,14 @@ var FEATURES = [
|
|
|
72
72
|
default: false,
|
|
73
73
|
dependencies: {},
|
|
74
74
|
devDependencies: {}
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
id: "hooks",
|
|
78
|
+
label: "Hooks (@thexjs/hooks)",
|
|
79
|
+
hint: "SSR-safe React hooks: debounce, media query, localStorage, forms, server actions",
|
|
80
|
+
default: false,
|
|
81
|
+
dependencies: {},
|
|
82
|
+
devDependencies: {}
|
|
75
83
|
}
|
|
76
84
|
];
|
|
77
85
|
var BASE_DEPENDENCIES = {
|
|
@@ -85,6 +93,65 @@ var BASE_DEV_DEPENDENCIES = {
|
|
|
85
93
|
typescript: "^5.8.0"
|
|
86
94
|
};
|
|
87
95
|
|
|
96
|
+
// src/package-json.ts
|
|
97
|
+
var FALLBACK_CORE_VERSION = "1.6.0";
|
|
98
|
+
var FALLBACK_CLI_VERSION = "1.1.2";
|
|
99
|
+
var FALLBACK_HOOKS_VERSION = "0.2.0";
|
|
100
|
+
async function resolveVersions(features, fetchVersion = fetchLatestVersion) {
|
|
101
|
+
const coreVersion = await fetchVersion("@thexjs/core") ?? FALLBACK_CORE_VERSION;
|
|
102
|
+
const cliVersion = await fetchVersion("@thexjs/cli") ?? FALLBACK_CLI_VERSION;
|
|
103
|
+
const hooksVersion = features.includes("hooks") ? await fetchVersion("@thexjs/hooks") ?? FALLBACK_HOOKS_VERSION : void 0;
|
|
104
|
+
return { coreVersion, cliVersion, ...hooksVersion !== void 0 ? { hooksVersion } : {} };
|
|
105
|
+
}
|
|
106
|
+
async function fetchLatestVersion(pkg) {
|
|
107
|
+
try {
|
|
108
|
+
const controller = new AbortController();
|
|
109
|
+
const timeout = setTimeout(() => controller.abort(), 3e3);
|
|
110
|
+
const res = await fetch(`https://registry.npmjs.org/${pkg}/latest`, {
|
|
111
|
+
signal: controller.signal
|
|
112
|
+
});
|
|
113
|
+
clearTimeout(timeout);
|
|
114
|
+
if (!res.ok) return null;
|
|
115
|
+
const data = await res.json();
|
|
116
|
+
return data.version ?? null;
|
|
117
|
+
} catch {
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
function buildPackageJson(name, features, coreVersion, cliVersion, hooksVersion) {
|
|
122
|
+
const dependencies = {
|
|
123
|
+
...BASE_DEPENDENCIES,
|
|
124
|
+
"@thexjs/core": `^${coreVersion}`
|
|
125
|
+
};
|
|
126
|
+
const devDependencies = {
|
|
127
|
+
...BASE_DEV_DEPENDENCIES,
|
|
128
|
+
"@thexjs/cli": `^${cliVersion}`
|
|
129
|
+
};
|
|
130
|
+
if (features.includes("hooks") && hooksVersion) {
|
|
131
|
+
dependencies["@thexjs/hooks"] = `^${hooksVersion}`;
|
|
132
|
+
}
|
|
133
|
+
for (const feature of features) {
|
|
134
|
+
const meta = FEATURES.find((f) => f.id === feature);
|
|
135
|
+
if (!meta) continue;
|
|
136
|
+
Object.assign(dependencies, meta.dependencies);
|
|
137
|
+
Object.assign(devDependencies, meta.devDependencies);
|
|
138
|
+
}
|
|
139
|
+
const pkg = {
|
|
140
|
+
name,
|
|
141
|
+
private: true,
|
|
142
|
+
type: "module",
|
|
143
|
+
scripts: {
|
|
144
|
+
dev: "x dev",
|
|
145
|
+
build: "x build",
|
|
146
|
+
start: "x start"
|
|
147
|
+
},
|
|
148
|
+
dependencies,
|
|
149
|
+
devDependencies
|
|
150
|
+
};
|
|
151
|
+
return `${JSON.stringify(pkg, null, 2)}
|
|
152
|
+
`;
|
|
153
|
+
}
|
|
154
|
+
|
|
88
155
|
// src/index.ts
|
|
89
156
|
function abort(message) {
|
|
90
157
|
cancel(message);
|
|
@@ -94,7 +161,6 @@ var __dirname = dirname(fileURLToPath(import.meta.url));
|
|
|
94
161
|
var TEMPLATES_ROOT = join(__dirname, "..", "templates");
|
|
95
162
|
var BASE_TEMPLATE = join(TEMPLATES_ROOT, "base");
|
|
96
163
|
var ADDONS_ROOT = join(TEMPLATES_ROOT, "addons");
|
|
97
|
-
var FALLBACK_CORE_VERSION = "1.2.2";
|
|
98
164
|
function parseArgs(argv) {
|
|
99
165
|
const options = {
|
|
100
166
|
features: [],
|
|
@@ -132,6 +198,9 @@ function parseArgs(argv) {
|
|
|
132
198
|
case "--content":
|
|
133
199
|
nonInteractive.push("content");
|
|
134
200
|
break;
|
|
201
|
+
case "--hooks":
|
|
202
|
+
nonInteractive.push("hooks");
|
|
203
|
+
break;
|
|
135
204
|
default:
|
|
136
205
|
if (arg && !arg.startsWith("--")) positional.push(arg);
|
|
137
206
|
}
|
|
@@ -148,21 +217,6 @@ function parseArgs(argv) {
|
|
|
148
217
|
function slugify(name) {
|
|
149
218
|
return name.trim().toLowerCase().replace(/[^a-z0-9-]+/g, "-").replace(/^-+|-+$/g, "") || "thexjs-app";
|
|
150
219
|
}
|
|
151
|
-
async function fetchLatestVersion(pkg) {
|
|
152
|
-
try {
|
|
153
|
-
const controller = new AbortController();
|
|
154
|
-
const timeout = setTimeout(() => controller.abort(), 3e3);
|
|
155
|
-
const res = await fetch(`https://registry.npmjs.org/${pkg}/latest`, {
|
|
156
|
-
signal: controller.signal
|
|
157
|
-
});
|
|
158
|
-
clearTimeout(timeout);
|
|
159
|
-
if (!res.ok) return null;
|
|
160
|
-
const data = await res.json();
|
|
161
|
-
return data.version ?? null;
|
|
162
|
-
} catch {
|
|
163
|
-
return null;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
220
|
function ensureDir(path) {
|
|
167
221
|
if (!existsSync(path)) mkdirSync(path, { recursive: true });
|
|
168
222
|
}
|
|
@@ -190,36 +244,6 @@ function finalizeGitignore(targetDir) {
|
|
|
190
244
|
const to = join(targetDir, ".gitignore");
|
|
191
245
|
renameSync(from, to);
|
|
192
246
|
}
|
|
193
|
-
function buildPackageJson(name, features, coreVersion, cliVersion) {
|
|
194
|
-
const dependencies = {
|
|
195
|
-
...BASE_DEPENDENCIES,
|
|
196
|
-
"@thexjs/core": `^${coreVersion}`
|
|
197
|
-
};
|
|
198
|
-
const devDependencies = {
|
|
199
|
-
...BASE_DEV_DEPENDENCIES,
|
|
200
|
-
"@thexjs/cli": `^${cliVersion}`
|
|
201
|
-
};
|
|
202
|
-
for (const feature of features) {
|
|
203
|
-
const meta = FEATURES.find((f) => f.id === feature);
|
|
204
|
-
if (!meta) continue;
|
|
205
|
-
Object.assign(dependencies, meta.dependencies);
|
|
206
|
-
Object.assign(devDependencies, meta.devDependencies);
|
|
207
|
-
}
|
|
208
|
-
const pkg = {
|
|
209
|
-
name,
|
|
210
|
-
private: true,
|
|
211
|
-
type: "module",
|
|
212
|
-
scripts: {
|
|
213
|
-
dev: "x dev",
|
|
214
|
-
build: "x build",
|
|
215
|
-
start: "x start"
|
|
216
|
-
},
|
|
217
|
-
dependencies,
|
|
218
|
-
devDependencies
|
|
219
|
-
};
|
|
220
|
-
return `${JSON.stringify(pkg, null, 2)}
|
|
221
|
-
`;
|
|
222
|
-
}
|
|
223
247
|
function buildXConfig(features) {
|
|
224
248
|
const lines = [];
|
|
225
249
|
lines.push('import { defineConfig } from "@thexjs/core";');
|
|
@@ -298,11 +322,10 @@ async function main() {
|
|
|
298
322
|
copyAddon(feature, targetDir);
|
|
299
323
|
}
|
|
300
324
|
spin.message("Resolving latest @thexjs versions");
|
|
301
|
-
const coreVersion = await
|
|
302
|
-
const cliVersion = await fetchLatestVersion("@thexjs/cli") ?? FALLBACK_CORE_VERSION;
|
|
325
|
+
const { coreVersion, cliVersion, hooksVersion } = await resolveVersions(features);
|
|
303
326
|
writeFileSync(
|
|
304
327
|
join(targetDir, "package.json"),
|
|
305
|
-
buildPackageJson(slug, features, coreVersion, cliVersion)
|
|
328
|
+
buildPackageJson(slug, features, coreVersion, cliVersion, hooksVersion)
|
|
306
329
|
);
|
|
307
330
|
writeFileSync(join(targetDir, "x.config.ts"), buildXConfig(features));
|
|
308
331
|
spin.stop(`Created ${slug}/`);
|