@seip/bluebird-js 0.1.6 → 0.2.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.
- package/.vscode/extensions.json +7 -7
- package/.vscode/settings.json +10 -10
- package/AGENTS.md +266 -116
- package/README.md +258 -245
- package/app/models/user.js +19 -0
- package/app/resources/html/home.html +137 -0
- package/app/resources/html/layouts/main.html +54 -0
- package/app/resources/html/notFound.html +14 -0
- package/app/resources/html/terms.html +46 -0
- package/app/resources/index.html +27 -0
- package/app/resources/layouts/AppLayout.jsx +89 -0
- package/app/resources/main.jsx +18 -0
- package/app/resources/pages/Dashboard.jsx +98 -0
- package/app/resources/pages/Home.jsx +140 -0
- package/app/resources/pages/Login.jsx +35 -0
- package/app/resources/pages/NotFound.jsx +16 -0
- package/app/resources/pages/Register.jsx +55 -0
- package/app/resources/routes.jsx +54 -0
- package/app/resources/spa.js +67 -0
- package/app/resources/styles.css +9 -0
- package/app/routes/api.js +85 -50
- package/app/routes/auth.js +209 -0
- package/app/routes/web.js +49 -37
- package/core/ai.d.ts +151 -151
- package/core/ai.js +1071 -1051
- package/core/app.d.ts +2 -18
- package/core/app.js +978 -792
- package/core/auth.d.ts +2 -13
- package/core/auth.js +444 -326
- package/core/cli/backup.js +167 -167
- package/core/cli/build.js +37 -0
- package/core/cli/dev.js +155 -0
- package/core/cli/doctor.js +37 -2
- package/core/cli/export.js +191 -0
- package/core/cli/init.js +101 -332
- package/core/cli/nginx.js +1 -1
- package/core/cli/templates.js +139 -0
- package/core/cli/view.js +73 -136
- package/core/config.js +44 -2
- package/core/csrf.js +156 -24
- package/core/database.js +737 -684
- package/core/debug.js +1 -1
- package/core/html.js +8 -1
- package/core/index.d.ts +1286 -1431
- package/core/paths.js +55 -0
- package/core/ratelimit.js +10 -1
- package/core/react/client/api.js +237 -0
- package/core/react/client/auth.js +236 -0
- package/core/react/client/components.js +1321 -0
- package/core/react/client/i18n.js +338 -0
- package/core/react/client/index.d.ts +249 -0
- package/core/react/client/index.js +49 -0
- package/core/react/client/router.js +26 -0
- package/core/react/client/theme.css +512 -0
- package/core/render-cache.js +250 -212
- package/core/render.d.ts +25 -21
- package/core/render.js +613 -603
- package/core/router.d.ts +2 -3
- package/core/router.js +171 -171
- package/core/seo.js +10 -0
- package/core/spa.js +599 -0
- package/core/view-loader.js +81 -455
- package/core/vite-plugin.d.ts +18 -0
- package/core/vite-plugin.js +162 -0
- package/core/vite.js +250 -145
- package/index.js +22 -18
- package/jsconfig.json +5 -3
- package/package.json +114 -92
- package/production.md +8 -3
- package/public/js/bluebird.js +1160 -0
- package/templates/_auth/app/database.js +19 -0
- package/templates/_auth/app/models/user.js +22 -0
- package/templates/_auth/app/routes/auth-router.js +304 -0
- package/templates/_base/app/resources/html/layouts/main.html +55 -0
- package/templates/_base/app/resources/html/notFound.html +14 -0
- package/templates/_base/app/resources/index.html +27 -0
- package/templates/_base/app/resources/styles.css +9 -0
- package/templates/api/app/models/note.js +18 -0
- package/templates/api/app/routes/api.js +82 -0
- package/templates/api/app/routes/auth.js +11 -0
- package/templates/api/index.js +19 -0
- package/templates/api/template.json +13 -0
- package/templates/auth/app/mail.js +11 -0
- package/templates/auth/app/models/password_reset.js +18 -0
- package/templates/auth/app/resources/html/home.html +21 -0
- package/templates/auth/app/resources/html/partials/nav.html +2 -0
- package/templates/auth/app/resources/layouts/AppLayout.jsx +60 -0
- package/templates/auth/app/resources/main.jsx +18 -0
- package/templates/auth/app/resources/pages/Dashboard.jsx +51 -0
- package/templates/auth/app/resources/pages/ForgotPassword.jsx +34 -0
- package/templates/auth/app/resources/pages/Login.jsx +36 -0
- package/templates/auth/app/resources/pages/NotFound.jsx +16 -0
- package/templates/auth/app/resources/pages/Profile.jsx +99 -0
- package/templates/auth/app/resources/pages/Register.jsx +50 -0
- package/templates/auth/app/resources/pages/ResetPassword.jsx +50 -0
- package/templates/auth/app/resources/routes.jsx +54 -0
- package/templates/auth/app/resources/spa.js +29 -0
- package/templates/auth/app/routes/api.js +17 -0
- package/templates/auth/app/routes/auth.js +13 -0
- package/templates/auth/app/routes/web.js +21 -0
- package/templates/auth/index.js +19 -0
- package/templates/auth/template.json +15 -0
- package/templates/blank/app/models/.gitkeep +0 -0
- package/templates/blank/app/resources/html/home.html +27 -0
- package/templates/blank/app/resources/html/partials/nav.html +1 -0
- package/templates/blank/app/resources/main.jsx +16 -0
- package/templates/blank/app/resources/pages/Home.jsx +42 -0
- package/templates/blank/app/resources/pages/NotFound.jsx +27 -0
- package/templates/blank/app/resources/routes.jsx +15 -0
- package/templates/blank/app/resources/spa.js +24 -0
- package/templates/blank/app/routes/api.js +11 -0
- package/templates/blank/app/routes/web.js +21 -0
- package/templates/blank/index.js +13 -0
- package/templates/blank/template.json +12 -0
- package/templates/blog/app/lib/blog.js +149 -0
- package/templates/blog/app/models/post.js +22 -0
- package/templates/blog/app/resources/html/home.html +28 -0
- package/templates/blog/app/resources/html/not-found.html +5 -0
- package/templates/blog/app/resources/html/partials/nav.html +2 -0
- package/templates/blog/app/resources/html/partials/post-card.html +9 -0
- package/templates/blog/app/resources/html/post.html +8 -0
- package/templates/blog/app/resources/layouts/AdminLayout.jsx +54 -0
- package/templates/blog/app/resources/main.jsx +18 -0
- package/templates/blog/app/resources/pages/Login.jsx +31 -0
- package/templates/blog/app/resources/pages/NotFound.jsx +16 -0
- package/templates/blog/app/resources/pages/PostEditor.jsx +51 -0
- package/templates/blog/app/resources/pages/Posts.jsx +83 -0
- package/templates/blog/app/resources/pages/Register.jsx +43 -0
- package/templates/blog/app/resources/routes.jsx +51 -0
- package/templates/blog/app/resources/spa.js +25 -0
- package/templates/blog/app/resources/styles.css +40 -0
- package/templates/blog/app/routes/api.js +77 -0
- package/templates/blog/app/routes/auth.js +10 -0
- package/templates/blog/app/routes/web.js +114 -0
- package/templates/blog/index.js +21 -0
- package/templates/blog/template.json +14 -0
- package/vite.config.js +11 -0
- package/app/views/about.jsx +0 -98
- package/app/views/components/Header.jsx +0 -42
- package/app/views/components/LiveCounter.jsx +0 -66
- package/app/views/dashboard.jsx +0 -300
- package/app/views/index.jsx +0 -123
- package/app/views/layouts/main/view.jsx +0 -201
- package/app/views/legal/terms.html +0 -29
- package/app/views/login.jsx +0 -141
- package/core/actions.d.ts +0 -4
- package/core/actions.js +0 -329
- package/core/jsx.d.ts +0 -38
- package/core/jsx.js +0 -1432
- package/core/vite.d.ts +0 -3
- package/public/js/bluebird-client.js +0 -3161
- package/public/js/tailwind.js +0 -8
package/core/view-loader.js
CHANGED
|
@@ -1,216 +1,53 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import { pathToFileURL } from "node:url";
|
|
4
3
|
import Config from "./config.js";
|
|
5
|
-
import
|
|
6
|
-
import { compileJsx, registerJsxLoader, stripTsTypes } from "./jsx.js";
|
|
4
|
+
import { PATHS } from "./paths.js";
|
|
7
5
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const props = Config.props();
|
|
11
|
-
const DEBUG = props.debug;
|
|
6
|
+
const DEBUG = Config.props().debug;
|
|
12
7
|
|
|
13
8
|
/**
|
|
14
|
-
* Returns the base views directory
|
|
9
|
+
* Returns the base views directory relative to `Config.appDir()`.
|
|
15
10
|
* @returns {string}
|
|
16
11
|
*/
|
|
17
12
|
function getViewsDir() {
|
|
18
|
-
return path.resolve(Config.appDir(), process.env.VIEWS_PATH ||
|
|
13
|
+
return path.resolve(Config.appDir(), process.env.VIEWS_PATH || PATHS.html);
|
|
19
14
|
}
|
|
20
15
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
* @type {Map<string, Object>}
|
|
24
|
-
*/
|
|
25
|
-
const moduleCache = new Map();
|
|
16
|
+
const fileCache = new Map();
|
|
17
|
+
const resolveCache = new Map();
|
|
26
18
|
|
|
27
19
|
/**
|
|
28
|
-
* Checks whether a candidate path
|
|
29
|
-
* Prevents directory traversal attacks.
|
|
20
|
+
* Checks whether a candidate path stays inside the views directory.
|
|
30
21
|
* @param {string} candidatePath
|
|
31
22
|
* @returns {boolean}
|
|
32
23
|
*/
|
|
33
24
|
function isSafePath(candidatePath) {
|
|
34
25
|
const viewsDir = getViewsDir();
|
|
35
26
|
const resolved = path.resolve(viewsDir, candidatePath);
|
|
36
|
-
return resolved.startsWith(viewsDir);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Parses JSX-like attribute strings inside legacy `html\`...\`` template literals.
|
|
41
|
-
* @param {string} attrs
|
|
42
|
-
* @returns {string}
|
|
43
|
-
*/
|
|
44
|
-
function transformJsxAttributes(attrs) {
|
|
45
|
-
const trimmed = attrs.trim();
|
|
46
|
-
if (!trimmed) return "{}";
|
|
47
|
-
|
|
48
|
-
if (trimmed.startsWith("props=")) {
|
|
49
|
-
let propVal = trimmed.slice(6).trim();
|
|
50
|
-
if (propVal.startsWith("{{") && propVal.endsWith("}}")) {
|
|
51
|
-
return propVal.slice(1, -1);
|
|
52
|
-
}
|
|
53
|
-
if (propVal.startsWith("{") && propVal.endsWith("}")) {
|
|
54
|
-
const inner = propVal.slice(1, -1).trim();
|
|
55
|
-
if (inner.startsWith("{") && inner.endsWith("}")) {
|
|
56
|
-
return inner;
|
|
57
|
-
}
|
|
58
|
-
return `{ ${inner} }`;
|
|
59
|
-
}
|
|
60
|
-
return propVal;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const entries = [];
|
|
64
|
-
const regex = /([a-zA-Z0-9_\-]+)(?:\s*=\s*(?:\{([\s\S]*?)\}|"([^"]*)"|'([^']*)'))?/g;
|
|
65
|
-
let m;
|
|
66
|
-
let hasParsed = false;
|
|
67
|
-
while ((m = regex.exec(trimmed)) !== null) {
|
|
68
|
-
hasParsed = true;
|
|
69
|
-
const key = m[1];
|
|
70
|
-
if (key.startsWith("...")) {
|
|
71
|
-
entries.push(key);
|
|
72
|
-
continue;
|
|
73
|
-
}
|
|
74
|
-
if (m[2] !== undefined) {
|
|
75
|
-
entries.push(`${key}: (${m[2]})`);
|
|
76
|
-
} else if (m[3] !== undefined) {
|
|
77
|
-
entries.push(`${key}: "${m[3]}"`);
|
|
78
|
-
} else if (m[4] !== undefined) {
|
|
79
|
-
entries.push(`${key}: '${m[4]}'`);
|
|
80
|
-
} else {
|
|
81
|
-
entries.push(`${key}: true`);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (!hasParsed) return "{}";
|
|
86
|
-
return `{ ${entries.join(", ")} }`;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Transforms legacy JSX component tags inside `html\`...\`` view source code into JavaScript calls.
|
|
91
|
-
* @param {string} code
|
|
92
|
-
* @returns {string}
|
|
93
|
-
*/
|
|
94
|
-
function transformViewJsx(code) {
|
|
95
|
-
let transformed = code;
|
|
96
|
-
transformed = transformed.replace(
|
|
97
|
-
/\$\{\s*<([A-Z][a-zA-Z0-9_]*)([\s\S]*?)\/>\s*\}/g,
|
|
98
|
-
(match, compName, attrs) => {
|
|
99
|
-
return `\${${compName}(${transformJsxAttributes(attrs)})}`;
|
|
100
|
-
}
|
|
101
|
-
);
|
|
102
|
-
transformed = transformed.replace(
|
|
103
|
-
/<([A-Z][a-zA-Z0-9_]*)\s+props=\{\s*\{?([^}]*)\}?\s*\}\s*\/>/g,
|
|
104
|
-
(match, compName, inner) => {
|
|
105
|
-
return `\${${compName}({ ${inner.trim()} })}`;
|
|
106
|
-
}
|
|
107
|
-
);
|
|
108
|
-
return transformed;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Automatically discovers and registers components from views directories.
|
|
113
|
-
*/
|
|
114
|
-
async function autoRegisterComponents() {
|
|
115
|
-
const viewsDir = getViewsDir();
|
|
116
|
-
const dirs = [path.join(viewsDir, "components"), path.join(viewsDir, "partials")];
|
|
117
|
-
|
|
118
|
-
for (const dir of dirs) {
|
|
119
|
-
if (!fs.existsSync(dir)) continue;
|
|
120
|
-
try {
|
|
121
|
-
const files = fs.readdirSync(dir);
|
|
122
|
-
for (const file of files) {
|
|
123
|
-
if ((!file.endsWith(".js") && !file.endsWith(".jsx")) || file.startsWith(".")) continue;
|
|
124
|
-
const ext = path.extname(file);
|
|
125
|
-
const compName = path.basename(file, ext);
|
|
126
|
-
if (html.getComponent(compName)) continue;
|
|
127
|
-
const fullPath = path.join(dir, file);
|
|
128
|
-
try {
|
|
129
|
-
const mod = await importModule(fullPath);
|
|
130
|
-
const compFn = mod.default || mod[compName];
|
|
131
|
-
if (typeof compFn === "function") {
|
|
132
|
-
html.register({ [compName]: compFn });
|
|
133
|
-
}
|
|
134
|
-
} catch {}
|
|
135
|
-
}
|
|
136
|
-
} catch {}
|
|
137
|
-
}
|
|
27
|
+
return resolved === viewsDir || resolved.startsWith(viewsDir + path.sep);
|
|
138
28
|
}
|
|
139
29
|
|
|
140
30
|
/**
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
* @
|
|
144
|
-
* @returns {Promise<Object>}
|
|
31
|
+
* Reads an HTML template file with production memoization and `.asar.unpacked` fallback.
|
|
32
|
+
* @param {string} fullPath
|
|
33
|
+
* @returns {{type: "html", filePath: string, content: string}}
|
|
145
34
|
*/
|
|
146
|
-
|
|
147
|
-
if (!DEBUG &&
|
|
148
|
-
return moduleCache.get(absolutePath);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
let targetPath = absolutePath;
|
|
152
|
-
if (absolutePath.includes(".asar")) {
|
|
153
|
-
const unpackedPath = absolutePath.replace(/\.asar(?=[\/\\]|$)/, ".asar.unpacked");
|
|
154
|
-
if (fs.existsSync(unpackedPath)) {
|
|
155
|
-
targetPath = unpackedPath;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
35
|
+
function readHtmlFile(fullPath) {
|
|
36
|
+
if (!DEBUG && fileCache.has(fullPath)) return fileCache.get(fullPath);
|
|
158
37
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
const rawCode = fs.readFileSync(targetPath, "utf-8");
|
|
164
|
-
const hasTemplateJsx = !isJsxOrTsx && (/\$\{\s*<[A-Z]|<[A-Z][a-zA-Z0-9_]*\s+props=/.test(rawCode));
|
|
165
|
-
|
|
166
|
-
let mod;
|
|
167
|
-
if (hasTemplateJsx) {
|
|
168
|
-
const transformedCode = transformViewJsx(rawCode);
|
|
169
|
-
const uniqueSuffix = `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
170
|
-
const tempFile = path.join(
|
|
171
|
-
path.dirname(targetPath),
|
|
172
|
-
`.bb-${uniqueSuffix}-${path.basename(targetPath)}`
|
|
173
|
-
);
|
|
174
|
-
fs.writeFileSync(tempFile, transformedCode, "utf-8");
|
|
175
|
-
try {
|
|
176
|
-
const fileUrl = pathToFileURL(tempFile).href;
|
|
177
|
-
mod = await import(fileUrl);
|
|
178
|
-
} finally {
|
|
179
|
-
try {
|
|
180
|
-
if (fs.existsSync(tempFile)) fs.unlinkSync(tempFile);
|
|
181
|
-
} catch {}
|
|
182
|
-
}
|
|
183
|
-
} else {
|
|
184
|
-
const stats = fs.statSync(targetPath);
|
|
185
|
-
const fileUrl = pathToFileURL(targetPath).href;
|
|
186
|
-
const targetUrl = DEBUG ? `${fileUrl}?t=${stats.mtimeMs}` : fileUrl;
|
|
187
|
-
|
|
188
|
-
try {
|
|
189
|
-
mod = await import(targetUrl);
|
|
190
|
-
} catch (err) {
|
|
191
|
-
if (isJsxOrTsx || isTsFile || absolutePath.includes(".asar")) {
|
|
192
|
-
let sourceToLoad = isJsxOrTsx ? compileJsx(rawCode, { ts: isTsxFile }) : rawCode;
|
|
193
|
-
if (isTsxFile || isTsFile) {
|
|
194
|
-
sourceToLoad = stripTsTypes(sourceToLoad);
|
|
195
|
-
}
|
|
196
|
-
const dataUrl = `data:text/javascript;base64,${Buffer.from(sourceToLoad).toString("base64")}`;
|
|
197
|
-
mod = await import(dataUrl);
|
|
198
|
-
} else {
|
|
199
|
-
throw err;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
38
|
+
let targetPath = fullPath;
|
|
39
|
+
if (fullPath.includes(".asar")) {
|
|
40
|
+
const unpacked = fullPath.replace(/\.asar(?=[\/\\]|$)/, ".asar.unpacked");
|
|
41
|
+
if (fs.existsSync(unpacked)) targetPath = unpacked;
|
|
202
42
|
}
|
|
203
43
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
return mod;
|
|
44
|
+
const entry = { type: "html", filePath: fullPath, content: fs.readFileSync(targetPath, "utf-8") };
|
|
45
|
+
if (!DEBUG) fileCache.set(fullPath, entry);
|
|
46
|
+
return entry;
|
|
208
47
|
}
|
|
209
48
|
|
|
210
49
|
/**
|
|
211
|
-
*
|
|
212
|
-
* Resolves React JSX views (.jsx), modular directory views (e.g. "dashboard/view.jsx" or "dashboard/view.js"),
|
|
213
|
-
* single-file views, components, and layouts.
|
|
50
|
+
* Resolver and loader for `.html` views, partials, and layouts inside `app/resources/html/`.
|
|
214
51
|
*/
|
|
215
52
|
export class ViewLoader {
|
|
216
53
|
/**
|
|
@@ -222,307 +59,96 @@ export class ViewLoader {
|
|
|
222
59
|
}
|
|
223
60
|
|
|
224
61
|
/**
|
|
225
|
-
* Resolves
|
|
226
|
-
*
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
* @param {string} viewName - Logical view identifier.
|
|
230
|
-
* @returns {Promise<{type: "jsx"|"js"|"html", module?: Object, filePath: string, content?: string}|null>}
|
|
62
|
+
* Resolves the absolute file path of a view inside `app/resources/html/`.
|
|
63
|
+
* @param {string} viewName
|
|
64
|
+
* @returns {string|null}
|
|
231
65
|
*/
|
|
232
|
-
static
|
|
233
|
-
if (!viewName || typeof viewName !== "string")
|
|
234
|
-
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
const clean = viewName.replace(/^\/+/, "").replace(/\.(jsx|js|html|ejs)$/, "");
|
|
66
|
+
static resolve(viewName) {
|
|
67
|
+
if (!viewName || typeof viewName !== "string") return null;
|
|
68
|
+
const viewsDir = getViewsDir();
|
|
69
|
+
const cacheKey = `${viewsDir}:${viewName}`;
|
|
70
|
+
const cached = resolveCache.get(cacheKey);
|
|
71
|
+
if (cached && (!DEBUG || fs.existsSync(cached))) return cached;
|
|
240
72
|
|
|
73
|
+
const raw = viewName.replace(/^\/+/, "");
|
|
74
|
+
const clean = raw.replace(/\.(html|htm)$/i, "");
|
|
241
75
|
const candidates = [
|
|
242
|
-
|
|
243
|
-
`${clean}.jsx`,
|
|
244
|
-
`${clean}.ts`,
|
|
245
|
-
`${clean}.js`,
|
|
246
|
-
`${clean}/view.tsx`,
|
|
247
|
-
`${clean}/view.jsx`,
|
|
248
|
-
`${clean}/view.ts`,
|
|
249
|
-
`${clean}/view.js`,
|
|
250
|
-
path.join("pages", `${clean}.tsx`),
|
|
251
|
-
path.join("pages", `${clean}.jsx`),
|
|
252
|
-
path.join("pages", `${clean}.ts`),
|
|
253
|
-
path.join("pages", `${clean}.js`),
|
|
254
|
-
path.join("pages", `${clean}/view.tsx`),
|
|
255
|
-
path.join("pages", `${clean}/view.jsx`),
|
|
256
|
-
path.join("pages", `${clean}/view.ts`),
|
|
257
|
-
path.join("pages", `${clean}/view.js`),
|
|
258
|
-
path.join("components", `${clean}.tsx`),
|
|
259
|
-
path.join("components", `${clean}.jsx`),
|
|
260
|
-
path.join("components", `${clean}.ts`),
|
|
261
|
-
path.join("components", `${clean}.js`),
|
|
262
|
-
path.join("components", `${clean}/view.tsx`),
|
|
263
|
-
path.join("components", `${clean}/view.jsx`),
|
|
264
|
-
path.join("components", `${clean}/view.ts`),
|
|
265
|
-
path.join("components", `${clean}/view.js`),
|
|
266
|
-
path.join("partials", `${clean}.tsx`),
|
|
267
|
-
path.join("partials", `${clean}.jsx`),
|
|
268
|
-
path.join("partials", `${clean}.ts`),
|
|
269
|
-
path.join("partials", `${clean}.js`),
|
|
270
|
-
path.join("partials", `${clean}/view.tsx`),
|
|
271
|
-
path.join("partials", `${clean}/view.jsx`),
|
|
272
|
-
path.join("partials", `${clean}/view.ts`),
|
|
273
|
-
path.join("partials", `${clean}/view.js`),
|
|
274
|
-
path.join("islands", `${clean}.tsx`),
|
|
275
|
-
path.join("islands", `${clean}.jsx`),
|
|
276
|
-
path.join("islands", `${clean}.ts`),
|
|
277
|
-
path.join("islands", `${clean}.js`),
|
|
278
|
-
path.join("layouts", `${clean}/view.tsx`),
|
|
279
|
-
path.join("layouts", `${clean}/view.jsx`),
|
|
280
|
-
path.join("layouts", `${clean}/view.ts`),
|
|
281
|
-
path.join("layouts", `${clean}/view.js`),
|
|
282
|
-
path.join("layouts", `${clean}.tsx`),
|
|
283
|
-
path.join("layouts", `${clean}.jsx`),
|
|
284
|
-
path.join("layouts", `${clean}.ts`),
|
|
285
|
-
path.join("layouts", `${clean}.js`),
|
|
76
|
+
raw,
|
|
286
77
|
`${clean}.html`,
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
78
|
+
`${clean}/view.html`,
|
|
79
|
+
`${clean}/index.html`,
|
|
80
|
+
`partials/${clean}.html`,
|
|
81
|
+
`layouts/${clean}.html`,
|
|
291
82
|
];
|
|
292
83
|
|
|
293
|
-
const viewsDir = getViewsDir();
|
|
294
84
|
for (const candidate of candidates) {
|
|
295
85
|
if (!isSafePath(candidate)) continue;
|
|
296
|
-
|
|
297
86
|
const fullPath = path.resolve(viewsDir, candidate);
|
|
298
|
-
|
|
299
|
-
if (
|
|
300
|
-
|
|
301
|
-
return
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
if (candidate.endsWith(".js") || candidate.endsWith(".ts")) {
|
|
305
|
-
const mod = await importModule(fullPath);
|
|
306
|
-
return { type: "js", module: mod, filePath: fullPath };
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
if (candidate.endsWith(".html")) {
|
|
310
|
-
const content = fs.readFileSync(fullPath, "utf-8");
|
|
311
|
-
return { type: "html", filePath: fullPath, content };
|
|
87
|
+
try {
|
|
88
|
+
if (fs.statSync(fullPath).isFile()) {
|
|
89
|
+
resolveCache.set(cacheKey, fullPath);
|
|
90
|
+
return fullPath;
|
|
312
91
|
}
|
|
313
|
-
}
|
|
92
|
+
} catch {}
|
|
314
93
|
}
|
|
315
|
-
|
|
316
94
|
return null;
|
|
317
95
|
}
|
|
318
96
|
|
|
319
97
|
/**
|
|
320
|
-
*
|
|
321
|
-
*
|
|
322
|
-
*
|
|
323
|
-
* @param {string} layoutName - Layout name (e.g. "main").
|
|
324
|
-
* @returns {Promise<{type: "jsx"|"js"|"html", module?: Object, filePath: string, content?: string}|null>}
|
|
98
|
+
* Loads an HTML view by name.
|
|
99
|
+
* @param {string} viewName
|
|
100
|
+
* @returns {Promise<{type: "html", filePath: string, content: string}|null>}
|
|
325
101
|
*/
|
|
326
|
-
static async
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
path.join("layouts", `${clean}/view.tsx`),
|
|
332
|
-
path.join("layouts", `${clean}/view.jsx`),
|
|
333
|
-
path.join("layouts", `${clean}/view.ts`),
|
|
334
|
-
path.join("layouts", `${clean}/view.js`),
|
|
335
|
-
path.join("layouts", `${clean}.tsx`),
|
|
336
|
-
path.join("layouts", `${clean}.jsx`),
|
|
337
|
-
path.join("layouts", `${clean}.ts`),
|
|
338
|
-
path.join("layouts", `${clean}.js`),
|
|
339
|
-
`${clean}/view.tsx`,
|
|
340
|
-
`${clean}/view.jsx`,
|
|
341
|
-
`${clean}/view.ts`,
|
|
342
|
-
`${clean}/view.js`,
|
|
343
|
-
`${clean}.tsx`,
|
|
344
|
-
`${clean}.jsx`,
|
|
345
|
-
`${clean}.ts`,
|
|
346
|
-
`${clean}.js`,
|
|
347
|
-
path.join("layouts", `${clean}.html`),
|
|
348
|
-
];
|
|
102
|
+
static async load(viewName) {
|
|
103
|
+
const fullPath = ViewLoader.resolve(viewName);
|
|
104
|
+
if (!fullPath) return null;
|
|
105
|
+
return readHtmlFile(fullPath);
|
|
106
|
+
}
|
|
349
107
|
|
|
108
|
+
/**
|
|
109
|
+
* Loads a partial HTML file (`app/resources/html/partials/<name>.html` or `<name>.html`).
|
|
110
|
+
* @param {string} partialName
|
|
111
|
+
* @returns {Promise<{type: "html", filePath: string, content: string}|null>}
|
|
112
|
+
*/
|
|
113
|
+
static async loadPartial(partialName) {
|
|
114
|
+
if (!partialName || typeof partialName !== "string") return null;
|
|
115
|
+
const clean = partialName.replace(/^\/+/, "").replace(/\.(html|htm)$/i, "");
|
|
350
116
|
const viewsDir = getViewsDir();
|
|
351
|
-
for (const candidate of
|
|
117
|
+
for (const candidate of [`partials/${clean}.html`, `${clean}.html`, `${clean}/view.html`]) {
|
|
352
118
|
if (!isSafePath(candidate)) continue;
|
|
353
|
-
|
|
354
119
|
const fullPath = path.resolve(viewsDir, candidate);
|
|
355
|
-
|
|
356
|
-
if (
|
|
357
|
-
|
|
358
|
-
return { type: "jsx", module: mod, filePath: fullPath };
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
if (candidate.endsWith(".js") || candidate.endsWith(".ts")) {
|
|
362
|
-
const mod = await importModule(fullPath);
|
|
363
|
-
return { type: "js", module: mod, filePath: fullPath };
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
if (candidate.endsWith(".html")) {
|
|
367
|
-
const content = fs.readFileSync(fullPath, "utf-8");
|
|
368
|
-
return { type: "html", filePath: fullPath, content };
|
|
369
|
-
}
|
|
370
|
-
}
|
|
120
|
+
try {
|
|
121
|
+
if (fs.statSync(fullPath).isFile()) return readHtmlFile(fullPath);
|
|
122
|
+
} catch {}
|
|
371
123
|
}
|
|
372
|
-
|
|
373
124
|
return null;
|
|
374
125
|
}
|
|
375
126
|
|
|
376
127
|
/**
|
|
377
|
-
*
|
|
128
|
+
* Loads an HTML layout (`app/resources/html/layouts/<name>.html`).
|
|
129
|
+
* @param {string} layoutName
|
|
130
|
+
* @returns {Promise<{type: "html", filePath: string, content: string}|null>}
|
|
378
131
|
*/
|
|
379
|
-
static
|
|
380
|
-
|
|
132
|
+
static async loadLayout(layoutName) {
|
|
133
|
+
if (!layoutName || typeof layoutName !== "string") return null;
|
|
134
|
+
const clean = layoutName.replace(/^\/+/, "").replace(/\.(html|htm)$/i, "");
|
|
135
|
+
const viewsDir = getViewsDir();
|
|
136
|
+
for (const candidate of [`layouts/${clean}.html`, `layouts/${clean}/view.html`, `layouts/${clean}/index.html`]) {
|
|
137
|
+
if (!isSafePath(candidate)) continue;
|
|
138
|
+
const fullPath = path.resolve(viewsDir, candidate);
|
|
139
|
+
try {
|
|
140
|
+
if (fs.statSync(fullPath).isFile()) return readHtmlFile(fullPath);
|
|
141
|
+
} catch {}
|
|
142
|
+
}
|
|
143
|
+
return null;
|
|
381
144
|
}
|
|
382
145
|
|
|
383
146
|
/**
|
|
384
|
-
*
|
|
385
|
-
* to discover page view modules and their declarative route configurations.
|
|
386
|
-
*
|
|
387
|
-
* Supported exports in any view module:
|
|
388
|
-
* - `export const route = "/custom-path" | false` (defaults to file-based route path)
|
|
389
|
-
* - `export const cache = 300` (applies `Render.cache(300)` automatically)
|
|
390
|
-
* - `export const middlewares = [...]` (applies custom route middlewares)
|
|
391
|
-
* - `export const seo = true | false` (defaults to `true` for public routes without middlewares)
|
|
392
|
-
* - `export const layout = "main"`
|
|
393
|
-
*
|
|
394
|
-
* @returns {Promise<Array<{viewName: string, routePath: string, cache: number, middlewares: Function[], seo: boolean, module: Object}>>}
|
|
147
|
+
* Clears in-memory file and resolution caches.
|
|
395
148
|
*/
|
|
396
|
-
static
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
const ignoredDirs = new Set([
|
|
401
|
-
"layouts",
|
|
402
|
-
"components",
|
|
403
|
-
"partials",
|
|
404
|
-
"islands",
|
|
405
|
-
"api",
|
|
406
|
-
"node_modules",
|
|
407
|
-
]);
|
|
408
|
-
|
|
409
|
-
const discovered = [];
|
|
410
|
-
const seenViews = new Set();
|
|
411
|
-
|
|
412
|
-
/**
|
|
413
|
-
* Recursively walks a directory relative to viewsDir.
|
|
414
|
-
* @param {string} currentDir
|
|
415
|
-
* @param {string} relPrefix
|
|
416
|
-
*/
|
|
417
|
-
const walk = async (currentDir, relPrefix = "") => {
|
|
418
|
-
let entries = [];
|
|
419
|
-
try {
|
|
420
|
-
entries = fs.readdirSync(currentDir, { withFileTypes: true });
|
|
421
|
-
} catch {
|
|
422
|
-
return;
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
entries.sort((a, b) => {
|
|
426
|
-
if (a.isFile() && b.isFile()) {
|
|
427
|
-
const aIsJsx = a.name.endsWith(".jsx") || a.name.endsWith(".tsx");
|
|
428
|
-
const bIsJsx = b.name.endsWith(".jsx") || b.name.endsWith(".tsx");
|
|
429
|
-
if (aIsJsx && !bIsJsx) return -1;
|
|
430
|
-
if (!aIsJsx && bIsJsx) return 1;
|
|
431
|
-
}
|
|
432
|
-
return a.name.localeCompare(b.name);
|
|
433
|
-
});
|
|
434
|
-
|
|
435
|
-
for (const entry of entries) {
|
|
436
|
-
if (entry.name.startsWith(".") || entry.name.startsWith("_")) continue;
|
|
437
|
-
|
|
438
|
-
const fullPath = path.join(currentDir, entry.name);
|
|
439
|
-
const relPath = relPrefix ? `${relPrefix}/${entry.name}` : entry.name;
|
|
440
|
-
|
|
441
|
-
if (entry.isDirectory()) {
|
|
442
|
-
if (ignoredDirs.has(entry.name.toLowerCase())) continue;
|
|
443
|
-
await walk(fullPath, relPath);
|
|
444
|
-
continue;
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
if (!entry.isFile()) continue;
|
|
448
|
-
if (
|
|
449
|
-
!entry.name.endsWith(".jsx") &&
|
|
450
|
-
!entry.name.endsWith(".tsx") &&
|
|
451
|
-
!entry.name.endsWith(".js") &&
|
|
452
|
-
!entry.name.endsWith(".ts")
|
|
453
|
-
) {
|
|
454
|
-
continue;
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
const ext = path.extname(entry.name);
|
|
458
|
-
const rawViewName = relPath.slice(0, -ext.length).replace(/\\/g, "/");
|
|
459
|
-
|
|
460
|
-
if (seenViews.has(rawViewName)) continue;
|
|
461
|
-
seenViews.add(rawViewName);
|
|
462
|
-
|
|
463
|
-
let mod;
|
|
464
|
-
try {
|
|
465
|
-
mod = await importModule(fullPath);
|
|
466
|
-
} catch {
|
|
467
|
-
continue;
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
if (!mod || typeof mod.default !== "function") continue;
|
|
471
|
-
if (mod.route === false) continue;
|
|
472
|
-
|
|
473
|
-
let routePath;
|
|
474
|
-
if (typeof mod.route === "string" && mod.route.trim()) {
|
|
475
|
-
routePath = mod.route.trim();
|
|
476
|
-
if (!routePath.startsWith("/")) routePath = `/${routePath}`;
|
|
477
|
-
} else {
|
|
478
|
-
let normalized = rawViewName;
|
|
479
|
-
if (normalized.startsWith("pages/")) {
|
|
480
|
-
normalized = normalized.slice("pages/".length);
|
|
481
|
-
}
|
|
482
|
-
if (normalized === "index" || normalized === "view") {
|
|
483
|
-
routePath = "/";
|
|
484
|
-
} else if (normalized.endsWith("/index")) {
|
|
485
|
-
routePath = "/" + normalized.slice(0, -"/index".length);
|
|
486
|
-
} else if (normalized.endsWith("/view")) {
|
|
487
|
-
routePath = "/" + normalized.slice(0, -"/view".length);
|
|
488
|
-
} else {
|
|
489
|
-
routePath = "/" + normalized;
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
routePath = routePath.replace(/\[([^\]]+)\]/g, ":$1");
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
if (routePath === "/api" || routePath.startsWith("/api/")) {
|
|
496
|
-
continue;
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
const middlewares = Array.isArray(mod.middlewares)
|
|
500
|
-
? mod.middlewares.filter((fn) => typeof fn === "function")
|
|
501
|
-
: typeof mod.middleware === "function"
|
|
502
|
-
? [mod.middleware]
|
|
503
|
-
: [];
|
|
504
|
-
|
|
505
|
-
const cache = typeof mod.cache === "number" && mod.cache > 0 ? mod.cache : 0;
|
|
506
|
-
const seo = mod.seo !== undefined ? Boolean(mod.seo) : middlewares.length === 0;
|
|
507
|
-
const actions =
|
|
508
|
-
mod.actions && (typeof mod.actions === "object" || typeof mod.actions === "function")
|
|
509
|
-
? mod.actions
|
|
510
|
-
: null;
|
|
511
|
-
|
|
512
|
-
discovered.push({
|
|
513
|
-
viewName: rawViewName,
|
|
514
|
-
routePath,
|
|
515
|
-
cache,
|
|
516
|
-
middlewares,
|
|
517
|
-
seo,
|
|
518
|
-
actions,
|
|
519
|
-
module: mod,
|
|
520
|
-
});
|
|
521
|
-
}
|
|
522
|
-
};
|
|
523
|
-
|
|
524
|
-
await walk(viewsDir, "");
|
|
525
|
-
return discovered;
|
|
149
|
+
static clearCache() {
|
|
150
|
+
fileCache.clear();
|
|
151
|
+
resolveCache.clear();
|
|
526
152
|
}
|
|
527
153
|
}
|
|
528
154
|
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Plugin } from "vite";
|
|
2
|
+
|
|
3
|
+
export interface BluebirdVitePluginOptions {
|
|
4
|
+
base?: string;
|
|
5
|
+
outDir?: string;
|
|
6
|
+
clientOutDir?: string;
|
|
7
|
+
input?: string[];
|
|
8
|
+
/** Inject the Bluebird design tokens and component classes (`btn`, `card`, `field`, `badge`...). Default `true`. */
|
|
9
|
+
theme?: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function injectTheme(code: string, file: string, options?: { theme?: boolean }): string | null;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Bluebird Vite plugin for client SPA bundling and Tailwind CSS compilation.
|
|
16
|
+
*/
|
|
17
|
+
export default function bluebird(options?: BluebirdVitePluginOptions): Plugin;
|
|
18
|
+
export { bluebird };
|