@seip/bluebird-js 0.1.7 → 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/AGENTS.md +726 -620
- package/README.md +615 -607
- 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 +59 -47
- package/core/ai.js +30 -10
- package/core/app.d.ts +2 -18
- package/core/app.js +987 -801
- package/core/auth.d.ts +2 -13
- package/core/auth.js +444 -326
- 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 +91 -322
- package/core/cli/nginx.js +1 -1
- package/core/cli/templates.js +139 -0
- package/core/cli/view.js +98 -161
- package/core/config.js +44 -2
- package/core/csrf.js +156 -24
- package/core/database.js +1184 -1131
- package/core/debug.js +1 -1
- package/core/html.js +8 -1
- package/core/index.d.ts +126 -310
- 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 +738 -736
- 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 +155 -613
- 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/components/Header.jsx +0 -42
- package/app/views/components/LiveCounter.jsx +0 -67
- package/app/views/layouts/main/view.jsx +0 -201
- package/app/views/legal/terms.html +0 -29
- package/app/views/pages/about.jsx +0 -98
- package/app/views/pages/dashboard.jsx +0 -278
- package/app/views/pages/index.jsx +0 -123
- package/app/views/pages/login.jsx +0 -141
- package/core/actions.d.ts +0 -4
- package/core/actions.js +0 -355
- package/core/jsx.d.ts +0 -38
- package/core/jsx.js +0 -1597
- package/core/vite.d.ts +0 -3
- package/public/js/bluebird-client.js +0 -3265
- package/public/js/tailwind.js +0 -8
|
@@ -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 };
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { PATHS } from "./paths.js";
|
|
5
|
+
|
|
6
|
+
const HERE = path.dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
const PACKAGE_ROOT = path.resolve(HERE, "..");
|
|
8
|
+
const CLIENT_DIR = path.join(HERE, "react/client");
|
|
9
|
+
const CLIENT_INDEX = path.join(CLIENT_DIR, "index.js");
|
|
10
|
+
const THEME_FILE = path.join(CLIENT_DIR, "theme.css");
|
|
11
|
+
const THEME_MARKER = "--color-primary: var(--primary)";
|
|
12
|
+
const TAILWIND_IMPORT = /@import\s+["']tailwindcss["'][^;]*;/;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Adds the Bluebird `@source` (React UI kit classes) and, unless disabled, the design tokens and component
|
|
16
|
+
* classes from `core/react/client/theme.css` right after `@import "tailwindcss"`, so the project's own
|
|
17
|
+
* `@theme` blocks and CSS variables declared later still override them.
|
|
18
|
+
* @param {string} code - Stylesheet source.
|
|
19
|
+
* @param {string} file - Absolute stylesheet path.
|
|
20
|
+
* @param {{ theme?: boolean }} [options={}]
|
|
21
|
+
* @returns {string|null} Transformed source, or `null` when nothing changes.
|
|
22
|
+
*/
|
|
23
|
+
export function injectTheme(code, file, options = {}) {
|
|
24
|
+
const match = TAILWIND_IMPORT.exec(code);
|
|
25
|
+
if (!match) return null;
|
|
26
|
+
let rel = path.relative(path.dirname(file), CLIENT_DIR).replace(/\\/g, "/");
|
|
27
|
+
if (!rel.startsWith(".")) rel = `./${rel}`;
|
|
28
|
+
const needsSource = !code.includes(rel);
|
|
29
|
+
const needsTheme = options.theme !== false && !code.includes(THEME_MARKER);
|
|
30
|
+
if (!needsSource && !needsTheme) return null;
|
|
31
|
+
const extra = [
|
|
32
|
+
needsSource ? `@source "${rel}";` : "",
|
|
33
|
+
needsTheme ? fs.readFileSync(THEME_FILE, "utf-8") : "",
|
|
34
|
+
]
|
|
35
|
+
.filter(Boolean)
|
|
36
|
+
.join("\n");
|
|
37
|
+
const end = match.index + match[0].length;
|
|
38
|
+
return `${code.slice(0, end)}\n${extra}\n${code.slice(end)}`;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Default Vite output paths relative to project root.
|
|
43
|
+
*/
|
|
44
|
+
export const BUILD_DIRS = {
|
|
45
|
+
client: "public/build",
|
|
46
|
+
base: "/build/",
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Resolves existing client entry and stylesheet files in a Bluebird project.
|
|
51
|
+
* @param {string} root - Project root directory.
|
|
52
|
+
* @param {string[]} [extra=[]] - Additional relative or absolute entry paths.
|
|
53
|
+
* @returns {string[]}
|
|
54
|
+
*/
|
|
55
|
+
export function resolveClientInputs(root, extra = []) {
|
|
56
|
+
const inputs = [];
|
|
57
|
+
const seen = new Set();
|
|
58
|
+
|
|
59
|
+
const add = (candidate) => {
|
|
60
|
+
const abs = path.isAbsolute(candidate) ? candidate : path.join(root, candidate);
|
|
61
|
+
if (fs.existsSync(abs) && !seen.has(abs)) {
|
|
62
|
+
seen.add(abs);
|
|
63
|
+
inputs.push(abs);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
for (const rel of PATHS.entries) {
|
|
68
|
+
const abs = path.join(root, rel);
|
|
69
|
+
if (fs.existsSync(abs)) {
|
|
70
|
+
add(abs);
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
for (const rel of PATHS.styles) {
|
|
76
|
+
const abs = path.join(root, rel);
|
|
77
|
+
if (fs.existsSync(abs)) {
|
|
78
|
+
add(abs);
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
for (const item of extra) {
|
|
84
|
+
if (item) add(item);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return inputs;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Bluebird Vite plugin for client-side React SPA bundling and Tailwind CSS compilation.
|
|
92
|
+
* Aliases `@seip/bluebird-js/react`, deduplicates React/React Router, configures client manifest builds,
|
|
93
|
+
* and registers the built-in React UI kit as a Tailwind `@source` in any stylesheet importing `tailwindcss`.
|
|
94
|
+
* @param {Object} [options={}]
|
|
95
|
+
* @param {string} [options.base="/build/"] - Public asset base path.
|
|
96
|
+
* @param {string} [options.outDir="public/build"] - Client build output directory.
|
|
97
|
+
* @param {string[]} [options.input=[]] - Extra Vite build entries.
|
|
98
|
+
* @param {boolean} [options.theme=true] - Inject the design tokens and component classes from `theme.css`.
|
|
99
|
+
* @returns {import('vite').Plugin}
|
|
100
|
+
*/
|
|
101
|
+
export default function bluebird(options = {}) {
|
|
102
|
+
return {
|
|
103
|
+
name: "bluebird",
|
|
104
|
+
enforce: "pre",
|
|
105
|
+
config(config, env) {
|
|
106
|
+
const root = path.resolve(config.root || process.cwd());
|
|
107
|
+
const extraInputs = Array.isArray(options.input) ? options.input : [];
|
|
108
|
+
const inputs = resolveClientInputs(root, extraInputs);
|
|
109
|
+
|
|
110
|
+
const out = {
|
|
111
|
+
appType: "custom",
|
|
112
|
+
resolve: {
|
|
113
|
+
alias: [
|
|
114
|
+
{ find: /^@seip\/bluebird-js\/react$/, replacement: CLIENT_INDEX },
|
|
115
|
+
],
|
|
116
|
+
dedupe: ["react", "react-dom", "react-router"],
|
|
117
|
+
},
|
|
118
|
+
optimizeDeps: {
|
|
119
|
+
entries: inputs.length > 0 ? inputs.map((file) => path.relative(root, file).replace(/\\/g, "/")) : undefined,
|
|
120
|
+
include: [
|
|
121
|
+
"react",
|
|
122
|
+
"react-dom",
|
|
123
|
+
"react-dom/client",
|
|
124
|
+
"react/jsx-runtime",
|
|
125
|
+
"react/jsx-dev-runtime",
|
|
126
|
+
"react-router",
|
|
127
|
+
"react-router/dom",
|
|
128
|
+
],
|
|
129
|
+
},
|
|
130
|
+
server: {
|
|
131
|
+
fs: {
|
|
132
|
+
allow: [root, PACKAGE_ROOT],
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
if (env.command === "build") {
|
|
138
|
+
const userBuild = config.build || {};
|
|
139
|
+
if (config.base === undefined) out.base = options.base || BUILD_DIRS.base;
|
|
140
|
+
if (config.publicDir === undefined) out.publicDir = false;
|
|
141
|
+
out.build = {
|
|
142
|
+
outDir: userBuild.outDir || options.outDir || options.clientOutDir || BUILD_DIRS.client,
|
|
143
|
+
emptyOutDir: userBuild.emptyOutDir ?? true,
|
|
144
|
+
manifest: userBuild.manifest ?? true,
|
|
145
|
+
};
|
|
146
|
+
if (!userBuild.rollupOptions?.input && inputs.length > 0) {
|
|
147
|
+
out.build.rollupOptions = { input: inputs };
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return out;
|
|
152
|
+
},
|
|
153
|
+
transform(code, id) {
|
|
154
|
+
const file = id.split("?")[0];
|
|
155
|
+
if (!file.endsWith(".css")) return null;
|
|
156
|
+
const out = injectTheme(code, file, { theme: options.theme });
|
|
157
|
+
return out === null ? null : { code: out, map: null };
|
|
158
|
+
},
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export { bluebird };
|
package/core/vite.js
CHANGED
|
@@ -1,145 +1,250 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
*
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
*
|
|
75
|
-
* @
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
import { escapeHtml } from "./html.js";
|
|
5
|
+
import Config from "./config.js";
|
|
6
|
+
import { BUILD_DIRS, resolveClientInputs } from "./vite-plugin.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Bridges Express and Vite for client-side React SPA bundles and Tailwind CSS assets.
|
|
10
|
+
* Runs Vite in middleware mode during development and reads `public/build/.vite/manifest.json` in production.
|
|
11
|
+
*/
|
|
12
|
+
export class ViteBridge {
|
|
13
|
+
/**
|
|
14
|
+
* Checks whether the project has Vite-managed frontend entries or a production build manifest.
|
|
15
|
+
* @param {string} [root]
|
|
16
|
+
* @returns {boolean}
|
|
17
|
+
*/
|
|
18
|
+
static needed(root = Config.appDir()) {
|
|
19
|
+
if (resolveClientInputs(root).length > 0) return true;
|
|
20
|
+
if (fs.existsSync(path.join(root, BUILD_DIRS.client, ".vite/manifest.json"))) return true;
|
|
21
|
+
for (const cfg of ["vite.config.js", "vite.config.mjs", "vite.config.ts"]) {
|
|
22
|
+
if (fs.existsSync(path.join(root, cfg))) return true;
|
|
23
|
+
}
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Retrieves the active ViteBridge instance attached to an Express app or request.
|
|
29
|
+
* @param {import('express').Request|import('express').Application|null} [target]
|
|
30
|
+
* @returns {ViteBridge|null}
|
|
31
|
+
*/
|
|
32
|
+
static from(target) {
|
|
33
|
+
if (!target) return null;
|
|
34
|
+
if (target.locals?._viteBridge) return target.locals._viteBridge;
|
|
35
|
+
if (target.app?.locals?._viteBridge) return target.app.locals._viteBridge;
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @param {Object} [options={}]
|
|
41
|
+
* @param {string} [options.root] - Project root directory.
|
|
42
|
+
* @param {boolean} [options.dev=false] - Prefer Vite dev middleware over build manifest.
|
|
43
|
+
* @param {string} [options.configFile] - Custom Vite configuration file path.
|
|
44
|
+
* @param {string} [options.base="/build/"] - Public URL prefix of built assets (`"./"` for static exports).
|
|
45
|
+
*/
|
|
46
|
+
constructor(options = {}) {
|
|
47
|
+
this.root = options.root || Config.appDir();
|
|
48
|
+
this.preferDev = Boolean(options.dev);
|
|
49
|
+
this.configFile = options.configFile;
|
|
50
|
+
this.base = options.base || BUILD_DIRS.base;
|
|
51
|
+
this.server = null;
|
|
52
|
+
this.manifest = null;
|
|
53
|
+
this.version = process.env.ASSET_VERSION || "";
|
|
54
|
+
this.mode = "dev";
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Returns the path to the Vite client build manifest.
|
|
59
|
+
* @returns {string}
|
|
60
|
+
*/
|
|
61
|
+
manifestPath() {
|
|
62
|
+
return path.join(this.root, BUILD_DIRS.client, ".vite/manifest.json");
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Checks whether a production client build manifest exists on disk.
|
|
67
|
+
* @returns {boolean}
|
|
68
|
+
*/
|
|
69
|
+
hasBuild() {
|
|
70
|
+
return fs.existsSync(this.manifestPath());
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Synchronously loads the production build manifest from disk when available.
|
|
75
|
+
* @returns {Object|null}
|
|
76
|
+
*/
|
|
77
|
+
loadManifestSync() {
|
|
78
|
+
if (this.manifest) return this.manifest;
|
|
79
|
+
if (!this.hasBuild()) return null;
|
|
80
|
+
try {
|
|
81
|
+
const raw = fs.readFileSync(this.manifestPath(), "utf-8");
|
|
82
|
+
this.manifest = JSON.parse(raw);
|
|
83
|
+
this.mode = "build";
|
|
84
|
+
return this.manifest;
|
|
85
|
+
} catch {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Resolves Vite configuration from `vite.config.*` or Bluebird defaults.
|
|
92
|
+
* Config files are loaded with Vite's in-memory module runner (`configLoader: "runner"`) instead of the
|
|
93
|
+
* default bundler, which writes `node_modules/.vite-temp/vite.config.js.timestamp-*.mjs` on every start and
|
|
94
|
+
* makes `node --watch` restart the server in an endless loop.
|
|
95
|
+
* @returns {Promise<Object>}
|
|
96
|
+
*/
|
|
97
|
+
async inlineConfig() {
|
|
98
|
+
const candidates = [this.configFile, "vite.config.js", "vite.config.mjs", "vite.config.ts"].filter(Boolean);
|
|
99
|
+
const found = candidates.map((c) => path.resolve(this.root, c)).find((c) => fs.existsSync(c));
|
|
100
|
+
if (found) {
|
|
101
|
+
return { root: this.root, configFile: found, configLoader: process.env.VITE_CONFIG_LOADER || "runner" };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const { default: bluebird } = await import("./vite-plugin.js");
|
|
105
|
+
const plugins = [bluebird()];
|
|
106
|
+
try {
|
|
107
|
+
const { default: react } = await import("@vitejs/plugin-react");
|
|
108
|
+
plugins.push(react());
|
|
109
|
+
} catch {}
|
|
110
|
+
try {
|
|
111
|
+
const { default: tailwindcss } = await import("@tailwindcss/vite");
|
|
112
|
+
plugins.push(tailwindcss());
|
|
113
|
+
} catch {}
|
|
114
|
+
return { root: this.root, configFile: false, plugins };
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Initializes the Vite dev middleware or loads the production build manifest.
|
|
119
|
+
* @param {import('express').Express} app
|
|
120
|
+
* @param {import('http').Server} [httpServer]
|
|
121
|
+
* @returns {Promise<void>}
|
|
122
|
+
*/
|
|
123
|
+
async init(app, httpServer) {
|
|
124
|
+
if (!this.preferDev && this.hasBuild()) {
|
|
125
|
+
this.mode = "build";
|
|
126
|
+
const raw = fs.readFileSync(this.manifestPath(), "utf-8");
|
|
127
|
+
this.manifest = JSON.parse(raw);
|
|
128
|
+
if (!this.version) {
|
|
129
|
+
this.version = createHash("sha256").update(raw).digest("hex").slice(0, 12);
|
|
130
|
+
}
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (!this.preferDev && resolveClientInputs(this.root).length > 0) {
|
|
135
|
+
console.warn(
|
|
136
|
+
"[BLUEBIRD VITE] No production build found (public/build). Running Vite dev middleware — run `npx bluebird-js build` before deploying."
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
this.mode = "dev";
|
|
141
|
+
if (!this.version) this.version = "dev";
|
|
142
|
+
const { createServer } = await import("vite");
|
|
143
|
+
const config = await this.inlineConfig();
|
|
144
|
+
const hmrAttached = Boolean(this.preferDev && httpServer);
|
|
145
|
+
this.server = await createServer({
|
|
146
|
+
...config,
|
|
147
|
+
appType: "custom",
|
|
148
|
+
logLevel: process.env.VITE_LOG_LEVEL || "warn",
|
|
149
|
+
server: {
|
|
150
|
+
middlewareMode: true,
|
|
151
|
+
hmr: hmrAttached ? { server: httpServer } : false,
|
|
152
|
+
ws: hmrAttached,
|
|
153
|
+
watch: this.preferDev ? undefined : null,
|
|
154
|
+
},
|
|
155
|
+
});
|
|
156
|
+
app.use(this.server.middlewares);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Resolves `<link>` and `<script>` tags for one or more Vite asset entries.
|
|
161
|
+
* @param {string|string[]} entries - Entry paths relative to project root (e.g. `"app/resources/styles.css"`).
|
|
162
|
+
* @returns {{ head: string, body: string, all: string }}
|
|
163
|
+
*/
|
|
164
|
+
assetTags(entries = []) {
|
|
165
|
+
const list = (Array.isArray(entries) ? entries : [entries])
|
|
166
|
+
.filter(Boolean)
|
|
167
|
+
.map((e) => String(e).replace(/^\/+/, "").replace(/\\/g, "/"));
|
|
168
|
+
|
|
169
|
+
if (list.length === 0) return { head: "", body: "", all: "" };
|
|
170
|
+
|
|
171
|
+
if (this.mode === "dev" || !this.manifest) {
|
|
172
|
+
const headTags = [];
|
|
173
|
+
const bodyTags = [];
|
|
174
|
+
for (const rel of list) {
|
|
175
|
+
if (/\.(css|scss|sass|less|styl)$/i.test(rel)) {
|
|
176
|
+
headTags.push(`<link rel="stylesheet" href="/${escapeHtml(rel)}">`);
|
|
177
|
+
} else {
|
|
178
|
+
bodyTags.push(`<script type="module" src="/${escapeHtml(rel)}"></script>`);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
const head = headTags.join("\n ");
|
|
182
|
+
const body = bodyTags.join("\n ");
|
|
183
|
+
return { head, body, all: [head, body].filter(Boolean).join("\n ") };
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const manifest = this.manifest;
|
|
187
|
+
const base = this.base;
|
|
188
|
+
const css = new Set();
|
|
189
|
+
const preloads = new Set();
|
|
190
|
+
const scripts = new Set();
|
|
191
|
+
|
|
192
|
+
const visit = (key, isRoot = false, seen = new Set()) => {
|
|
193
|
+
if (seen.has(key)) return;
|
|
194
|
+
seen.add(key);
|
|
195
|
+
const chunk = manifest[key];
|
|
196
|
+
if (!chunk) return;
|
|
197
|
+
if (chunk.file.endsWith(".css")) {
|
|
198
|
+
css.add(chunk.file);
|
|
199
|
+
} else if (isRoot) {
|
|
200
|
+
scripts.add(chunk.file);
|
|
201
|
+
} else {
|
|
202
|
+
preloads.add(chunk.file);
|
|
203
|
+
}
|
|
204
|
+
for (const c of chunk.css || []) css.add(c);
|
|
205
|
+
for (const imp of chunk.imports || []) visit(imp, false, seen);
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
for (const rel of list) {
|
|
209
|
+
if (manifest[rel]) {
|
|
210
|
+
visit(rel, true);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const headTags = [
|
|
215
|
+
...[...css].map((f) => `<link rel="stylesheet" href="${base}${escapeHtml(f)}">`),
|
|
216
|
+
...[...preloads].map((f) => `<link rel="modulepreload" href="${base}${escapeHtml(f)}">`),
|
|
217
|
+
];
|
|
218
|
+
const bodyTags = [...scripts].map(
|
|
219
|
+
(f) => `<script type="module" src="${base}${escapeHtml(f)}"></script>`
|
|
220
|
+
);
|
|
221
|
+
|
|
222
|
+
const head = headTags.join("\n ");
|
|
223
|
+
const body = bodyTags.join("\n ");
|
|
224
|
+
return { head, body, all: [head, body].filter(Boolean).join("\n ") };
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Applies Vite HTML transforms in development mode (Vite client and React Fast Refresh preamble).
|
|
229
|
+
* @param {string} url
|
|
230
|
+
* @param {string} htmlStr
|
|
231
|
+
* @returns {Promise<string>}
|
|
232
|
+
*/
|
|
233
|
+
async transformHtml(url, htmlStr) {
|
|
234
|
+
if (this.mode !== "dev" || !this.server) return htmlStr;
|
|
235
|
+
return this.server.transformIndexHtml(url, htmlStr);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Closes the underlying Vite dev server if active.
|
|
240
|
+
* @returns {Promise<void>}
|
|
241
|
+
*/
|
|
242
|
+
async close() {
|
|
243
|
+
if (this.server) {
|
|
244
|
+
await this.server.close();
|
|
245
|
+
this.server = null;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export default ViteBridge;
|
package/index.js
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
|
-
import App from "@seip/bluebird-js/core/app.js";
|
|
2
|
-
import routerApi from "./app/routes/api.js";
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
*
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
import App from "@seip/bluebird-js/core/app.js";
|
|
2
|
+
import routerApi from "./app/routes/api.js";
|
|
3
|
+
import routerAuth from "./app/routes/auth.js";
|
|
4
|
+
import routerWeb from "./app/routes/web.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Main entrypoint for the Bluebird.js application.
|
|
8
|
+
* HTML SSR templates live in `app/resources/html/`, while the React SPA lives in `app/resources/`.
|
|
9
|
+
*/
|
|
10
|
+
const app = new App({
|
|
11
|
+
routes: [routerWeb, routerAuth, routerApi],
|
|
12
|
+
cors: {},
|
|
13
|
+
security: true,
|
|
14
|
+
host: "http://0.0.0.0",
|
|
15
|
+
port: Number(
|
|
16
|
+
process.env.APP_PORT ||
|
|
17
|
+
(process.env.PORT && process.env.PORT !== "8080" ? process.env.PORT : 3000)
|
|
18
|
+
),
|
|
19
|
+
logger: false,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
app.run();
|
package/jsconfig.json
CHANGED
|
@@ -4,12 +4,14 @@
|
|
|
4
4
|
"module": "NodeNext",
|
|
5
5
|
"moduleResolution": "NodeNext",
|
|
6
6
|
"checkJs": false,
|
|
7
|
-
"allowJs": true
|
|
7
|
+
"allowJs": true,
|
|
8
|
+
"jsx": "react-jsx"
|
|
8
9
|
},
|
|
9
10
|
"include": [
|
|
10
|
-
"public/**/*",
|
|
11
11
|
"app/**/*",
|
|
12
12
|
"core/**/*",
|
|
13
|
-
"test/**/*"
|
|
13
|
+
"test/**/*",
|
|
14
|
+
"index.js",
|
|
15
|
+
"vite.config.js"
|
|
14
16
|
]
|
|
15
17
|
}
|