@seip/bluebird-js 0.1.7 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (151) hide show
  1. package/AGENTS.md +727 -620
  2. package/README.md +670 -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 +55 -0
  6. package/app/resources/html/notFound.html +14 -0
  7. package/app/resources/html/table.html +15 -0
  8. package/app/resources/html/terms.html +46 -0
  9. package/app/resources/index.html +27 -0
  10. package/app/resources/layouts/AppLayout.jsx +92 -0
  11. package/app/resources/main.jsx +18 -0
  12. package/app/resources/pages/Dashboard.jsx +93 -0
  13. package/app/resources/pages/Home.jsx +140 -0
  14. package/app/resources/pages/Login.jsx +35 -0
  15. package/app/resources/pages/NotFound.jsx +16 -0
  16. package/app/resources/pages/Register.jsx +55 -0
  17. package/app/resources/pages/TableDemo.jsx +85 -0
  18. package/app/resources/routes.jsx +59 -0
  19. package/app/resources/spa.js +73 -0
  20. package/app/resources/styles.css +9 -0
  21. package/app/routes/api.js +129 -50
  22. package/app/routes/auth.js +209 -0
  23. package/app/routes/web.js +89 -47
  24. package/core/ai.js +30 -10
  25. package/core/app.d.ts +2 -18
  26. package/core/app.js +987 -801
  27. package/core/auth.d.ts +2 -13
  28. package/core/auth.js +444 -326
  29. package/core/cli/build.js +37 -0
  30. package/core/cli/dev.js +155 -0
  31. package/core/cli/doctor.js +37 -2
  32. package/core/cli/export.js +191 -0
  33. package/core/cli/init.js +91 -322
  34. package/core/cli/nginx.js +1 -1
  35. package/core/cli/templates.js +139 -0
  36. package/core/cli/view.js +98 -161
  37. package/core/config.js +44 -2
  38. package/core/csrf.js +156 -24
  39. package/core/database.js +1184 -1131
  40. package/core/debug.js +1 -1
  41. package/core/html.js +8 -1
  42. package/core/index.d.ts +126 -310
  43. package/core/paths.js +55 -0
  44. package/core/ratelimit.js +10 -1
  45. package/core/react/client/api.js +239 -0
  46. package/core/react/client/auth.js +236 -0
  47. package/core/react/client/components.js +1321 -0
  48. package/core/react/client/datatable.js +595 -0
  49. package/core/react/client/i18n.js +440 -0
  50. package/core/react/client/index.d.ts +314 -0
  51. package/core/react/client/index.js +50 -0
  52. package/core/react/client/router.js +26 -0
  53. package/core/react/client/theme.css +512 -0
  54. package/core/render-cache.js +250 -212
  55. package/core/render.d.ts +25 -21
  56. package/core/render.js +738 -736
  57. package/core/router.d.ts +2 -3
  58. package/core/router.js +171 -171
  59. package/core/seo.js +10 -0
  60. package/core/spa.js +599 -0
  61. package/core/view-loader.js +155 -613
  62. package/core/vite-plugin.d.ts +18 -0
  63. package/core/vite-plugin.js +162 -0
  64. package/core/vite.js +250 -145
  65. package/index.js +22 -18
  66. package/jsconfig.json +5 -3
  67. package/package.json +114 -92
  68. package/production.md +8 -3
  69. package/public/js/bluebird.js +1886 -0
  70. package/templates/_auth/app/database.js +19 -0
  71. package/templates/_auth/app/models/user.js +22 -0
  72. package/templates/_auth/app/routes/auth-router.js +304 -0
  73. package/templates/_base/app/resources/html/layouts/main.html +55 -0
  74. package/templates/_base/app/resources/html/notFound.html +14 -0
  75. package/templates/_base/app/resources/index.html +27 -0
  76. package/templates/_base/app/resources/styles.css +9 -0
  77. package/templates/api/app/models/note.js +18 -0
  78. package/templates/api/app/routes/api.js +82 -0
  79. package/templates/api/app/routes/auth.js +11 -0
  80. package/templates/api/index.js +19 -0
  81. package/templates/api/template.json +13 -0
  82. package/templates/auth/app/mail.js +11 -0
  83. package/templates/auth/app/models/password_reset.js +18 -0
  84. package/templates/auth/app/resources/html/home.html +21 -0
  85. package/templates/auth/app/resources/html/partials/nav.html +2 -0
  86. package/templates/auth/app/resources/layouts/AppLayout.jsx +60 -0
  87. package/templates/auth/app/resources/main.jsx +18 -0
  88. package/templates/auth/app/resources/pages/Dashboard.jsx +51 -0
  89. package/templates/auth/app/resources/pages/ForgotPassword.jsx +34 -0
  90. package/templates/auth/app/resources/pages/Login.jsx +36 -0
  91. package/templates/auth/app/resources/pages/NotFound.jsx +16 -0
  92. package/templates/auth/app/resources/pages/Profile.jsx +99 -0
  93. package/templates/auth/app/resources/pages/Register.jsx +50 -0
  94. package/templates/auth/app/resources/pages/ResetPassword.jsx +50 -0
  95. package/templates/auth/app/resources/routes.jsx +54 -0
  96. package/templates/auth/app/resources/spa.js +29 -0
  97. package/templates/auth/app/routes/api.js +17 -0
  98. package/templates/auth/app/routes/auth.js +13 -0
  99. package/templates/auth/app/routes/web.js +21 -0
  100. package/templates/auth/index.js +19 -0
  101. package/templates/auth/template.json +15 -0
  102. package/templates/blank/app/models/.gitkeep +0 -0
  103. package/templates/blank/app/resources/html/home.html +27 -0
  104. package/templates/blank/app/resources/html/partials/nav.html +1 -0
  105. package/templates/blank/app/resources/main.jsx +16 -0
  106. package/templates/blank/app/resources/pages/Home.jsx +42 -0
  107. package/templates/blank/app/resources/pages/NotFound.jsx +27 -0
  108. package/templates/blank/app/resources/routes.jsx +15 -0
  109. package/templates/blank/app/resources/spa.js +24 -0
  110. package/templates/blank/app/routes/api.js +11 -0
  111. package/templates/blank/app/routes/web.js +21 -0
  112. package/templates/blank/index.js +13 -0
  113. package/templates/blank/template.json +12 -0
  114. package/templates/blog/app/lib/blog.js +149 -0
  115. package/templates/blog/app/models/post.js +22 -0
  116. package/templates/blog/app/resources/html/home.html +28 -0
  117. package/templates/blog/app/resources/html/not-found.html +5 -0
  118. package/templates/blog/app/resources/html/partials/nav.html +2 -0
  119. package/templates/blog/app/resources/html/partials/post-card.html +9 -0
  120. package/templates/blog/app/resources/html/post.html +8 -0
  121. package/templates/blog/app/resources/layouts/AdminLayout.jsx +54 -0
  122. package/templates/blog/app/resources/main.jsx +18 -0
  123. package/templates/blog/app/resources/pages/Login.jsx +31 -0
  124. package/templates/blog/app/resources/pages/NotFound.jsx +16 -0
  125. package/templates/blog/app/resources/pages/PostEditor.jsx +51 -0
  126. package/templates/blog/app/resources/pages/Posts.jsx +83 -0
  127. package/templates/blog/app/resources/pages/Register.jsx +43 -0
  128. package/templates/blog/app/resources/routes.jsx +51 -0
  129. package/templates/blog/app/resources/spa.js +25 -0
  130. package/templates/blog/app/resources/styles.css +40 -0
  131. package/templates/blog/app/routes/api.js +77 -0
  132. package/templates/blog/app/routes/auth.js +10 -0
  133. package/templates/blog/app/routes/web.js +114 -0
  134. package/templates/blog/index.js +21 -0
  135. package/templates/blog/template.json +14 -0
  136. package/vite.config.js +11 -0
  137. package/app/views/components/Header.jsx +0 -42
  138. package/app/views/components/LiveCounter.jsx +0 -67
  139. package/app/views/layouts/main/view.jsx +0 -201
  140. package/app/views/legal/terms.html +0 -29
  141. package/app/views/pages/about.jsx +0 -98
  142. package/app/views/pages/dashboard.jsx +0 -278
  143. package/app/views/pages/index.jsx +0 -123
  144. package/app/views/pages/login.jsx +0 -141
  145. package/core/actions.d.ts +0 -4
  146. package/core/actions.js +0 -355
  147. package/core/jsx.d.ts +0 -38
  148. package/core/jsx.js +0 -1597
  149. package/core/vite.d.ts +0 -3
  150. package/public/js/bluebird-client.js +0 -3265
  151. package/public/js/tailwind.js +0 -8
@@ -0,0 +1,139 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+
4
+ const TEMPLATE_TOKEN = /%%APP_TITLE%%/g;
5
+ const TEXT_EXTENSIONS = new Set([".js", ".jsx", ".mjs", ".json", ".html", ".css", ".md", ".txt"]);
6
+ const DEMO_TEMPLATE = {
7
+ name: "demo",
8
+ description: "Full showcase (carousel, toasts, tasks, SSE, login/register) used to develop the framework itself",
9
+ demo: true,
10
+ client: true,
11
+ database: "optional",
12
+ routes: ["/ HTML {{ }} landing", "/app/* React SPA demo"],
13
+ };
14
+
15
+ /**
16
+ * Reads the template name from `--template <name>`, `--template=<name>`, or a shorthand flag (`--auth`, `--blog`...).
17
+ * Shorthand flags only match names in `known`, so other flags (`--yes`, `--title`) are never read as templates.
18
+ * @param {string[]} argv
19
+ * @param {string[]} known - Available template names.
20
+ * @returns {string|null}
21
+ */
22
+ export function parseTemplateArg(argv, known) {
23
+ for (let i = 0; i < argv.length; i++) {
24
+ const arg = argv[i];
25
+ if ((arg === "--template" || arg === "-t") && argv[i + 1]) return argv[i + 1].toLowerCase();
26
+ if (arg.startsWith("--template=")) return arg.slice(11).toLowerCase();
27
+ }
28
+ const shorthand = argv.find((arg) => arg.startsWith("--") && known.includes(arg.slice(2).toLowerCase()));
29
+ return shorthand ? shorthand.slice(2).toLowerCase() : null;
30
+ }
31
+
32
+ /**
33
+ * Reads the value of a `--name <value>` or `--name=<value>` flag.
34
+ * @param {string[]} argv
35
+ * @param {string} name - Flag name without dashes.
36
+ * @returns {string|null}
37
+ */
38
+ export function readFlag(argv, name) {
39
+ for (let i = 0; i < argv.length; i++) {
40
+ if (argv[i] === `--${name}` && argv[i + 1] && !argv[i + 1].startsWith("--")) return argv[i + 1];
41
+ if (argv[i].startsWith(`--${name}=`)) return argv[i].slice(name.length + 3);
42
+ }
43
+ return null;
44
+ }
45
+
46
+ /**
47
+ * Lists the project templates shipped in `templates/` (folders starting with `_` are shared layers) plus `demo`.
48
+ * @param {string} sourceDir - Framework package root.
49
+ * @returns {Array<{ name: string, description: string }>}
50
+ */
51
+ export function listTemplates(sourceDir) {
52
+ const dir = path.join(sourceDir, "templates");
53
+ const found = fs.existsSync(dir)
54
+ ? fs
55
+ .readdirSync(dir)
56
+ .filter((name) => !name.startsWith("_") && fs.existsSync(path.join(dir, name, "template.json")))
57
+ .map((name) => loadTemplate(sourceDir, name))
58
+ : [];
59
+ const order = ["blank", "auth", "blog", "api"];
60
+ found.sort((a, b) => (order.indexOf(a.name) + 1 || 99) - (order.indexOf(b.name) + 1 || 99));
61
+ return [...found, DEMO_TEMPLATE];
62
+ }
63
+
64
+ /**
65
+ * Loads a template manifest (`templates/<name>/template.json`).
66
+ * @param {string} sourceDir
67
+ * @param {string} name
68
+ * @returns {{ name: string, description: string, layers: string[], client: boolean, database: string, routes?: string[], demo?: boolean }}
69
+ */
70
+ export function loadTemplate(sourceDir, name) {
71
+ if (name === "demo") return DEMO_TEMPLATE;
72
+ const manifest = JSON.parse(fs.readFileSync(path.join(sourceDir, "templates", name, "template.json"), "utf-8"));
73
+ return { layers: [], client: true, database: "optional", ...manifest, name };
74
+ }
75
+
76
+ /**
77
+ * Formats the template list for the CLI.
78
+ * @param {string} sourceDir
79
+ * @returns {string}
80
+ */
81
+ export function describeTemplates(sourceDir) {
82
+ return listTemplates(sourceDir)
83
+ .map((t) => ` ${t.name.padEnd(6)} ${t.description}`)
84
+ .join("\n");
85
+ }
86
+
87
+ /**
88
+ * Collects every file of a directory recursively as paths relative to it.
89
+ * @param {string} dir
90
+ * @param {string} [prefix=""]
91
+ * @returns {string[]}
92
+ */
93
+ function walkFiles(dir, prefix = "") {
94
+ if (!fs.existsSync(dir)) return [];
95
+ const out = [];
96
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
97
+ const rel = prefix ? `${prefix}/${entry.name}` : entry.name;
98
+ if (entry.isDirectory()) out.push(...walkFiles(path.join(dir, entry.name), rel));
99
+ else if (entry.name !== "template.json") out.push(rel);
100
+ }
101
+ return out;
102
+ }
103
+
104
+ /**
105
+ * Writes a template into the project: shared layers first (`_base`, `_auth`), then the template folder,
106
+ * each later file replacing the earlier one. Existing project files are never overwritten.
107
+ * `%%APP_TITLE%%` is replaced with the project title.
108
+ * @param {string} sourceDir - Framework package root.
109
+ * @param {string} appDir - Project root.
110
+ * @param {{ name: string, layers: string[] }} template
111
+ * @param {{ title?: string }} [vars={}]
112
+ * @returns {{ written: string[], skipped: string[] }}
113
+ */
114
+ export function scaffoldTemplate(sourceDir, appDir, template, vars = {}) {
115
+ const files = new Map();
116
+ for (const layer of [...(template.layers || []), template.name]) {
117
+ const layerDir = path.join(sourceDir, "templates", layer);
118
+ for (const rel of walkFiles(layerDir)) files.set(rel, path.join(layerDir, rel));
119
+ }
120
+
121
+ const safeTitle = String(vars.title || "Bluebird App").replace(/[<>{}"'`\\$&]/g, "").trim() || "Bluebird App";
122
+ const written = [];
123
+ const skipped = [];
124
+ for (const [rel, src] of files) {
125
+ const dest = path.join(appDir, rel);
126
+ if (fs.existsSync(dest)) {
127
+ skipped.push(rel);
128
+ continue;
129
+ }
130
+ fs.mkdirSync(path.dirname(dest), { recursive: true });
131
+ if (TEXT_EXTENSIONS.has(path.extname(rel))) {
132
+ fs.writeFileSync(dest, fs.readFileSync(src, "utf-8").replace(TEMPLATE_TOKEN, safeTitle));
133
+ } else {
134
+ fs.copyFileSync(src, dest);
135
+ }
136
+ written.push(rel);
137
+ }
138
+ return { written, skipped };
139
+ }
package/core/cli/view.js CHANGED
@@ -1,161 +1,98 @@
1
- #!/usr/bin/env node
2
-
3
- import fs from "node:fs";
4
- import path from "node:path";
5
- import colors from "../util/colors.js";
6
-
7
- const VIEWS_DIR = path.resolve(process.cwd(), "app/views");
8
-
9
- const rawArgs = process.argv.slice(2);
10
- const args = rawArgs.filter(
11
- (a) => a !== "view" && a !== "make:view" && !a.endsWith("view.js")
12
- );
13
- const viewName = args.find((a) => !a.startsWith("-"));
14
- const isHtml = rawArgs.some((a) => a === "--html");
15
- const isJs = rawArgs.some((a) => a === "--js");
16
- const isJsx = !isHtml && !isJs;
17
-
18
- if (!viewName) {
19
- console.log(colors.red("[ERROR] Missing view name."));
20
- console.log("Usage: npx bluebird-js make:view <name> [--jsx | --js | --html]");
21
- process.exit(1);
22
- }
23
-
24
- const cleanName = viewName.toLowerCase().replace(/[^a-z0-9_-]/g, "_");
25
- const titleCase = cleanName.charAt(0).toUpperCase() + cleanName.slice(1);
26
-
27
- if (!fs.existsSync(VIEWS_DIR)) {
28
- fs.mkdirSync(VIEWS_DIR, { recursive: true });
29
- }
30
-
31
- if (isHtml) {
32
- const filePath = path.join(VIEWS_DIR, `${cleanName}.html`);
33
- if (fs.existsSync(filePath)) {
34
- console.log(colors.yellow(`[WARN] View '${cleanName}.html' already exists at app/views/${cleanName}.html`));
35
- process.exit(0);
36
- }
37
-
38
- const rawHtml = `<!DOCTYPE html>
39
- <html lang="en" class="dark" data-theme="dark">
40
- <head>
41
- <meta charset="UTF-8" />
42
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
43
- <title>${titleCase}</title>
44
- <link rel="preconnect" href="https://fonts.googleapis.com">
45
- <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
46
- <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
47
- <script src="/js/tailwind.js"></script>
48
- <style type="text/tailwindcss">
49
- @custom-variant dark (&:where(.dark, .dark *, [data-theme="dark"], [data-theme="dark"] *));
50
- @theme {
51
- --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
52
- }
53
- </style>
54
- </head>
55
- <body class="min-h-screen bg-slate-950 text-slate-100 font-sans p-8 max-w-4xl mx-auto">
56
- <h1 class="text-3xl font-extrabold text-sky-400 mb-4">${titleCase}</h1>
57
- </body>
58
- </html>
59
- `;
60
- fs.writeFileSync(filePath, rawHtml, "utf-8");
61
- console.log(colors.green(`[OK] Static HTML view created at app/views/${cleanName}.html`));
62
- console.log(colors.cyan("To render:"));
63
- console.log(colors.gray(` routerWeb.get("/${cleanName}", (req, res) => Render.html(res, "${cleanName}.html"));`));
64
- process.exit(0);
65
- }
66
-
67
- if (isJsx) {
68
- const filePath = path.join(VIEWS_DIR, `${cleanName}.jsx`);
69
- if (fs.existsSync(filePath)) {
70
- console.log(colors.yellow(`[WARN] View '${cleanName}.jsx' already exists at app/views/${cleanName}.jsx`));
71
- process.exit(0);
72
- }
73
-
74
- const jsxTemplate = `import { Client } from "@seip/bluebird-js/core/jsx.js";
75
-
76
- export const layout = "main";
77
-
78
- export const head = () => ({
79
- title: "${titleCase} — Blue Bird",
80
- description: "${titleCase} view rendered with Bluebird React SSR",
81
- });
82
-
83
- /**
84
- * ${titleCase} React SSR view module.
85
- * @param {Object} props
86
- */
87
- export default async function ${titleCase}View(props = {}) {
88
- return (
89
- <>
90
- <section className="py-10 md:py-14 border-b border-slate-800/80">
91
- <h1 className="text-3xl md:text-5xl font-extrabold tracking-tight bg-gradient-to-r from-sky-400 to-indigo-400 bg-clip-text text-transparent">
92
- ${titleCase}
93
- </h1>
94
- <p className="mt-4 text-base md:text-lg text-slate-300">
95
- Welcome to your new Bluebird React SSR view.
96
- </p>
97
- </section>
98
-
99
- <div className="mt-8">
100
- <article className="rounded-2xl border border-slate-800 bg-slate-900/60 p-6">
101
- <p className="text-slate-300">
102
- Rendered on the server with zero-build JSX and instant partial navigation.
103
- </p>
104
- </article>
105
- </div>
106
- </>
107
- );
108
- }
109
- `;
110
-
111
- fs.writeFileSync(filePath, jsxTemplate, "utf-8");
112
- console.log(colors.green(`[OK] React JSX view created at app/views/${cleanName}.jsx`));
113
- console.log("");
114
- console.log(colors.cyan("To render this view in a route:"));
115
- console.log(colors.gray(` import Render from "@seip/bluebird-js/core/render.js";`));
116
- console.log(colors.gray(` routerWeb.get("/${cleanName}", Render.view("${cleanName}"));`));
117
- process.exit(0);
118
- }
119
-
120
- const filePath = path.join(VIEWS_DIR, `${cleanName}.js`);
121
- if (fs.existsSync(filePath)) {
122
- console.log(colors.yellow(`[WARN] View '${cleanName}.js' already exists at app/views/${cleanName}.js`));
123
- process.exit(0);
124
- }
125
-
126
- const serverTemplate = `import { html, script } from "@seip/bluebird-js/core/html.js";
127
-
128
- export const layout = "main";
129
-
130
- export const head = () => ({
131
- title: "${titleCase} — Blue Bird",
132
- description: "${titleCase} view",
133
- });
134
-
135
- /**
136
- * ${titleCase} view module.
137
- * @param {Object} props
138
- * @returns {import('@seip/bluebird-js/core/html.js').SafeHtml}
139
- */
140
- export default function ${titleCase}View(props = {}) {
141
- return html\`
142
- <section class="py-10 md:py-14 border-b border-slate-800/80">
143
- <h1 class="text-3xl md:text-5xl font-extrabold tracking-tight bg-gradient-to-r from-sky-400 to-indigo-400 bg-clip-text text-transparent">${titleCase}</h1>
144
- <p class="mt-4 text-base md:text-lg text-slate-300">Welcome to your new Bluebird view.</p>
145
- </section>
146
-
147
- <div class="mt-8">
148
- <article class="rounded-2xl border border-slate-800 bg-slate-900/60 p-6">
149
- <p class="text-slate-300">Rendered with pure JavaScript ESM and zero build tools.</p>
150
- </article>
151
- </div>
152
- \`;
153
- }
154
- `;
155
-
156
- fs.writeFileSync(filePath, serverTemplate, "utf-8");
157
- console.log(colors.green(`[OK] View created at app/views/${cleanName}.js`));
158
- console.log("");
159
- console.log(colors.cyan("To render this view in a route:"));
160
- console.log(colors.gray(` import Render from "@seip/bluebird-js/core/render.js";`));
161
- console.log(colors.gray(` routerWeb.get("/${cleanName}", Render.view("${cleanName}"));`));
1
+ #!/usr/bin/env node
2
+
3
+ import fs from "node:fs";
4
+ import path from "node:path";
5
+ import colors from "../util/colors.js";
6
+
7
+ /**
8
+ * `npx bluebird-js make:view <name> [--partial | --layout]`:
9
+ * Scaffolds an HTML `{{ }}` template view, partial, or layout inside `app/resources/html/`.
10
+ */
11
+ const VIEWS_DIR = path.resolve(process.cwd(), "app/resources/html");
12
+ const rawArgs = process.argv.slice(2).filter((a) => a !== "view" && a !== "make:view");
13
+ const viewName = rawArgs.find((a) => !a.startsWith("-"));
14
+ const isPartial = rawArgs.includes("--partial");
15
+ const isLayout = rawArgs.includes("--layout");
16
+
17
+ if (!viewName) {
18
+ console.log(colors.red("[ERROR] Missing view name."));
19
+ console.log("Usage: npx bluebird-js make:view <name> [--partial | --layout]");
20
+ process.exit(1);
21
+ }
22
+
23
+ const cleanName = viewName.toLowerCase().replace(/[^a-z0-9_/-]/g, "_").replace(/^\/+/, "");
24
+ const relPath = isLayout
25
+ ? `layouts/${cleanName}.html`
26
+ : isPartial
27
+ ? `partials/${cleanName}.html`
28
+ : `${cleanName}.html`;
29
+ const filePath = path.join(VIEWS_DIR, relPath);
30
+
31
+ if (fs.existsSync(filePath)) {
32
+ console.log(colors.yellow(`[WARN] ${path.relative(process.cwd(), filePath)} already exists.`));
33
+ process.exit(0);
34
+ }
35
+
36
+ fs.mkdirSync(path.dirname(filePath), { recursive: true });
37
+
38
+ const themeMetaHead = ` <meta name="color-scheme" content="light dark">
39
+ <script>
40
+ (function(){try{var k="bb-theme",t=localStorage.getItem(k),m=document.querySelector('meta[name="color-scheme"]'),d=document.documentElement,r=t==="light"||t==="dark"?t:(window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light");d.classList.toggle("dark",r==="dark");d.setAttribute("data-theme",r);if(m)m.content=t==="light"||t==="dark"?t:"light dark";}catch(e){}})();
41
+ </script>`;
42
+
43
+ let content;
44
+ if (isLayout) {
45
+ content = `<!DOCTYPE html>
46
+ <html lang="{{ lang }}">
47
+ <head>
48
+ <meta charset="UTF-8">
49
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
50
+ ${themeMetaHead}
51
+ <title>{{ title }}</title>
52
+ {{ vite "app/resources/styles.css" }}
53
+ <script src="/js/bluebird.js" defer></script>
54
+ </head>
55
+ <body class="min-h-screen bg-app text-foreground antialiased">
56
+ <main class="mx-auto max-w-5xl px-6 py-10">
57
+ {{{ body }}}
58
+ </main>
59
+ </body>
60
+ </html>
61
+ `;
62
+ } else if (isPartial) {
63
+ content = `<section class="card">
64
+ <h2 class="card-title">{{ title }}</h2>
65
+ </section>
66
+ `;
67
+ } else {
68
+ content = `<!DOCTYPE html>
69
+ <html lang="{{ lang }}">
70
+ <head>
71
+ <meta charset="UTF-8">
72
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
73
+ ${themeMetaHead}
74
+ <title>{{ title }}</title>
75
+ {{ vite "app/resources/styles.css" }}
76
+ <script src="/js/bluebird.js" defer></script>
77
+ </head>
78
+ <body class="min-h-screen bg-app text-foreground antialiased">
79
+ <main class="mx-auto max-w-4xl px-6 py-12">
80
+ <section class="glass-card">
81
+ <h1 class="text-3xl font-semibold tracking-tight">{{ title }}</h1>
82
+ {{#if subtitle}}
83
+ <p class="mt-2 text-muted-foreground">{{ subtitle }}</p>
84
+ {{/if}}
85
+ </section>
86
+ </main>
87
+ </body>
88
+ </html>
89
+ `;
90
+ }
91
+
92
+ fs.writeFileSync(filePath, content, "utf-8");
93
+ console.log(colors.green(`[OK] Created ${path.relative(process.cwd(), filePath)}`));
94
+ if (!isLayout && !isPartial) {
95
+ console.log(
96
+ colors.gray(`Serve it with: routerWeb.get("/${cleanName}", (req, res) => Render.html(res, "${cleanName}", { title: "${cleanName}" }))`)
97
+ );
98
+ }
package/core/config.js CHANGED
@@ -1,9 +1,51 @@
1
1
  import path from "node:path";
2
2
  import os from "node:os";
3
+ import fs from "node:fs";
3
4
 
4
5
  let _cachedProps = null;
5
6
  let _customUserDataDir = null;
6
7
  let _customAppDir = null;
8
+ let _envLoaded = false;
9
+
10
+ /**
11
+ * Loads .env or .env_example fallback into process.env if not already loaded.
12
+ * @param {string} baseDir
13
+ */
14
+ function ensureEnvLoaded(baseDir) {
15
+ if (_envLoaded) return;
16
+ _envLoaded = true;
17
+ const candidates = [
18
+ path.join(baseDir, ".env"),
19
+ path.join(baseDir, ".env.example"),
20
+ path.join(baseDir, ".env_example"),
21
+ ];
22
+ for (const file of candidates) {
23
+ if (!fs.existsSync(file)) continue;
24
+ try {
25
+ const content = fs.readFileSync(file, "utf-8");
26
+ for (const rawLine of content.split(/\r?\n/)) {
27
+ const line = rawLine.trim();
28
+ if (!line || line.startsWith("#")) continue;
29
+ const eqIdx = line.indexOf("=");
30
+ if (eqIdx <= 0) continue;
31
+ const key = line.slice(0, eqIdx).trim();
32
+ let val = line.slice(eqIdx + 1).trim();
33
+ if (
34
+ (val.startsWith('"') && val.endsWith('"')) ||
35
+ (val.startsWith("'") && val.endsWith("'"))
36
+ ) {
37
+ val = val.slice(1, -1);
38
+ }
39
+ if (process.env[key] === undefined) {
40
+ process.env[key] = val;
41
+ } else if (key === "PORT" && process.env.PORT === "8080" && val === "3000") {
42
+ process.env.APP_PORT = val;
43
+ }
44
+ }
45
+ break;
46
+ } catch {}
47
+ }
48
+ }
7
49
 
8
50
  /**
9
51
  * Configuration class to manage application-wide settings, environment variables,
@@ -47,7 +89,6 @@ class Config {
47
89
  return Boolean(
48
90
  process.versions?.electron ||
49
91
  process.env.DESKTOP_MODE === "true" ||
50
- process.env.ELECTRON_RUN_AS_NODE ||
51
92
  _customUserDataDir ||
52
93
  _customAppDir
53
94
  );
@@ -101,7 +142,8 @@ class Config {
101
142
  static props() {
102
143
  if (_cachedProps) return _cachedProps;
103
144
 
104
- const portRaw = parseInt(process.env.PORT, 10);
145
+ ensureEnvLoaded(this.appDir());
146
+ const portRaw = parseInt(process.env.APP_PORT || process.env.PORT, 10);
105
147
 
106
148
  _cachedProps = {
107
149
  debug: process.env.DEBUG === "true",