@seip/bluebird-js 0.1.6 → 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/.vscode/extensions.json +7 -7
- package/.vscode/settings.json +10 -10
- package/AGENTS.md +266 -116
- package/README.md +258 -245
- 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 +49 -37
- package/core/ai.d.ts +151 -151
- package/core/ai.js +1071 -1051
- package/core/app.d.ts +2 -18
- package/core/app.js +978 -792
- package/core/auth.d.ts +2 -13
- package/core/auth.js +444 -326
- package/core/cli/backup.js +167 -167
- 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 +101 -332
- package/core/cli/nginx.js +1 -1
- package/core/cli/templates.js +139 -0
- package/core/cli/view.js +73 -136
- package/core/config.js +44 -2
- package/core/csrf.js +156 -24
- package/core/database.js +737 -684
- package/core/debug.js +1 -1
- package/core/html.js +8 -1
- package/core/index.d.ts +1286 -1431
- 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 +613 -603
- 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 +81 -455
- 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/about.jsx +0 -98
- package/app/views/components/Header.jsx +0 -42
- package/app/views/components/LiveCounter.jsx +0 -66
- package/app/views/dashboard.jsx +0 -300
- package/app/views/index.jsx +0 -123
- package/app/views/layouts/main/view.jsx +0 -201
- package/app/views/legal/terms.html +0 -29
- package/app/views/login.jsx +0 -141
- package/core/actions.d.ts +0 -4
- package/core/actions.js +0 -329
- package/core/jsx.d.ts +0 -38
- package/core/jsx.js +0 -1432
- package/core/vite.d.ts +0 -3
- package/public/js/bluebird-client.js +0 -3161
- package/public/js/tailwind.js +0 -8
package/core/cli/backup.js
CHANGED
|
@@ -1,167 +1,167 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import fs from "node:fs";
|
|
4
|
-
import path from "node:path";
|
|
5
|
-
import readline from "node:readline/promises";
|
|
6
|
-
import colors from "../util/colors.js";
|
|
7
|
-
import { Database, DB_TYPE } from "../database.js";
|
|
8
|
-
import Config from "../config.js";
|
|
9
|
-
|
|
10
|
-
try {
|
|
11
|
-
process.loadEnvFile?.();
|
|
12
|
-
} catch {}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Prompts user for yes/no confirmation via CLI.
|
|
16
|
-
* @param {string} question
|
|
17
|
-
* @param {boolean} [defaultYes=false]
|
|
18
|
-
* @returns {Promise<boolean>}
|
|
19
|
-
*/
|
|
20
|
-
async function promptConfirm(question, defaultYes = false) {
|
|
21
|
-
if (!process.stdin.isTTY) {
|
|
22
|
-
return defaultYes;
|
|
23
|
-
}
|
|
24
|
-
const rl = readline.createInterface({
|
|
25
|
-
input: process.stdin,
|
|
26
|
-
output: process.stdout,
|
|
27
|
-
});
|
|
28
|
-
try {
|
|
29
|
-
const answer = await rl.question(colors.cyan(question));
|
|
30
|
-
const trimmed = answer.trim().toLowerCase();
|
|
31
|
-
if (!trimmed) return defaultYes;
|
|
32
|
-
return ["y", "yes", "s", "si", "true", "1"].includes(trimmed);
|
|
33
|
-
} finally {
|
|
34
|
-
rl.close();
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Formats byte size into human-readable string.
|
|
40
|
-
* @param {number} bytes
|
|
41
|
-
* @returns {string}
|
|
42
|
-
*/
|
|
43
|
-
function formatSize(bytes) {
|
|
44
|
-
if (bytes < 1024) return `${bytes} B`;
|
|
45
|
-
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(2)} KB`;
|
|
46
|
-
return `${(bytes / (1024 * 1024)).toFixed(2)} MB`;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Executes database backup CLI command.
|
|
51
|
-
*/
|
|
52
|
-
export async function runBackup() {
|
|
53
|
-
const args = process.argv.slice(2);
|
|
54
|
-
let keep = 10;
|
|
55
|
-
let outDir = null;
|
|
56
|
-
let compress = true;
|
|
57
|
-
|
|
58
|
-
for (let i = 0; i < args.length; i++) {
|
|
59
|
-
if (args[i] === "--keep" && args[i + 1]) {
|
|
60
|
-
keep = parseInt(args[i + 1], 10) || 10;
|
|
61
|
-
i++;
|
|
62
|
-
} else if (args[i].startsWith("--keep=")) {
|
|
63
|
-
keep = parseInt(args[i].split("=")[1], 10) || 10;
|
|
64
|
-
} else if (args[i] === "--out" && args[i + 1]) {
|
|
65
|
-
outDir = args[i + 1];
|
|
66
|
-
i++;
|
|
67
|
-
} else if (args[i].startsWith("--out=")) {
|
|
68
|
-
outDir = args[i].split("=")[1];
|
|
69
|
-
} else if (args[i] === "--no-compress") {
|
|
70
|
-
compress = false;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
console.log(colors.cyan(`[INFO] Creating atomic database backup (${DB_TYPE})...`));
|
|
75
|
-
|
|
76
|
-
try {
|
|
77
|
-
const result = await Database.backup({
|
|
78
|
-
out: outDir,
|
|
79
|
-
keep,
|
|
80
|
-
compress,
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
console.log(colors.green(`[OK] Database backup created successfully:`));
|
|
84
|
-
console.log(` ${colors.bold("File:")} ${result.file}`);
|
|
85
|
-
console.log(` ${colors.bold("Size:")} ${formatSize(result.size)}`);
|
|
86
|
-
console.log(` ${colors.bold("Type:")} ${result.dbType}`);
|
|
87
|
-
if (result.rotated > 0) {
|
|
88
|
-
console.log(` ${colors.bold("Rotated:")} ${result.rotated} older backup(s) purged (retention: ${keep})`);
|
|
89
|
-
}
|
|
90
|
-
} catch (err) {
|
|
91
|
-
console.error(colors.red(`[ERROR] Database backup failed:`), err.message);
|
|
92
|
-
process.exit(1);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Executes database restore CLI command.
|
|
98
|
-
*/
|
|
99
|
-
export async function runRestore() {
|
|
100
|
-
const args = process.argv.slice(2);
|
|
101
|
-
let targetFile = null;
|
|
102
|
-
let isAutoYes = false;
|
|
103
|
-
|
|
104
|
-
for (let i = 0; i < args.length; i++) {
|
|
105
|
-
const arg = args[i];
|
|
106
|
-
if (arg === "--yes" || arg === "-y") {
|
|
107
|
-
isAutoYes = true;
|
|
108
|
-
} else if (arg !== "db:restore" && arg !== "restore" && !arg.startsWith("--")) {
|
|
109
|
-
targetFile = arg;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
if (!targetFile) {
|
|
114
|
-
const backupsDir = path.resolve(Config.userDataDir(), "database/backups");
|
|
115
|
-
console.log(colors.yellow("[WARN] No backup file specified."));
|
|
116
|
-
if (fs.existsSync(backupsDir)) {
|
|
117
|
-
const files = fs.readdirSync(backupsDir).filter((f) => !f.startsWith("."));
|
|
118
|
-
if (files.length > 0) {
|
|
119
|
-
console.log(colors.cyan("\nAvailable backups in database/backups:"));
|
|
120
|
-
for (const f of files.slice(0, 10)) {
|
|
121
|
-
console.log(` - ${f}`);
|
|
122
|
-
}
|
|
123
|
-
console.log(colors.gray("\nUsage: npx bluebird-js db:restore <filename> [--yes]"));
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
process.exit(1);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
if (!isAutoYes) {
|
|
130
|
-
const confirmed = await promptConfirm(
|
|
131
|
-
`⚠️ WARNING: Restoring will overwrite the active database.\nA safety snapshot of the current database will be saved automatically.\nAre you sure you want to proceed? (y/N): `,
|
|
132
|
-
false
|
|
133
|
-
);
|
|
134
|
-
if (!confirmed) {
|
|
135
|
-
console.log(colors.yellow("[CANCELLED] Database restore cancelled by user."));
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
console.log(colors.cyan(`[INFO] Restoring database from '${targetFile}'...`));
|
|
141
|
-
|
|
142
|
-
try {
|
|
143
|
-
const result = await Database.restore(targetFile, {
|
|
144
|
-
safetyBackup: true,
|
|
145
|
-
verify: true,
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
console.log(colors.green(`[OK] Database restored successfully:`));
|
|
149
|
-
console.log(` ${colors.bold("Source:")} ${result.restoredFrom}`);
|
|
150
|
-
console.log(` ${colors.bold("Target:")} ${result.targetFile}`);
|
|
151
|
-
console.log(` ${colors.bold("Size:")} ${formatSize(result.size)}`);
|
|
152
|
-
if (result.preRestoreBackup) {
|
|
153
|
-
console.log(` ${colors.bold("Snapshot:")} ${result.preRestoreBackup} (pre-restore safety backup)`);
|
|
154
|
-
}
|
|
155
|
-
} catch (err) {
|
|
156
|
-
console.error(colors.red(`[ERROR] Database restore failed:`), err.message);
|
|
157
|
-
process.exit(1);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
const action = process.argv[2];
|
|
162
|
-
if (action === "db:restore" || action === "restore") {
|
|
163
|
-
runRestore();
|
|
164
|
-
} else {
|
|
165
|
-
runBackup();
|
|
166
|
-
}
|
|
167
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import readline from "node:readline/promises";
|
|
6
|
+
import colors from "../util/colors.js";
|
|
7
|
+
import { Database, DB_TYPE } from "../database.js";
|
|
8
|
+
import Config from "../config.js";
|
|
9
|
+
|
|
10
|
+
try {
|
|
11
|
+
process.loadEnvFile?.();
|
|
12
|
+
} catch {}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Prompts user for yes/no confirmation via CLI.
|
|
16
|
+
* @param {string} question
|
|
17
|
+
* @param {boolean} [defaultYes=false]
|
|
18
|
+
* @returns {Promise<boolean>}
|
|
19
|
+
*/
|
|
20
|
+
async function promptConfirm(question, defaultYes = false) {
|
|
21
|
+
if (!process.stdin.isTTY) {
|
|
22
|
+
return defaultYes;
|
|
23
|
+
}
|
|
24
|
+
const rl = readline.createInterface({
|
|
25
|
+
input: process.stdin,
|
|
26
|
+
output: process.stdout,
|
|
27
|
+
});
|
|
28
|
+
try {
|
|
29
|
+
const answer = await rl.question(colors.cyan(question));
|
|
30
|
+
const trimmed = answer.trim().toLowerCase();
|
|
31
|
+
if (!trimmed) return defaultYes;
|
|
32
|
+
return ["y", "yes", "s", "si", "true", "1"].includes(trimmed);
|
|
33
|
+
} finally {
|
|
34
|
+
rl.close();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Formats byte size into human-readable string.
|
|
40
|
+
* @param {number} bytes
|
|
41
|
+
* @returns {string}
|
|
42
|
+
*/
|
|
43
|
+
function formatSize(bytes) {
|
|
44
|
+
if (bytes < 1024) return `${bytes} B`;
|
|
45
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(2)} KB`;
|
|
46
|
+
return `${(bytes / (1024 * 1024)).toFixed(2)} MB`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Executes database backup CLI command.
|
|
51
|
+
*/
|
|
52
|
+
export async function runBackup() {
|
|
53
|
+
const args = process.argv.slice(2);
|
|
54
|
+
let keep = 10;
|
|
55
|
+
let outDir = null;
|
|
56
|
+
let compress = true;
|
|
57
|
+
|
|
58
|
+
for (let i = 0; i < args.length; i++) {
|
|
59
|
+
if (args[i] === "--keep" && args[i + 1]) {
|
|
60
|
+
keep = parseInt(args[i + 1], 10) || 10;
|
|
61
|
+
i++;
|
|
62
|
+
} else if (args[i].startsWith("--keep=")) {
|
|
63
|
+
keep = parseInt(args[i].split("=")[1], 10) || 10;
|
|
64
|
+
} else if (args[i] === "--out" && args[i + 1]) {
|
|
65
|
+
outDir = args[i + 1];
|
|
66
|
+
i++;
|
|
67
|
+
} else if (args[i].startsWith("--out=")) {
|
|
68
|
+
outDir = args[i].split("=")[1];
|
|
69
|
+
} else if (args[i] === "--no-compress") {
|
|
70
|
+
compress = false;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
console.log(colors.cyan(`[INFO] Creating atomic database backup (${DB_TYPE})...`));
|
|
75
|
+
|
|
76
|
+
try {
|
|
77
|
+
const result = await Database.backup({
|
|
78
|
+
out: outDir,
|
|
79
|
+
keep,
|
|
80
|
+
compress,
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
console.log(colors.green(`[OK] Database backup created successfully:`));
|
|
84
|
+
console.log(` ${colors.bold("File:")} ${result.file}`);
|
|
85
|
+
console.log(` ${colors.bold("Size:")} ${formatSize(result.size)}`);
|
|
86
|
+
console.log(` ${colors.bold("Type:")} ${result.dbType}`);
|
|
87
|
+
if (result.rotated > 0) {
|
|
88
|
+
console.log(` ${colors.bold("Rotated:")} ${result.rotated} older backup(s) purged (retention: ${keep})`);
|
|
89
|
+
}
|
|
90
|
+
} catch (err) {
|
|
91
|
+
console.error(colors.red(`[ERROR] Database backup failed:`), err.message);
|
|
92
|
+
process.exit(1);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Executes database restore CLI command.
|
|
98
|
+
*/
|
|
99
|
+
export async function runRestore() {
|
|
100
|
+
const args = process.argv.slice(2);
|
|
101
|
+
let targetFile = null;
|
|
102
|
+
let isAutoYes = false;
|
|
103
|
+
|
|
104
|
+
for (let i = 0; i < args.length; i++) {
|
|
105
|
+
const arg = args[i];
|
|
106
|
+
if (arg === "--yes" || arg === "-y") {
|
|
107
|
+
isAutoYes = true;
|
|
108
|
+
} else if (arg !== "db:restore" && arg !== "restore" && !arg.startsWith("--")) {
|
|
109
|
+
targetFile = arg;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (!targetFile) {
|
|
114
|
+
const backupsDir = path.resolve(Config.userDataDir(), "database/backups");
|
|
115
|
+
console.log(colors.yellow("[WARN] No backup file specified."));
|
|
116
|
+
if (fs.existsSync(backupsDir)) {
|
|
117
|
+
const files = fs.readdirSync(backupsDir).filter((f) => !f.startsWith("."));
|
|
118
|
+
if (files.length > 0) {
|
|
119
|
+
console.log(colors.cyan("\nAvailable backups in database/backups:"));
|
|
120
|
+
for (const f of files.slice(0, 10)) {
|
|
121
|
+
console.log(` - ${f}`);
|
|
122
|
+
}
|
|
123
|
+
console.log(colors.gray("\nUsage: npx bluebird-js db:restore <filename> [--yes]"));
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
process.exit(1);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (!isAutoYes) {
|
|
130
|
+
const confirmed = await promptConfirm(
|
|
131
|
+
`⚠️ WARNING: Restoring will overwrite the active database.\nA safety snapshot of the current database will be saved automatically.\nAre you sure you want to proceed? (y/N): `,
|
|
132
|
+
false
|
|
133
|
+
);
|
|
134
|
+
if (!confirmed) {
|
|
135
|
+
console.log(colors.yellow("[CANCELLED] Database restore cancelled by user."));
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
console.log(colors.cyan(`[INFO] Restoring database from '${targetFile}'...`));
|
|
141
|
+
|
|
142
|
+
try {
|
|
143
|
+
const result = await Database.restore(targetFile, {
|
|
144
|
+
safetyBackup: true,
|
|
145
|
+
verify: true,
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
console.log(colors.green(`[OK] Database restored successfully:`));
|
|
149
|
+
console.log(` ${colors.bold("Source:")} ${result.restoredFrom}`);
|
|
150
|
+
console.log(` ${colors.bold("Target:")} ${result.targetFile}`);
|
|
151
|
+
console.log(` ${colors.bold("Size:")} ${formatSize(result.size)}`);
|
|
152
|
+
if (result.preRestoreBackup) {
|
|
153
|
+
console.log(` ${colors.bold("Snapshot:")} ${result.preRestoreBackup} (pre-restore safety backup)`);
|
|
154
|
+
}
|
|
155
|
+
} catch (err) {
|
|
156
|
+
console.error(colors.red(`[ERROR] Database restore failed:`), err.message);
|
|
157
|
+
process.exit(1);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const action = process.argv[2];
|
|
162
|
+
if (action === "db:restore" || action === "restore") {
|
|
163
|
+
runRestore();
|
|
164
|
+
} else {
|
|
165
|
+
runBackup();
|
|
166
|
+
}
|
|
167
|
+
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import colors from "../util/colors.js";
|
|
3
|
+
import ViteBridge from "../vite.js";
|
|
4
|
+
import { BUILD_DIRS, resolveClientInputs } from "../vite-plugin.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* `npx bluebird-js build`: builds the client SPA bundle and compiled Tailwind CSS into `public/build/`.
|
|
8
|
+
*/
|
|
9
|
+
async function build() {
|
|
10
|
+
const root = process.cwd();
|
|
11
|
+
delete process.env.DEBUG;
|
|
12
|
+
process.env.NODE_ENV = process.env.NODE_ENV || "production";
|
|
13
|
+
|
|
14
|
+
const inputs = resolveClientInputs(root);
|
|
15
|
+
if (inputs.length === 0) {
|
|
16
|
+
console.log(colors.yellow("[BUILD] No client entry (app/resources/main.jsx) or stylesheet (app/resources/styles.css) found. Nothing to build."));
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const { build: viteBuild } = await import("vite");
|
|
21
|
+
const bridge = new ViteBridge({ root, dev: false });
|
|
22
|
+
const config = await bridge.inlineConfig();
|
|
23
|
+
const started = Date.now();
|
|
24
|
+
|
|
25
|
+
console.log(colors.cyan("[BUILD] Client bundle ->"), BUILD_DIRS.client);
|
|
26
|
+
await viteBuild({ ...config, mode: "production", logLevel: "warn" });
|
|
27
|
+
|
|
28
|
+
console.log(
|
|
29
|
+
colors.green(`[OK] Build completed in ${((Date.now() - started) / 1000).toFixed(1)}s.`),
|
|
30
|
+
colors.gray(`Start with: npm start (${path.join(BUILD_DIRS.client, ".vite/manifest.json")})`)
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
build().catch((err) => {
|
|
35
|
+
console.error(colors.red("[BUILD ERROR]"), err?.message || err);
|
|
36
|
+
process.exit(1);
|
|
37
|
+
});
|
package/core/cli/dev.js
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { spawn } from "node:child_process";
|
|
6
|
+
import colors from "../util/colors.js";
|
|
7
|
+
|
|
8
|
+
const SERVER_EXTENSIONS = new Set([".js", ".mjs", ".cjs", ".json"]);
|
|
9
|
+
const IGNORED_SEGMENTS = new Set(["node_modules", ".vite", ".vite-temp", "logs", "cache", ".git", "dist", "build"]);
|
|
10
|
+
const DEFAULT_DIRS = ["app", "core"];
|
|
11
|
+
const CLIENT_DIRS = ["app/resources/"];
|
|
12
|
+
const DEFAULT_FILES = ["index.js", ".env", "app/resources/spa.js"];
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Parses `bluebird-js dev [entry] [--watch <path>]... [--delay <ms>]` arguments.
|
|
16
|
+
* @param {string[]} argv
|
|
17
|
+
* @returns {{ entry: string, watch: string[], delay: number }}
|
|
18
|
+
*/
|
|
19
|
+
function parseArgs(argv) {
|
|
20
|
+
const out = { entry: "index.js", watch: [], delay: 150 };
|
|
21
|
+
for (let i = 0; i < argv.length; i++) {
|
|
22
|
+
const arg = argv[i];
|
|
23
|
+
if (arg === "--watch" && argv[i + 1]) out.watch.push(argv[++i]);
|
|
24
|
+
else if (arg.startsWith("--watch=")) out.watch.push(arg.slice(8));
|
|
25
|
+
else if (arg === "--delay" && argv[i + 1]) out.delay = Number(argv[++i]) || out.delay;
|
|
26
|
+
else if (!arg.startsWith("-")) out.entry = arg;
|
|
27
|
+
}
|
|
28
|
+
return out;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Checks whether a changed file should restart the server (server code only, never build output or logs).
|
|
33
|
+
* Every server file under `app/` (routes, models, jobs, lib, database.js, ...) restarts the server.
|
|
34
|
+
* Client code in `app/resources/` is hot-reloaded by Vite, so only explicitly watched files there restart.
|
|
35
|
+
* @param {string} relPath
|
|
36
|
+
* @param {Set<string>} watchedFiles
|
|
37
|
+
* @returns {boolean}
|
|
38
|
+
*/
|
|
39
|
+
export function shouldRestart(relPath, watchedFiles) {
|
|
40
|
+
const clean = relPath.replace(/\\/g, "/").replace(/^\.\//, "");
|
|
41
|
+
if (watchedFiles.has(clean)) return true;
|
|
42
|
+
if (CLIENT_DIRS.some((dir) => clean.startsWith(dir))) return false;
|
|
43
|
+
const segments = clean.split("/");
|
|
44
|
+
if (segments.some((s) => IGNORED_SEGMENTS.has(s))) return false;
|
|
45
|
+
if (segments.some((s) => s.includes(".timestamp-"))) return false;
|
|
46
|
+
return SERVER_EXTENSIONS.has(path.extname(clean));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* `npx bluebird-js dev`: runs the server with `--env-file-if-exists=.env` and restarts it when server files change.
|
|
51
|
+
* Replaces `node --watch-path`, which on some platforms reports changes outside the watched paths
|
|
52
|
+
* (`logs/`, `node_modules/.vite-temp`, esbuild binaries) and restarts endlessly.
|
|
53
|
+
*/
|
|
54
|
+
function dev() {
|
|
55
|
+
const root = process.cwd();
|
|
56
|
+
const args = parseArgs(process.argv.slice(3));
|
|
57
|
+
const entry = args.entry;
|
|
58
|
+
|
|
59
|
+
if (!fs.existsSync(path.join(root, entry))) {
|
|
60
|
+
console.error(colors.red(`[DEV] Entry file '${entry}' not found.`));
|
|
61
|
+
process.exit(1);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const watchedFiles = new Set([entry, ...DEFAULT_FILES].map((f) => f.replace(/\\/g, "/")));
|
|
65
|
+
const watchedDirs = [];
|
|
66
|
+
for (const item of [...DEFAULT_DIRS, ...args.watch]) {
|
|
67
|
+
const abs = path.resolve(root, item);
|
|
68
|
+
if (!fs.existsSync(abs)) continue;
|
|
69
|
+
if (fs.statSync(abs).isDirectory()) watchedDirs.push(abs);
|
|
70
|
+
else watchedFiles.add(path.relative(root, abs).replace(/\\/g, "/"));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
let child = null;
|
|
74
|
+
let restarting = false;
|
|
75
|
+
let timer = null;
|
|
76
|
+
let pendingReason = "";
|
|
77
|
+
|
|
78
|
+
const start = () => {
|
|
79
|
+
child = spawn(process.execPath, ["--env-file-if-exists=.env", entry], {
|
|
80
|
+
cwd: root,
|
|
81
|
+
stdio: ["inherit", "inherit", "inherit", "ipc"],
|
|
82
|
+
env: { ...process.env, BLUEBIRD_DEV_RUNNER: "1" },
|
|
83
|
+
});
|
|
84
|
+
child.on("exit", (code, signal) => {
|
|
85
|
+
const wasRestart = restarting;
|
|
86
|
+
child = null;
|
|
87
|
+
if (wasRestart) {
|
|
88
|
+
restarting = false;
|
|
89
|
+
start();
|
|
90
|
+
} else if (signal !== "SIGTERM" && signal !== "SIGINT") {
|
|
91
|
+
console.log(colors.yellow(`[DEV] Server exited (code ${code ?? signal}). Waiting for file changes...`));
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const restart = (reason) => {
|
|
97
|
+
console.log(colors.cyan(`[DEV] ${reason} changed, restarting...`));
|
|
98
|
+
if (child) {
|
|
99
|
+
restarting = true;
|
|
100
|
+
child.kill("SIGTERM");
|
|
101
|
+
} else {
|
|
102
|
+
start();
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const bootedAt = Date.now();
|
|
107
|
+
const mtimes = new Map();
|
|
108
|
+
const hasRealChange = (relPath) => {
|
|
109
|
+
let mtime = -1;
|
|
110
|
+
try {
|
|
111
|
+
mtime = fs.statSync(path.join(root, relPath)).mtimeMs;
|
|
112
|
+
} catch {}
|
|
113
|
+
const previous = mtimes.has(relPath) ? mtimes.get(relPath) : bootedAt;
|
|
114
|
+
mtimes.set(relPath, mtime);
|
|
115
|
+
return (mtime === -1 && previous !== -1) || mtime > previous;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const schedule = (relPath) => {
|
|
119
|
+
if (!shouldRestart(relPath, watchedFiles)) return;
|
|
120
|
+
if (!hasRealChange(relPath)) return;
|
|
121
|
+
pendingReason = relPath.replace(/\\/g, "/");
|
|
122
|
+
clearTimeout(timer);
|
|
123
|
+
timer = setTimeout(() => restart(pendingReason), args.delay);
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
for (const dir of watchedDirs) {
|
|
127
|
+
fs.watch(dir, { recursive: true }, (event, filename) => {
|
|
128
|
+
if (filename) schedule(path.relative(root, path.join(dir, filename.toString())));
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const fileDirs = new Set([...watchedFiles].map((f) => path.dirname(path.join(root, f))));
|
|
133
|
+
for (const dir of fileDirs) {
|
|
134
|
+
if (!fs.existsSync(dir) || watchedDirs.some((w) => dir === w || dir.startsWith(w + path.sep))) continue;
|
|
135
|
+
fs.watch(dir, (event, filename) => {
|
|
136
|
+
if (!filename) return;
|
|
137
|
+
const rel = path.relative(root, path.join(dir, filename.toString())).replace(/\\/g, "/");
|
|
138
|
+
if (watchedFiles.has(rel)) schedule(rel);
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const stop = () => {
|
|
143
|
+
clearTimeout(timer);
|
|
144
|
+
if (child) child.kill("SIGTERM");
|
|
145
|
+
process.exit(0);
|
|
146
|
+
};
|
|
147
|
+
process.on("SIGINT", stop);
|
|
148
|
+
process.on("SIGTERM", stop);
|
|
149
|
+
|
|
150
|
+
const dirs = watchedDirs.map((d) => path.relative(root, d).replace(/\\/g, "/")).join(", ");
|
|
151
|
+
console.log(colors.gray(`[DEV] Watching ${dirs || "(no dirs)"} + ${[...watchedFiles].join(", ")}`));
|
|
152
|
+
start();
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (process.argv[2] === "dev") dev();
|
package/core/cli/doctor.js
CHANGED
|
@@ -60,8 +60,6 @@ function findSampleStaticAsset() {
|
|
|
60
60
|
if (!fs.existsSync(publicDir)) return null;
|
|
61
61
|
|
|
62
62
|
const candidates = [
|
|
63
|
-
"js/tailwind.js",
|
|
64
|
-
"js/bluebird-client.js",
|
|
65
63
|
"images/favicon.ico",
|
|
66
64
|
];
|
|
67
65
|
|
|
@@ -184,6 +182,24 @@ export async function runDoctor() {
|
|
|
184
182
|
} else {
|
|
185
183
|
console.log(colors.green(" [PASS] 'app/' directory exists."));
|
|
186
184
|
}
|
|
185
|
+
|
|
186
|
+
const cwd = process.cwd();
|
|
187
|
+
for (const legacy of ["app/views", "app/client", "app/styles.css"]) {
|
|
188
|
+
if (fs.existsSync(path.join(cwd, legacy))) {
|
|
189
|
+
console.log(colors.yellow(` [WARN] Legacy '${legacy}' found: move it into 'app/resources/' (html/ for views).`));
|
|
190
|
+
warningsFound++;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
const hasSpaEntry = ["main.jsx", "main.tsx", "main.js", "main.ts"].some((f) => fs.existsSync(path.join(cwd, "app/resources", f)));
|
|
194
|
+
if (hasSpaEntry) {
|
|
195
|
+
console.log(colors.green(" [PASS] React SPA entry found in 'app/resources/'."));
|
|
196
|
+
if (fs.existsSync(path.join(cwd, "public/build/.vite/manifest.json"))) {
|
|
197
|
+
console.log(colors.green(" [PASS] Production client build found (public/build/.vite/manifest.json)."));
|
|
198
|
+
} else {
|
|
199
|
+
console.log(colors.yellow(" [WARN] No production build: run 'npx bluebird-js build' before 'npm start'."));
|
|
200
|
+
warningsFound++;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
187
203
|
console.log("");
|
|
188
204
|
|
|
189
205
|
console.log(colors.bold("[3/5] Port Availability & Binding:"));
|
|
@@ -209,8 +225,10 @@ export async function runDoctor() {
|
|
|
209
225
|
}
|
|
210
226
|
|
|
211
227
|
let serverReachable = false;
|
|
228
|
+
let foreignServer = false;
|
|
212
229
|
|
|
213
230
|
for (const item of testUrls) {
|
|
231
|
+
if (foreignServer) break;
|
|
214
232
|
try {
|
|
215
233
|
const controller = new AbortController();
|
|
216
234
|
const timeoutId = setTimeout(() => controller.abort(), 3000);
|
|
@@ -219,6 +237,23 @@ export async function runDoctor() {
|
|
|
219
237
|
|
|
220
238
|
serverReachable = true;
|
|
221
239
|
|
|
240
|
+
if (item.isApi) {
|
|
241
|
+
const body = await res.text();
|
|
242
|
+
let isBluebird = false;
|
|
243
|
+
try {
|
|
244
|
+
const json = JSON.parse(body);
|
|
245
|
+
isBluebird = json?.status === "ok" && "uptime" in json;
|
|
246
|
+
} catch {}
|
|
247
|
+
if (!isBluebird) {
|
|
248
|
+
foreignServer = true;
|
|
249
|
+
console.log(colors.yellow(` [WARN] ${appUrl} answered, but it is not this Bluebird app (HTTP ${res.status}, ${res.headers.get("content-type") || "no content type"}).`));
|
|
250
|
+
console.log(colors.yellow(` Another process is using port ${port} (e.g. VS Code Live Preview or another dev server).`));
|
|
251
|
+
console.log(colors.yellow(" Stop it or set PORT to a free port, then run doctor again with your app started."));
|
|
252
|
+
warningsFound++;
|
|
253
|
+
continue;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
222
257
|
if (res.status === 200) {
|
|
223
258
|
console.log(colors.green(` [PASS] ${item.name} returned HTTP 200 OK.`));
|
|
224
259
|
} else if (res.status === 403) {
|