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.
- package/README.md +56 -915
- package/dist/index.js +283 -196
- package/package.json +5 -1
- package/templates/{basic → addons/auth}/src/api/auth/login.ts +1 -3
- package/templates/{basic → addons/auth}/src/lib/auth.ts +13 -9
- package/templates/{basic → addons/auth}/src/lib/migrations/001_create_sessions.sql +1 -3
- package/templates/addons/auth/src/pages/dashboard/index.tsx +39 -0
- package/templates/addons/auth/src/pages/login.tsx +72 -0
- package/templates/addons/content/content/hello-world.md +13 -0
- package/templates/addons/content/src/pages/blog.tsx +29 -0
- package/templates/{basic → addons/shadcn}/components.json +1 -1
- package/templates/addons/shadcn/src/components/ui/badge.tsx +17 -0
- package/templates/addons/shadcn/src/components/ui/button.tsx +36 -0
- package/templates/addons/shadcn/src/components/ui/card.tsx +33 -0
- package/templates/addons/shadcn/src/components/ui/input.tsx +18 -0
- package/templates/addons/tailwind/src/styles/globals.css +32 -0
- package/templates/base/_gitignore +26 -0
- package/templates/base/src/pages/index.tsx +29 -0
- package/templates/base/src/styles/globals.css +22 -0
- package/templates/base/tsconfig.json +24 -0
- package/templates/basic/content/blog/hello.md +0 -8
- package/templates/basic/public/favicon.ico +0 -0
- package/templates/basic/src/actions/dashboard/greet.ts +0 -3
- package/templates/basic/src/api/placeholder/comments.ts +0 -17
- package/templates/basic/src/api/placeholder/posts.ts +0 -20
- package/templates/basic/src/api/placeholder/todos.ts +0 -21
- package/templates/basic/src/api/placeholder/users.ts +0 -12
- package/templates/basic/src/components/Head.tsx +0 -21
- package/templates/basic/src/components/Image.tsx +0 -27
- package/templates/basic/src/components/Link.tsx +0 -10
- package/templates/basic/src/components/ui/badge.tsx +0 -49
- package/templates/basic/src/components/ui/button.tsx +0 -58
- package/templates/basic/src/components/ui/card.tsx +0 -88
- package/templates/basic/src/components/ui/input.tsx +0 -20
- package/templates/basic/src/layouts/main.tsx +0 -38
- package/templates/basic/src/lib/placeholder-data.ts +0 -176
- package/templates/basic/src/pages/_404.tsx +0 -17
- package/templates/basic/src/pages/about.tsx +0 -22
- package/templates/basic/src/pages/blog.tsx +0 -41
- package/templates/basic/src/pages/dashboard/index.tsx +0 -84
- package/templates/basic/src/pages/index.tsx +0 -54
- package/templates/basic/src/pages/login.tsx +0 -92
- package/templates/basic/src/pages/placeholder.tsx +0 -203
- package/templates/basic/src/pages/posts/[id].tsx +0 -17
- package/templates/basic/src/styles/globals.css +0 -90
- package/templates/basic/src/x-routes.ts +0 -29
- package/templates/basic/tsconfig.json +0 -11
- package/templates/basic/x.config.ts +0 -10
- package/templates/blog/components.json +0 -20
- package/templates/blog/content/posts/getting-started.md +0 -38
- package/templates/blog/content/posts/hello-world.md +0 -21
- package/templates/blog/content/posts/tailwind-v4.md +0 -31
- package/templates/blog/public/favicon.ico +0 -0
- package/templates/blog/src/components/ui/avatar.tsx +0 -91
- package/templates/blog/src/components/ui/badge.tsx +0 -49
- package/templates/blog/src/components/ui/button.tsx +0 -58
- package/templates/blog/src/components/ui/card.tsx +0 -88
- package/templates/blog/src/components/ui/input.tsx +0 -20
- package/templates/blog/src/layouts/blog.tsx +0 -46
- package/templates/blog/src/layouts/main.tsx +0 -32
- package/templates/blog/src/lib/utils.ts +0 -5
- package/templates/blog/src/pages/about.tsx +0 -36
- package/templates/blog/src/pages/blog/[slug].tsx +0 -56
- package/templates/blog/src/pages/blog/index.tsx +0 -70
- package/templates/blog/src/pages/index.tsx +0 -73
- package/templates/blog/src/styles/globals.css +0 -90
- package/templates/blog/src/x-routes.ts +0 -20
- package/templates/blog/tsconfig.json +0 -5
- package/templates/blog/x.config.ts +0 -6
- package/templates/default/components.json +0 -19
- package/templates/default/src/layouts/main.tsx +0 -28
- package/templates/default/src/pages/index.tsx +0 -66
- package/templates/default/src/styles/globals.css +0 -55
- package/templates/default/src/x-routes.ts +0 -17
- package/templates/default/tsconfig.json +0 -5
- package/templates/default/x.config.ts +0 -6
- package/templates/landing/components.json +0 -20
- package/templates/landing/public/favicon.ico +0 -0
- package/templates/landing/src/components/code-block.tsx +0 -118
- package/templates/landing/src/components/ui/avatar.tsx +0 -91
- package/templates/landing/src/components/ui/badge.tsx +0 -49
- package/templates/landing/src/components/ui/button.tsx +0 -58
- package/templates/landing/src/components/ui/card.tsx +0 -88
- package/templates/landing/src/components/ui/input.tsx +0 -20
- package/templates/landing/src/layouts/main.tsx +0 -78
- package/templates/landing/src/lib/syntax.tsx +0 -366
- package/templates/landing/src/lib/utils.ts +0 -5
- package/templates/landing/src/pages/docs/_layout.tsx +0 -139
- package/templates/landing/src/pages/docs/api-routes.tsx +0 -113
- package/templates/landing/src/pages/docs/build-deploy.tsx +0 -124
- package/templates/landing/src/pages/docs/configuration.tsx +0 -121
- package/templates/landing/src/pages/docs/content-collections.tsx +0 -130
- package/templates/landing/src/pages/docs/data-layer.tsx +0 -142
- package/templates/landing/src/pages/docs/getting-started.tsx +0 -129
- package/templates/landing/src/pages/docs/index.tsx +0 -187
- package/templates/landing/src/pages/docs/installation.tsx +0 -143
- package/templates/landing/src/pages/docs/introduction.tsx +0 -114
- package/templates/landing/src/pages/docs/layouts.tsx +0 -114
- package/templates/landing/src/pages/docs/middleware.tsx +0 -124
- package/templates/landing/src/pages/docs/packages/cli.tsx +0 -133
- package/templates/landing/src/pages/docs/packages/core.tsx +0 -176
- package/templates/landing/src/pages/docs/packages/env.tsx +0 -128
- package/templates/landing/src/pages/docs/pages.tsx +0 -135
- package/templates/landing/src/pages/docs/routing.tsx +0 -123
- package/templates/landing/src/pages/docs/server-functions.tsx +0 -177
- package/templates/landing/src/pages/features.tsx +0 -129
- package/templates/landing/src/pages/index.tsx +0 -159
- package/templates/landing/src/styles/globals.css +0 -136
- package/templates/landing/src/x-routes.ts +0 -31
- package/templates/landing/tsconfig.json +0 -10
- package/templates/landing/x.config.ts +0 -2
- package/templates/saas/components.json +0 -20
- package/templates/saas/public/favicon.ico +0 -0
- package/templates/saas/src/actions/dashboard.ts +0 -3
- package/templates/saas/src/api/auth/login.ts +0 -31
- package/templates/saas/src/components/ui/avatar.tsx +0 -91
- package/templates/saas/src/components/ui/badge.tsx +0 -49
- package/templates/saas/src/components/ui/button.tsx +0 -58
- package/templates/saas/src/components/ui/card.tsx +0 -88
- package/templates/saas/src/components/ui/input.tsx +0 -20
- package/templates/saas/src/layouts/dashboard.tsx +0 -67
- package/templates/saas/src/layouts/main.tsx +0 -38
- package/templates/saas/src/lib/auth.ts +0 -91
- package/templates/saas/src/lib/migrations/001_create_sessions.sql +0 -9
- package/templates/saas/src/lib/utils.ts +0 -5
- package/templates/saas/src/pages/dashboard/_middleware.ts +0 -9
- package/templates/saas/src/pages/dashboard/analytics.tsx +0 -68
- package/templates/saas/src/pages/dashboard/index.tsx +0 -86
- package/templates/saas/src/pages/dashboard/settings.tsx +0 -111
- package/templates/saas/src/pages/index.tsx +0 -110
- package/templates/saas/src/pages/login.tsx +0 -140
- package/templates/saas/src/pages/pricing.tsx +0 -121
- package/templates/saas/src/styles/globals.css +0 -90
- package/templates/saas/src/x-routes.ts +0 -22
- package/templates/saas/tsconfig.json +0 -5
- package/templates/saas/x.config.ts +0 -7
- /package/templates/{basic → addons/auth}/src/api/auth/logout.ts +0 -0
- /package/templates/{basic → addons/auth}/src/pages/dashboard/_middleware.ts +0 -0
- /package/templates/{basic → addons/shadcn}/src/lib/utils.ts +0 -0
package/dist/index.js
CHANGED
|
@@ -2,153 +2,148 @@
|
|
|
2
2
|
|
|
3
3
|
// src/index.ts
|
|
4
4
|
import { spawnSync } from "child_process";
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
cpSync,
|
|
7
|
+
existsSync,
|
|
8
|
+
mkdirSync,
|
|
9
|
+
readdirSync,
|
|
10
|
+
renameSync,
|
|
11
|
+
statSync,
|
|
12
|
+
writeFileSync
|
|
13
|
+
} from "fs";
|
|
6
14
|
import { dirname, join, resolve } from "path";
|
|
7
|
-
import { createInterface } from "readline/promises";
|
|
8
15
|
import { fileURLToPath } from "url";
|
|
16
|
+
import {
|
|
17
|
+
cancel,
|
|
18
|
+
confirm,
|
|
19
|
+
intro,
|
|
20
|
+
isCancel,
|
|
21
|
+
log,
|
|
22
|
+
multiselect,
|
|
23
|
+
note,
|
|
24
|
+
outro,
|
|
25
|
+
spinner,
|
|
26
|
+
text
|
|
27
|
+
} from "@clack/prompts";
|
|
9
28
|
|
|
10
29
|
// src/templates.ts
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
label: "
|
|
15
|
-
|
|
16
|
-
|
|
30
|
+
var FEATURES = [
|
|
31
|
+
{
|
|
32
|
+
id: "tailwind",
|
|
33
|
+
label: "Tailwind CSS",
|
|
34
|
+
hint: "Utility-first styling + the x dev build pipeline",
|
|
35
|
+
default: true,
|
|
17
36
|
dependencies: {
|
|
18
|
-
react: "^19.1.0",
|
|
19
|
-
"react-dom": "^19.1.0"
|
|
20
|
-
},
|
|
21
|
-
devDependencies: {
|
|
22
37
|
"@tailwindcss/cli": "^4.3.3",
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
typescript: "^5.8.0"
|
|
27
|
-
}
|
|
38
|
+
tailwindcss: "^4.3.3"
|
|
39
|
+
},
|
|
40
|
+
devDependencies: {}
|
|
28
41
|
},
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
42
|
+
{
|
|
43
|
+
id: "shadcn",
|
|
44
|
+
label: "shadcn/ui",
|
|
45
|
+
hint: "Accessible React components (requires Tailwind)",
|
|
46
|
+
default: false,
|
|
47
|
+
requires: ["tailwind"],
|
|
32
48
|
dependencies: {
|
|
33
49
|
"@base-ui/react": "^1.6.0",
|
|
34
|
-
"@tailwindcss/cli": "^4.3.3",
|
|
35
50
|
"class-variance-authority": "^0.7.1",
|
|
36
51
|
clsx: "^2.1.1",
|
|
37
52
|
"lucide-react": "^1.27.0",
|
|
38
|
-
react: "^19.0.0",
|
|
39
|
-
"react-dom": "^19.0.0",
|
|
40
|
-
shadcn: "^4.15.0",
|
|
41
53
|
"tailwind-merge": "^3.6.0",
|
|
42
|
-
tailwindcss: "^4.3.3",
|
|
43
54
|
"tw-animate-css": "^1.4.0"
|
|
44
55
|
},
|
|
45
56
|
devDependencies: {
|
|
46
|
-
|
|
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"
|
|
57
|
+
shadcn: "^4.17.0"
|
|
70
58
|
}
|
|
71
59
|
},
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
}
|
|
60
|
+
{
|
|
61
|
+
id: "auth",
|
|
62
|
+
label: "Auth (sessions + login)",
|
|
63
|
+
hint: "SQLite-backed demo sessions, /login and a protected /dashboard",
|
|
64
|
+
default: false,
|
|
65
|
+
dependencies: {},
|
|
66
|
+
devDependencies: {}
|
|
93
67
|
},
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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
|
-
}
|
|
68
|
+
{
|
|
69
|
+
id: "content",
|
|
70
|
+
label: "Content collections",
|
|
71
|
+
hint: "Markdown/MDX with frontmatter, auto-routed from content/",
|
|
72
|
+
default: false,
|
|
73
|
+
dependencies: {},
|
|
74
|
+
devDependencies: {}
|
|
115
75
|
}
|
|
76
|
+
];
|
|
77
|
+
var BASE_DEPENDENCIES = {
|
|
78
|
+
react: "^19.1.0",
|
|
79
|
+
"react-dom": "^19.1.0"
|
|
80
|
+
};
|
|
81
|
+
var BASE_DEV_DEPENDENCIES = {
|
|
82
|
+
"@types/react": "^19.1.0",
|
|
83
|
+
"@types/react-dom": "^19.1.0",
|
|
84
|
+
typescript: "^5.8.0"
|
|
116
85
|
};
|
|
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
86
|
|
|
148
87
|
// src/index.ts
|
|
88
|
+
function abort(message) {
|
|
89
|
+
cancel(message);
|
|
90
|
+
process.exit(1);
|
|
91
|
+
}
|
|
149
92
|
var __dirname = dirname(fileURLToPath(import.meta.url));
|
|
150
93
|
var TEMPLATES_ROOT = join(__dirname, "..", "templates");
|
|
94
|
+
var BASE_TEMPLATE = join(TEMPLATES_ROOT, "base");
|
|
95
|
+
var ADDONS_ROOT = join(TEMPLATES_ROOT, "addons");
|
|
151
96
|
var FALLBACK_CORE_VERSION = "0.1.0";
|
|
97
|
+
function parseArgs(argv) {
|
|
98
|
+
const options = {
|
|
99
|
+
features: [],
|
|
100
|
+
install: true,
|
|
101
|
+
git: true,
|
|
102
|
+
runDev: false
|
|
103
|
+
};
|
|
104
|
+
const positional = [];
|
|
105
|
+
const nonInteractive = [];
|
|
106
|
+
for (let i = 0; i < argv.length; i++) {
|
|
107
|
+
const arg = argv[i];
|
|
108
|
+
switch (arg) {
|
|
109
|
+
case "--template":
|
|
110
|
+
case "-t":
|
|
111
|
+
i++;
|
|
112
|
+
break;
|
|
113
|
+
case "--no-install":
|
|
114
|
+
options.install = false;
|
|
115
|
+
break;
|
|
116
|
+
case "--no-git":
|
|
117
|
+
options.git = false;
|
|
118
|
+
break;
|
|
119
|
+
case "--dev":
|
|
120
|
+
options.runDev = true;
|
|
121
|
+
break;
|
|
122
|
+
case "--tailwind":
|
|
123
|
+
nonInteractive.push("tailwind");
|
|
124
|
+
break;
|
|
125
|
+
case "--shadcn":
|
|
126
|
+
nonInteractive.push("shadcn");
|
|
127
|
+
break;
|
|
128
|
+
case "--auth":
|
|
129
|
+
nonInteractive.push("auth");
|
|
130
|
+
break;
|
|
131
|
+
case "--content":
|
|
132
|
+
nonInteractive.push("content");
|
|
133
|
+
break;
|
|
134
|
+
default:
|
|
135
|
+
if (arg && !arg.startsWith("--")) positional.push(arg);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
const firstPositional = positional[0];
|
|
139
|
+
if (firstPositional) {
|
|
140
|
+
options.projectName = firstPositional;
|
|
141
|
+
}
|
|
142
|
+
if (nonInteractive.length > 0) {
|
|
143
|
+
options.features = Array.from(/* @__PURE__ */ new Set([...options.features, ...nonInteractive]));
|
|
144
|
+
}
|
|
145
|
+
return options;
|
|
146
|
+
}
|
|
152
147
|
function slugify(name) {
|
|
153
148
|
return name.trim().toLowerCase().replace(/[^a-z0-9-]+/g, "-").replace(/^-+|-+$/g, "") || "thexjs-app";
|
|
154
149
|
}
|
|
@@ -167,102 +162,194 @@ async function fetchLatestVersion(pkg) {
|
|
|
167
162
|
return null;
|
|
168
163
|
}
|
|
169
164
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
165
|
+
function ensureDir(path) {
|
|
166
|
+
if (!existsSync(path)) mkdirSync(path, { recursive: true });
|
|
167
|
+
}
|
|
168
|
+
function mergeTree(src, dest) {
|
|
169
|
+
ensureDir(dest);
|
|
170
|
+
for (const entry of readdirSync(src)) {
|
|
171
|
+
const from = join(src, entry);
|
|
172
|
+
const to = join(dest, entry);
|
|
173
|
+
const stat = statSync(from);
|
|
174
|
+
if (stat.isDirectory()) {
|
|
175
|
+
mergeTree(from, to);
|
|
176
|
+
} else {
|
|
177
|
+
cpSync(from, to);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
function copyAddon(addon, targetDir) {
|
|
182
|
+
const src = join(ADDONS_ROOT, addon);
|
|
183
|
+
if (!existsSync(src)) return;
|
|
184
|
+
mergeTree(src, targetDir);
|
|
176
185
|
}
|
|
177
|
-
function
|
|
178
|
-
|
|
186
|
+
function finalizeGitignore(targetDir) {
|
|
187
|
+
const from = join(targetDir, "_gitignore");
|
|
188
|
+
if (!existsSync(from)) return;
|
|
189
|
+
const to = join(targetDir, ".gitignore");
|
|
190
|
+
renameSync(from, to);
|
|
179
191
|
}
|
|
180
|
-
function
|
|
181
|
-
|
|
182
|
-
|
|
192
|
+
function buildPackageJson(name, features, coreVersion, cliVersion) {
|
|
193
|
+
const dependencies = {
|
|
194
|
+
...BASE_DEPENDENCIES,
|
|
195
|
+
"@thexjs/core": `^${coreVersion}`
|
|
196
|
+
};
|
|
197
|
+
const devDependencies = {
|
|
198
|
+
...BASE_DEV_DEPENDENCIES,
|
|
199
|
+
"@thexjs/cli": `^${cliVersion}`
|
|
200
|
+
};
|
|
201
|
+
for (const feature of features) {
|
|
202
|
+
const meta = FEATURES.find((f) => f.id === feature);
|
|
183
203
|
if (!meta) continue;
|
|
184
|
-
|
|
185
|
-
|
|
204
|
+
Object.assign(dependencies, meta.dependencies);
|
|
205
|
+
Object.assign(devDependencies, meta.devDependencies);
|
|
206
|
+
}
|
|
207
|
+
const pkg = {
|
|
208
|
+
name,
|
|
209
|
+
private: true,
|
|
210
|
+
type: "module",
|
|
211
|
+
scripts: {
|
|
212
|
+
dev: "x dev",
|
|
213
|
+
build: "x build",
|
|
214
|
+
start: "x start"
|
|
215
|
+
},
|
|
216
|
+
dependencies,
|
|
217
|
+
devDependencies
|
|
218
|
+
};
|
|
219
|
+
return `${JSON.stringify(pkg, null, 2)}
|
|
220
|
+
`;
|
|
221
|
+
}
|
|
222
|
+
function buildXConfig(features) {
|
|
223
|
+
const lines = [];
|
|
224
|
+
lines.push('import { defineConfig } from "@thexjs/core";');
|
|
225
|
+
lines.push("");
|
|
226
|
+
lines.push("export default defineConfig({");
|
|
227
|
+
lines.push(' pagesDir: "src/pages",');
|
|
228
|
+
lines.push(' layoutsDir: "src/layouts",');
|
|
229
|
+
lines.push(' apiDir: "src/api",');
|
|
230
|
+
if (features.includes("content")) {
|
|
231
|
+
lines.push(' contentDir: "content",');
|
|
186
232
|
}
|
|
233
|
+
lines.push(" port: 3000,");
|
|
234
|
+
lines.push("});");
|
|
235
|
+
lines.push("");
|
|
236
|
+
return lines.join("\n");
|
|
187
237
|
}
|
|
238
|
+
var FEATURE_SELECT_OPTIONS = FEATURES.map((feature) => ({
|
|
239
|
+
value: feature.id,
|
|
240
|
+
label: `${feature.label}${feature.requires ? ` (requires ${feature.requires.join(", ")})` : ""}`,
|
|
241
|
+
hint: feature.hint
|
|
242
|
+
}));
|
|
188
243
|
async function main() {
|
|
189
|
-
|
|
190
|
-
const
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
let
|
|
194
|
-
let projectName = positional[0];
|
|
244
|
+
const options = parseArgs(process.argv.slice(2));
|
|
245
|
+
const interactive = !options.projectName || options.features.length === 0;
|
|
246
|
+
intro("create thexjs-app");
|
|
247
|
+
let projectName = options.projectName;
|
|
248
|
+
let features = options.features;
|
|
195
249
|
if (!projectName) {
|
|
196
|
-
|
|
250
|
+
const input = await text({
|
|
251
|
+
message: "What should your project be called?",
|
|
252
|
+
placeholder: "my-thexjs-app",
|
|
253
|
+
defaultValue: "my-thexjs-app",
|
|
254
|
+
validate: (value) => {
|
|
255
|
+
if (!value || value.trim().length === 0) return "Project name is required.";
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
if (isCancel(input)) return abort("Cancelled.");
|
|
259
|
+
projectName = input;
|
|
197
260
|
}
|
|
198
261
|
const slug = slugify(projectName);
|
|
199
262
|
const targetDir = resolve(process.cwd(), slug);
|
|
200
263
|
if (existsSync(targetDir) && readdirSync(targetDir).length > 0) {
|
|
201
|
-
|
|
202
|
-
[create-thexjs-app] Directory "${slug}" already exists and is not empty.`);
|
|
203
|
-
process.exit(1);
|
|
264
|
+
return abort(`Directory "${slug}" already exists and is not empty.`);
|
|
204
265
|
}
|
|
205
|
-
if (
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
266
|
+
if (features.length === 0) {
|
|
267
|
+
const selected = await multiselect({
|
|
268
|
+
message: "Which features do you want?",
|
|
269
|
+
options: FEATURE_SELECT_OPTIONS,
|
|
270
|
+
required: false,
|
|
271
|
+
initialValues: FEATURES.filter((f) => f.default).map((f) => f.id)
|
|
272
|
+
});
|
|
273
|
+
if (isCancel(selected)) return abort("Cancelled.");
|
|
274
|
+
features = selected;
|
|
275
|
+
}
|
|
276
|
+
if (!features.includes("tailwind") && features.includes("shadcn")) {
|
|
277
|
+
features = ["tailwind", ...features.filter((f) => f !== "shadcn").sort()];
|
|
278
|
+
log.warn("shadcn/ui requires Tailwind \u2014 enabled Tailwind for you.");
|
|
279
|
+
}
|
|
280
|
+
if (interactive && options.install) {
|
|
281
|
+
const installOk = await confirm({
|
|
282
|
+
message: "Install dependencies and initialize a git repo?",
|
|
283
|
+
initialValue: true
|
|
284
|
+
});
|
|
285
|
+
if (isCancel(installOk)) return abort("Cancelled.");
|
|
286
|
+
if (!installOk) {
|
|
287
|
+
options.install = false;
|
|
288
|
+
options.git = false;
|
|
289
|
+
}
|
|
210
290
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
291
|
+
const spin = spinner();
|
|
292
|
+
spin.start(`Scaffolding "${slug}"`);
|
|
293
|
+
ensureDir(targetDir);
|
|
294
|
+
mergeTree(BASE_TEMPLATE, targetDir);
|
|
295
|
+
finalizeGitignore(targetDir);
|
|
296
|
+
for (const feature of features) {
|
|
297
|
+
copyAddon(feature, targetDir);
|
|
215
298
|
}
|
|
216
|
-
|
|
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...");
|
|
299
|
+
spin.message("Resolving latest @thexjs versions");
|
|
222
300
|
const coreVersion = await fetchLatestVersion("@thexjs/core") ?? FALLBACK_CORE_VERSION;
|
|
223
301
|
const cliVersion = await fetchLatestVersion("@thexjs/cli") ?? FALLBACK_CORE_VERSION;
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
"
|
|
239
|
-
|
|
302
|
+
writeFileSync(
|
|
303
|
+
join(targetDir, "package.json"),
|
|
304
|
+
buildPackageJson(slug, features, coreVersion, cliVersion)
|
|
305
|
+
);
|
|
306
|
+
writeFileSync(join(targetDir, "x.config.ts"), buildXConfig(features));
|
|
307
|
+
spin.stop(`Created ${slug}/`);
|
|
308
|
+
if (options.git) {
|
|
309
|
+
const initSpin = spinner();
|
|
310
|
+
initSpin.start("Initializing git repository (main branch)");
|
|
311
|
+
const result = spawnSync("git", ["init", "-q", "-b", "main"], {
|
|
312
|
+
cwd: targetDir,
|
|
313
|
+
stdio: "ignore"
|
|
314
|
+
});
|
|
315
|
+
if (result.status === 0) {
|
|
316
|
+
initSpin.stop("Git repository initialized on main");
|
|
317
|
+
} else {
|
|
318
|
+
initSpin.stop("Git could not be initialized (is git installed?)");
|
|
240
319
|
}
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
320
|
+
}
|
|
321
|
+
let installed = false;
|
|
322
|
+
if (options.install) {
|
|
323
|
+
const hasBun = spawnSync("bun", ["--version"], { stdio: "ignore" }).status === 0;
|
|
324
|
+
if (hasBun) {
|
|
325
|
+
const installSpin = spinner();
|
|
326
|
+
installSpin.start("Installing dependencies (bun install)");
|
|
327
|
+
const result = spawnSync("bun", ["install"], { cwd: targetDir, stdio: "inherit" });
|
|
328
|
+
if (result.status === 0) {
|
|
329
|
+
installSpin.stop("Dependencies installed");
|
|
330
|
+
installed = true;
|
|
331
|
+
} else {
|
|
332
|
+
installSpin.stop("bun install failed \u2014 you can retry manually");
|
|
333
|
+
}
|
|
334
|
+
} else {
|
|
335
|
+
log.warn(
|
|
336
|
+
"Bun was not found on your PATH. Install it from https://bun.sh, then run `bun install` inside the project."
|
|
337
|
+
);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
const summary = ["", `cd ${slug}`, !installed ? "bun install" : "", "bun run dev"].filter(Boolean).join("\n");
|
|
341
|
+
note(summary, "Next steps");
|
|
342
|
+
outro("Your x app is ready!");
|
|
343
|
+
if (options.runDev && installed) {
|
|
344
|
+
const devSpin = spinner();
|
|
345
|
+
devSpin.start("Starting development server");
|
|
346
|
+
const result = spawnSync("bun", ["run", "dev"], { cwd: targetDir, stdio: "inherit" });
|
|
249
347
|
if (result.status !== 0) {
|
|
250
|
-
|
|
348
|
+
devSpin.stop("Dev server exited");
|
|
251
349
|
}
|
|
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
350
|
}
|
|
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
351
|
}
|
|
265
352
|
main().catch((err) => {
|
|
266
|
-
|
|
353
|
+
cancel(`Unexpected error: ${err}`);
|
|
267
354
|
process.exit(1);
|
|
268
355
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-thexjs-app",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
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":
|
|
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
|
|
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
|
-
|
|
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
|
|
50
|
-
const row =
|
|
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
|
|
59
|
-
|
|
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);
|