@seip/bluebird-js 0.1.2 → 0.1.5
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 -0
- package/.vscode/settings.json +10 -0
- package/AGENTS.md +495 -454
- package/README.md +528 -353
- package/app/routes/web.js +47 -55
- package/app/views/about.jsx +98 -0
- package/app/views/components/Header.jsx +42 -0
- package/app/views/components/LiveCounter.jsx +66 -0
- package/app/views/dashboard.jsx +300 -0
- package/app/views/index.jsx +123 -0
- package/app/views/layouts/main/view.jsx +201 -0
- package/app/views/legal/terms.html +29 -19
- package/app/views/login.jsx +141 -0
- package/core/actions.d.ts +4 -0
- package/core/actions.js +329 -0
- package/core/app.js +38 -6
- package/core/cli/doctor.js +3 -4
- package/core/cli/init.js +20 -6
- package/core/cli/migrate.js +418 -145
- package/core/cli/view.js +76 -11
- package/core/database.js +6 -10
- package/core/debug.js +1 -1
- package/core/html.d.ts +54 -42
- package/core/html.js +473 -217
- package/core/index.d.ts +1385 -1190
- package/core/jsx.d.ts +38 -0
- package/core/jsx.js +1432 -0
- package/core/model.js +271 -61
- package/core/render-cache.js +212 -212
- package/core/render.d.ts +20 -2
- package/core/render.js +459 -51
- package/core/validate.js +1 -1
- package/core/view-loader.js +360 -24
- package/package.json +9 -3
- package/public/js/bluebird-client.js +3160 -1780
- package/public/js/tailwind.js +8 -0
- package/app/views/about.js +0 -63
- package/app/views/dashboard.js +0 -147
- package/app/views/index.js +0 -80
- package/app/views/layouts/main/view.js +0 -81
- package/app/views/login.js +0 -80
- package/public/css/bluebird.min.css +0 -2
- package/public/js/bluebird.min.js +0 -1073
package/core/validate.js
CHANGED
|
@@ -215,7 +215,7 @@ class Validator {
|
|
|
215
215
|
messages.push(errorMsg);
|
|
216
216
|
errors.push({ field, message: errorMsg });
|
|
217
217
|
}
|
|
218
|
-
if (config.number && !validators.isNumeric(value)) {
|
|
218
|
+
if ((config.number || config.numeric) && !validators.isNumeric(value)) {
|
|
219
219
|
const errorMsg = config.messages?.number || msg.number(field);
|
|
220
220
|
messages.push(errorMsg);
|
|
221
221
|
errors.push({ field, message: errorMsg });
|
package/core/view-loader.js
CHANGED
|
@@ -2,6 +2,10 @@ import fs from "node:fs";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { pathToFileURL } from "node:url";
|
|
4
4
|
import Config from "./config.js";
|
|
5
|
+
import html from "./html.js";
|
|
6
|
+
import { compileJsx, registerJsxLoader, stripTsTypes } from "./jsx.js";
|
|
7
|
+
|
|
8
|
+
registerJsxLoader();
|
|
5
9
|
|
|
6
10
|
const props = Config.props();
|
|
7
11
|
const DEBUG = props.debug;
|
|
@@ -33,8 +37,109 @@ function isSafePath(candidatePath) {
|
|
|
33
37
|
}
|
|
34
38
|
|
|
35
39
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
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
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Loads a JavaScript or React JSX view module with development cache-busting, .asar unpacked fallback,
|
|
142
|
+
* zero-disk in-memory JSX compilation, or production memoization.
|
|
38
143
|
* @param {string} absolutePath
|
|
39
144
|
* @returns {Promise<Object>}
|
|
40
145
|
*/
|
|
@@ -51,20 +156,48 @@ async function importModule(absolutePath) {
|
|
|
51
156
|
}
|
|
52
157
|
}
|
|
53
158
|
|
|
54
|
-
const
|
|
55
|
-
const
|
|
56
|
-
const
|
|
159
|
+
const isJsxFile = targetPath.endsWith(".jsx");
|
|
160
|
+
const isTsxFile = targetPath.endsWith(".tsx");
|
|
161
|
+
const isTsFile = targetPath.endsWith(".ts");
|
|
162
|
+
const isJsxOrTsx = isJsxFile || isTsxFile;
|
|
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));
|
|
57
165
|
|
|
58
166
|
let mod;
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
+
}
|
|
68
201
|
}
|
|
69
202
|
}
|
|
70
203
|
|
|
@@ -76,8 +209,8 @@ async function importModule(absolutePath) {
|
|
|
76
209
|
|
|
77
210
|
/**
|
|
78
211
|
* View loader and resolver for Bluebird.js.
|
|
79
|
-
* Resolves modular directory views (e.g. "dashboard/view.js"),
|
|
80
|
-
* components, and layouts.
|
|
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.
|
|
81
214
|
*/
|
|
82
215
|
export class ViewLoader {
|
|
83
216
|
/**
|
|
@@ -90,29 +223,65 @@ export class ViewLoader {
|
|
|
90
223
|
|
|
91
224
|
/**
|
|
92
225
|
* Resolves and loads a view by name.
|
|
93
|
-
* Searches
|
|
94
|
-
*
|
|
226
|
+
* Searches React JSX (.jsx) and JS (.js) conventions first, then subdirectories,
|
|
227
|
+
* and finally static HTML files.
|
|
95
228
|
*
|
|
96
229
|
* @param {string} viewName - Logical view identifier.
|
|
97
|
-
* @returns {Promise<{type: "js"|"html", module?: Object, filePath: string, content?: string}|null>}
|
|
230
|
+
* @returns {Promise<{type: "jsx"|"js"|"html", module?: Object, filePath: string, content?: string}|null>}
|
|
98
231
|
*/
|
|
99
232
|
static async load(viewName) {
|
|
100
233
|
if (!viewName || typeof viewName !== "string") {
|
|
101
234
|
return null;
|
|
102
235
|
}
|
|
103
236
|
|
|
104
|
-
|
|
237
|
+
await autoRegisterComponents();
|
|
238
|
+
|
|
239
|
+
const clean = viewName.replace(/^\/+/, "").replace(/\.(jsx|js|html|ejs)$/, "");
|
|
105
240
|
|
|
106
241
|
const candidates = [
|
|
242
|
+
`${clean}.tsx`,
|
|
243
|
+
`${clean}.jsx`,
|
|
244
|
+
`${clean}.ts`,
|
|
107
245
|
`${clean}.js`,
|
|
246
|
+
`${clean}/view.tsx`,
|
|
247
|
+
`${clean}/view.jsx`,
|
|
248
|
+
`${clean}/view.ts`,
|
|
108
249
|
`${clean}/view.js`,
|
|
250
|
+
path.join("pages", `${clean}.tsx`),
|
|
251
|
+
path.join("pages", `${clean}.jsx`),
|
|
252
|
+
path.join("pages", `${clean}.ts`),
|
|
109
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`),
|
|
110
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`),
|
|
111
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`),
|
|
112
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`),
|
|
113
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`),
|
|
114
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`),
|
|
115
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`),
|
|
116
285
|
path.join("layouts", `${clean}.js`),
|
|
117
286
|
`${clean}.html`,
|
|
118
287
|
path.join("pages", `${clean}.html`),
|
|
@@ -127,7 +296,12 @@ export class ViewLoader {
|
|
|
127
296
|
|
|
128
297
|
const fullPath = path.resolve(viewsDir, candidate);
|
|
129
298
|
if (fs.existsSync(fullPath)) {
|
|
130
|
-
if (candidate.endsWith(".
|
|
299
|
+
if (candidate.endsWith(".jsx") || candidate.endsWith(".tsx")) {
|
|
300
|
+
const mod = await importModule(fullPath);
|
|
301
|
+
return { type: "jsx", module: mod, filePath: fullPath };
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
if (candidate.endsWith(".js") || candidate.endsWith(".ts")) {
|
|
131
305
|
const mod = await importModule(fullPath);
|
|
132
306
|
return { type: "js", module: mod, filePath: fullPath };
|
|
133
307
|
}
|
|
@@ -147,16 +321,28 @@ export class ViewLoader {
|
|
|
147
321
|
* Defaults to searching in app/views/layouts/.
|
|
148
322
|
*
|
|
149
323
|
* @param {string} layoutName - Layout name (e.g. "main").
|
|
150
|
-
* @returns {Promise<{type: "js"|"html", module?: Object, filePath: string, content?: string}|null>}
|
|
324
|
+
* @returns {Promise<{type: "jsx"|"js"|"html", module?: Object, filePath: string, content?: string}|null>}
|
|
151
325
|
*/
|
|
152
326
|
static async loadLayout(layoutName) {
|
|
153
327
|
if (!layoutName) return null;
|
|
154
|
-
const clean = layoutName.replace(/^\/+/, "").replace(/\.(js|html)$/, "");
|
|
328
|
+
const clean = layoutName.replace(/^\/+/, "").replace(/\.(jsx|tsx|js|ts|html)$/, "");
|
|
155
329
|
|
|
156
330
|
const candidates = [
|
|
331
|
+
path.join("layouts", `${clean}/view.tsx`),
|
|
332
|
+
path.join("layouts", `${clean}/view.jsx`),
|
|
333
|
+
path.join("layouts", `${clean}/view.ts`),
|
|
157
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`),
|
|
158
338
|
path.join("layouts", `${clean}.js`),
|
|
339
|
+
`${clean}/view.tsx`,
|
|
340
|
+
`${clean}/view.jsx`,
|
|
341
|
+
`${clean}/view.ts`,
|
|
159
342
|
`${clean}/view.js`,
|
|
343
|
+
`${clean}.tsx`,
|
|
344
|
+
`${clean}.jsx`,
|
|
345
|
+
`${clean}.ts`,
|
|
160
346
|
`${clean}.js`,
|
|
161
347
|
path.join("layouts", `${clean}.html`),
|
|
162
348
|
];
|
|
@@ -167,7 +353,12 @@ export class ViewLoader {
|
|
|
167
353
|
|
|
168
354
|
const fullPath = path.resolve(viewsDir, candidate);
|
|
169
355
|
if (fs.existsSync(fullPath)) {
|
|
170
|
-
if (candidate.endsWith(".
|
|
356
|
+
if (candidate.endsWith(".jsx") || candidate.endsWith(".tsx")) {
|
|
357
|
+
const mod = await importModule(fullPath);
|
|
358
|
+
return { type: "jsx", module: mod, filePath: fullPath };
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
if (candidate.endsWith(".js") || candidate.endsWith(".ts")) {
|
|
171
362
|
const mod = await importModule(fullPath);
|
|
172
363
|
return { type: "js", module: mod, filePath: fullPath };
|
|
173
364
|
}
|
|
@@ -188,6 +379,151 @@ export class ViewLoader {
|
|
|
188
379
|
static clearCache() {
|
|
189
380
|
moduleCache.clear();
|
|
190
381
|
}
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Scans `app/views/` (excluding `layouts`, `components`, `partials`, `islands`, and `api`)
|
|
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}>>}
|
|
395
|
+
*/
|
|
396
|
+
static async discoverRoutes() {
|
|
397
|
+
const viewsDir = getViewsDir();
|
|
398
|
+
if (!fs.existsSync(viewsDir)) return [];
|
|
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;
|
|
526
|
+
}
|
|
191
527
|
}
|
|
192
528
|
|
|
193
529
|
export default ViewLoader;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seip/bluebird-js",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Performance-first Node.js API and web framework with built-in JWT auth, HTML rendering, validation, BaseModel, and multi-level caching",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "core/app.js",
|
|
@@ -27,12 +27,17 @@
|
|
|
27
27
|
"keywords": [
|
|
28
28
|
"express",
|
|
29
29
|
"framework",
|
|
30
|
+
"react",
|
|
31
|
+
"jsx",
|
|
32
|
+
"ssr",
|
|
30
33
|
"html",
|
|
31
34
|
"api",
|
|
32
35
|
"jwt",
|
|
33
36
|
"render",
|
|
34
37
|
"seo",
|
|
35
|
-
"model"
|
|
38
|
+
"model",
|
|
39
|
+
"sqlite",
|
|
40
|
+
"tailwind"
|
|
36
41
|
],
|
|
37
42
|
"author": "Seip25",
|
|
38
43
|
"license": "MIT",
|
|
@@ -68,7 +73,8 @@
|
|
|
68
73
|
"AGENTS.md",
|
|
69
74
|
"production.md",
|
|
70
75
|
".env_example",
|
|
71
|
-
"jsconfig.json"
|
|
76
|
+
"jsconfig.json",
|
|
77
|
+
".vscode"
|
|
72
78
|
],
|
|
73
79
|
"dependencies": {
|
|
74
80
|
"express": "^5.2.1"
|