@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.
Files changed (148) hide show
  1. package/AGENTS.md +726 -620
  2. package/README.md +615 -607
  3. package/app/models/user.js +19 -0
  4. package/app/resources/html/home.html +137 -0
  5. package/app/resources/html/layouts/main.html +54 -0
  6. package/app/resources/html/notFound.html +14 -0
  7. package/app/resources/html/terms.html +46 -0
  8. package/app/resources/index.html +27 -0
  9. package/app/resources/layouts/AppLayout.jsx +89 -0
  10. package/app/resources/main.jsx +18 -0
  11. package/app/resources/pages/Dashboard.jsx +98 -0
  12. package/app/resources/pages/Home.jsx +140 -0
  13. package/app/resources/pages/Login.jsx +35 -0
  14. package/app/resources/pages/NotFound.jsx +16 -0
  15. package/app/resources/pages/Register.jsx +55 -0
  16. package/app/resources/routes.jsx +54 -0
  17. package/app/resources/spa.js +67 -0
  18. package/app/resources/styles.css +9 -0
  19. package/app/routes/api.js +85 -50
  20. package/app/routes/auth.js +209 -0
  21. package/app/routes/web.js +59 -47
  22. package/core/ai.js +30 -10
  23. package/core/app.d.ts +2 -18
  24. package/core/app.js +987 -801
  25. package/core/auth.d.ts +2 -13
  26. package/core/auth.js +444 -326
  27. package/core/cli/build.js +37 -0
  28. package/core/cli/dev.js +155 -0
  29. package/core/cli/doctor.js +37 -2
  30. package/core/cli/export.js +191 -0
  31. package/core/cli/init.js +91 -322
  32. package/core/cli/nginx.js +1 -1
  33. package/core/cli/templates.js +139 -0
  34. package/core/cli/view.js +98 -161
  35. package/core/config.js +44 -2
  36. package/core/csrf.js +156 -24
  37. package/core/database.js +1184 -1131
  38. package/core/debug.js +1 -1
  39. package/core/html.js +8 -1
  40. package/core/index.d.ts +126 -310
  41. package/core/paths.js +55 -0
  42. package/core/ratelimit.js +10 -1
  43. package/core/react/client/api.js +237 -0
  44. package/core/react/client/auth.js +236 -0
  45. package/core/react/client/components.js +1321 -0
  46. package/core/react/client/i18n.js +338 -0
  47. package/core/react/client/index.d.ts +249 -0
  48. package/core/react/client/index.js +49 -0
  49. package/core/react/client/router.js +26 -0
  50. package/core/react/client/theme.css +512 -0
  51. package/core/render-cache.js +250 -212
  52. package/core/render.d.ts +25 -21
  53. package/core/render.js +738 -736
  54. package/core/router.d.ts +2 -3
  55. package/core/router.js +171 -171
  56. package/core/seo.js +10 -0
  57. package/core/spa.js +599 -0
  58. package/core/view-loader.js +155 -613
  59. package/core/vite-plugin.d.ts +18 -0
  60. package/core/vite-plugin.js +162 -0
  61. package/core/vite.js +250 -145
  62. package/index.js +22 -18
  63. package/jsconfig.json +5 -3
  64. package/package.json +114 -92
  65. package/production.md +8 -3
  66. package/public/js/bluebird.js +1160 -0
  67. package/templates/_auth/app/database.js +19 -0
  68. package/templates/_auth/app/models/user.js +22 -0
  69. package/templates/_auth/app/routes/auth-router.js +304 -0
  70. package/templates/_base/app/resources/html/layouts/main.html +55 -0
  71. package/templates/_base/app/resources/html/notFound.html +14 -0
  72. package/templates/_base/app/resources/index.html +27 -0
  73. package/templates/_base/app/resources/styles.css +9 -0
  74. package/templates/api/app/models/note.js +18 -0
  75. package/templates/api/app/routes/api.js +82 -0
  76. package/templates/api/app/routes/auth.js +11 -0
  77. package/templates/api/index.js +19 -0
  78. package/templates/api/template.json +13 -0
  79. package/templates/auth/app/mail.js +11 -0
  80. package/templates/auth/app/models/password_reset.js +18 -0
  81. package/templates/auth/app/resources/html/home.html +21 -0
  82. package/templates/auth/app/resources/html/partials/nav.html +2 -0
  83. package/templates/auth/app/resources/layouts/AppLayout.jsx +60 -0
  84. package/templates/auth/app/resources/main.jsx +18 -0
  85. package/templates/auth/app/resources/pages/Dashboard.jsx +51 -0
  86. package/templates/auth/app/resources/pages/ForgotPassword.jsx +34 -0
  87. package/templates/auth/app/resources/pages/Login.jsx +36 -0
  88. package/templates/auth/app/resources/pages/NotFound.jsx +16 -0
  89. package/templates/auth/app/resources/pages/Profile.jsx +99 -0
  90. package/templates/auth/app/resources/pages/Register.jsx +50 -0
  91. package/templates/auth/app/resources/pages/ResetPassword.jsx +50 -0
  92. package/templates/auth/app/resources/routes.jsx +54 -0
  93. package/templates/auth/app/resources/spa.js +29 -0
  94. package/templates/auth/app/routes/api.js +17 -0
  95. package/templates/auth/app/routes/auth.js +13 -0
  96. package/templates/auth/app/routes/web.js +21 -0
  97. package/templates/auth/index.js +19 -0
  98. package/templates/auth/template.json +15 -0
  99. package/templates/blank/app/models/.gitkeep +0 -0
  100. package/templates/blank/app/resources/html/home.html +27 -0
  101. package/templates/blank/app/resources/html/partials/nav.html +1 -0
  102. package/templates/blank/app/resources/main.jsx +16 -0
  103. package/templates/blank/app/resources/pages/Home.jsx +42 -0
  104. package/templates/blank/app/resources/pages/NotFound.jsx +27 -0
  105. package/templates/blank/app/resources/routes.jsx +15 -0
  106. package/templates/blank/app/resources/spa.js +24 -0
  107. package/templates/blank/app/routes/api.js +11 -0
  108. package/templates/blank/app/routes/web.js +21 -0
  109. package/templates/blank/index.js +13 -0
  110. package/templates/blank/template.json +12 -0
  111. package/templates/blog/app/lib/blog.js +149 -0
  112. package/templates/blog/app/models/post.js +22 -0
  113. package/templates/blog/app/resources/html/home.html +28 -0
  114. package/templates/blog/app/resources/html/not-found.html +5 -0
  115. package/templates/blog/app/resources/html/partials/nav.html +2 -0
  116. package/templates/blog/app/resources/html/partials/post-card.html +9 -0
  117. package/templates/blog/app/resources/html/post.html +8 -0
  118. package/templates/blog/app/resources/layouts/AdminLayout.jsx +54 -0
  119. package/templates/blog/app/resources/main.jsx +18 -0
  120. package/templates/blog/app/resources/pages/Login.jsx +31 -0
  121. package/templates/blog/app/resources/pages/NotFound.jsx +16 -0
  122. package/templates/blog/app/resources/pages/PostEditor.jsx +51 -0
  123. package/templates/blog/app/resources/pages/Posts.jsx +83 -0
  124. package/templates/blog/app/resources/pages/Register.jsx +43 -0
  125. package/templates/blog/app/resources/routes.jsx +51 -0
  126. package/templates/blog/app/resources/spa.js +25 -0
  127. package/templates/blog/app/resources/styles.css +40 -0
  128. package/templates/blog/app/routes/api.js +77 -0
  129. package/templates/blog/app/routes/auth.js +10 -0
  130. package/templates/blog/app/routes/web.js +114 -0
  131. package/templates/blog/index.js +21 -0
  132. package/templates/blog/template.json +14 -0
  133. package/vite.config.js +11 -0
  134. package/app/views/components/Header.jsx +0 -42
  135. package/app/views/components/LiveCounter.jsx +0 -67
  136. package/app/views/layouts/main/view.jsx +0 -201
  137. package/app/views/legal/terms.html +0 -29
  138. package/app/views/pages/about.jsx +0 -98
  139. package/app/views/pages/dashboard.jsx +0 -278
  140. package/app/views/pages/index.jsx +0 -123
  141. package/app/views/pages/login.jsx +0 -141
  142. package/core/actions.d.ts +0 -4
  143. package/core/actions.js +0 -355
  144. package/core/jsx.d.ts +0 -38
  145. package/core/jsx.js +0 -1597
  146. package/core/vite.d.ts +0 -3
  147. package/public/js/bluebird-client.js +0 -3265
  148. 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 Config from "./config.js";
4
-
5
- /**
6
- * Vite integration helper for Bluebird.js.
7
- * Handles React Refresh preamble, Vite HMR client in development,
8
- * and manifest.json asset resolution in production.
9
- */
10
- class Vite {
11
- /**
12
- * Cached production manifest data.
13
- * @type {Object|null}
14
- * @private
15
- */
16
- static _manifest = null;
17
-
18
- /**
19
- * Cached production head tags string.
20
- * @type {string|null}
21
- * @private
22
- */
23
- static _cachedProductionTags = null;
24
-
25
- /**
26
- * Clears the in-memory manifest cache.
27
- */
28
- static clearCache() {
29
- this._manifest = null;
30
- this._cachedProductionTags = null;
31
- }
32
-
33
- /**
34
- * Resolves the manifest file path.
35
- * @returns {string|null}
36
- * @private
37
- */
38
- static getManifestPath() {
39
- const root = Config.appDir();
40
- const viteManifest = path.join(root, "public/dist/.vite/manifest.json");
41
- if (fs.existsSync(viteManifest)) return viteManifest;
42
-
43
- const legacyManifest = path.join(root, "public/dist/manifest.json");
44
- if (fs.existsSync(legacyManifest)) return legacyManifest;
45
-
46
- return null;
47
- }
48
-
49
- /**
50
- * Loads the manifest JSON.
51
- * @returns {Object|null}
52
- * @private
53
- */
54
- static loadManifest() {
55
- if (this._manifest) return this._manifest;
56
-
57
- const manifestPath = this.getManifestPath();
58
- if (!manifestPath) return null;
59
-
60
- try {
61
- const raw = fs.readFileSync(manifestPath, "utf-8");
62
- this._manifest = JSON.parse(raw);
63
- return this._manifest;
64
- } catch {
65
- return null;
66
- }
67
- }
68
-
69
- /**
70
- * Returns HTML tags needed for Vite assets.
71
- * In development: injects Vite client and entry script.
72
- * In production: resolves hashed CSS and JS bundles from manifest.json.
73
- * @param {Object} [options={}]
74
- * @param {string} [options.entry="src/islands/main.jsx"] - Client entry point.
75
- * @param {string} [options.viteUrl] - Custom Vite dev server URL.
76
- * @param {boolean} [options.debug] - Development mode flag override.
77
- * @returns {string} HTML markup to place in <head>.
78
- */
79
- static tags(options = {}) {
80
- const props = Config.props();
81
- const isDebug = options.debug !== undefined ? Boolean(options.debug) : props.debug;
82
- const entry = options.entry || "src/islands/main.jsx";
83
-
84
- if (isDebug) {
85
- const viteUrl =
86
- options.viteUrl ||
87
- process.env.VITE_URL ||
88
- "http://localhost:5173";
89
- const cleanEntry = entry.startsWith("/") ? entry : `/${entry}`;
90
-
91
- return [
92
- `<script type="module">`,
93
- ` import RefreshRuntime from "${viteUrl}/@react-refresh";`,
94
- ` RefreshRuntime.injectIntoGlobalHook(window);`,
95
- ` window.$RefreshReg$ = () => {};`,
96
- ` window.$RefreshSig$ = () => (type) => type;`,
97
- ` window.__vite_plugin_react_preamble_installed__ = true;`,
98
- `</script>`,
99
- `<script type="module" src="${viteUrl}/@vite/client"></script>`,
100
- `<script type="module" src="${viteUrl}${cleanEntry}"></script>`,
101
- ].join("\n");
102
- }
103
-
104
- if (this._cachedProductionTags) {
105
- return this._cachedProductionTags;
106
- }
107
-
108
- const manifest = this.loadManifest();
109
- if (!manifest) {
110
- return "";
111
- }
112
-
113
- let entryChunk = manifest[entry];
114
- if (!entryChunk) {
115
- for (const key of Object.keys(manifest)) {
116
- if (manifest[key].isEntry) {
117
- entryChunk = manifest[key];
118
- break;
119
- }
120
- }
121
- }
122
-
123
- if (!entryChunk) {
124
- return "";
125
- }
126
-
127
- const tags = [];
128
-
129
- if (Array.isArray(entryChunk.css)) {
130
- for (const cssFile of entryChunk.css) {
131
- tags.push(`<link rel="stylesheet" href="/dist/${cssFile}">`);
132
- }
133
- }
134
-
135
- if (entryChunk.file) {
136
- tags.push(`<script type="module" src="/dist/${entryChunk.file}"></script>`);
137
- }
138
-
139
- this._cachedProductionTags = tags.join("\n");
140
- return this._cachedProductionTags;
141
- }
142
- }
143
-
144
- export { Vite };
145
- export default Vite;
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 routerWeb from "./app/routes/web.js";
4
-
5
- /**
6
- * Main entry point for the Blue Bird application.
7
- * Initializes the App instance with routes, configuration, and starts the server.
8
- */
9
- const app = new App({
10
- routes: [routerWeb, routerApi],
11
- cors: {},
12
- middlewares: [],
13
- host: "http://localhost",
14
- port: process.env.PORT || 3000,
15
- logger: false,
16
- });
17
-
18
- app.run();
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
  }