@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,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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
);
|
|
13
|
-
const viewName =
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
console.log(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
if (
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
<
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
<
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
</head>
|
|
55
|
-
<body class="min-h-screen bg-
|
|
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
|
-
<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
|
-
|
|
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",
|