@seip/bluebird-js 0.0.1 ā 0.1.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.
- package/.env_example +53 -53
- package/AGENTS.md +426 -403
- package/LICENSE +1 -1
- package/README.md +292 -285
- package/app/routes/api.js +50 -50
- package/app/routes/web.js +55 -53
- package/app/views/about.js +63 -0
- package/app/views/dashboard.js +147 -0
- package/app/views/index.js +80 -0
- package/app/views/layouts/main/view.js +81 -0
- package/app/views/legal/terms.html +19 -0
- package/app/views/login.js +80 -0
- package/core/app.d.ts +18 -18
- package/core/app.js +684 -644
- package/core/auth.d.ts +13 -13
- package/core/auth.js +326 -326
- package/core/cache.d.ts +17 -17
- package/core/cache.js +475 -475
- package/core/cli/doctor.js +287 -287
- package/core/cli/ecosystem.js +162 -162
- package/core/cli/init.js +779 -779
- package/core/cli/migrate.js +541 -541
- package/core/cli/model.js +66 -66
- package/core/cli/nginx.js +199 -199
- package/core/cli/route.js +120 -120
- package/core/cli/view.js +55 -36
- package/core/config.d.ts +3 -3
- package/core/config.js +111 -111
- package/core/csrf.d.ts +3 -3
- package/core/csrf.js +114 -114
- package/core/database.d.ts +15 -15
- package/core/database.js +636 -636
- package/core/debug.d.ts +3 -3
- package/core/debug.js +249 -249
- package/core/hash.d.ts +3 -3
- package/core/hash.js +194 -194
- package/core/html.d.ts +42 -0
- package/core/html.js +217 -0
- package/core/index.d.ts +1176 -1071
- package/core/logger.d.ts +3 -3
- package/core/logger.js +127 -124
- package/core/middleware.d.ts +3 -3
- package/core/middleware.js +28 -28
- package/core/model.d.ts +19 -19
- package/core/model.js +600 -600
- package/core/queue.d.ts +13 -13
- package/core/queue.js +172 -172
- package/core/ratelimit.d.ts +3 -3
- package/core/ratelimit.js +145 -145
- package/core/redis.d.ts +21 -21
- package/core/redis.js +230 -230
- package/core/render-cache.js +212 -0
- package/core/render.d.ts +3 -3
- package/core/render.js +199 -555
- package/core/router.d.ts +3 -3
- package/core/router.js +171 -171
- package/core/seo.d.ts +3 -3
- package/core/seo.js +106 -106
- package/core/swagger.d.ts +3 -3
- package/core/swagger.js +60 -60
- package/core/upload.d.ts +13 -13
- package/core/upload.js +102 -102
- package/core/util/colors.js +82 -82
- package/core/validate.d.ts +15 -15
- package/core/validate.js +364 -364
- package/core/view-loader.js +162 -0
- package/core/vite.d.ts +3 -3
- package/core/vite.js +145 -145
- package/core/ws.d.ts +13 -13
- package/core/ws.js +245 -245
- package/index.js +18 -18
- package/jsconfig.json +15 -15
- package/package.json +85 -86
- package/production.md +273 -273
- package/public/css/bluebird.min.css +1 -1
- package/public/js/bluebird-client.js +1780 -1662
- package/public/js/bluebird.min.js +1072 -1072
- package/app/views/about.html +0 -161
- package/app/views/dashboard.html +0 -140
- package/app/views/index.html +0 -150
- package/app/views/login.html +0 -144
package/core/cli/init.js
CHANGED
|
@@ -1,779 +1,779 @@
|
|
|
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 { stdin as input, stdout as output } from "node:process";
|
|
7
|
-
import crypto from "node:crypto";
|
|
8
|
-
import { execSync } from "node:child_process";
|
|
9
|
-
import colors from "../util/colors.js";
|
|
10
|
-
|
|
11
|
-
try {
|
|
12
|
-
process.loadEnvFile?.();
|
|
13
|
-
} catch {}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Initializes a new Bluebird project with interactive configuration.
|
|
17
|
-
*/
|
|
18
|
-
class ProjectInit {
|
|
19
|
-
constructor() {
|
|
20
|
-
this.appDir = process.cwd();
|
|
21
|
-
this.sourceDir = path.resolve(import.meta.dirname, "../../");
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Runs the project initialization process.
|
|
26
|
-
*/
|
|
27
|
-
async run() {
|
|
28
|
-
console.log(colors.cyan("Starting Bluebird project initialization..."));
|
|
29
|
-
|
|
30
|
-
const rl = readline.createInterface({ input, output });
|
|
31
|
-
|
|
32
|
-
let title = "Bluebird App";
|
|
33
|
-
let port = 3000;
|
|
34
|
-
let appUrl = "http://localhost:3000";
|
|
35
|
-
let dbType = "sqlite";
|
|
36
|
-
let dbName = "blue_bird";
|
|
37
|
-
let dbFile = "database/blue_bird.db";
|
|
38
|
-
let dbUser = "root";
|
|
39
|
-
let dbPassword = "root";
|
|
40
|
-
let dbPort = 3306;
|
|
41
|
-
let cacheMode = "memory";
|
|
42
|
-
|
|
43
|
-
try {
|
|
44
|
-
const isAutoYes = process.argv.includes("--yes") || process.argv.includes("-y");
|
|
45
|
-
|
|
46
|
-
const ask = async (query, defaultValue) => {
|
|
47
|
-
if (isAutoYes) return defaultValue;
|
|
48
|
-
const formattedQuery =
|
|
49
|
-
defaultValue !== undefined
|
|
50
|
-
? `${query} [${defaultValue}]: `
|
|
51
|
-
: `${query}: `;
|
|
52
|
-
const answer = await rl.question(formattedQuery);
|
|
53
|
-
return answer.trim() || defaultValue;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
title = await ask("Project Title", title);
|
|
57
|
-
|
|
58
|
-
const portInput = await ask("Server Port", port);
|
|
59
|
-
port = parseInt(portInput, 10);
|
|
60
|
-
if (Number.isNaN(port)) {
|
|
61
|
-
port = 3000;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const defaultAppUrl = `http://localhost:${port}`;
|
|
65
|
-
appUrl = await ask("Application URL", defaultAppUrl);
|
|
66
|
-
|
|
67
|
-
const dbTypeAns = await ask(
|
|
68
|
-
"Which database do you want to configure? (sqlite / mysql / postgres / none)",
|
|
69
|
-
"sqlite"
|
|
70
|
-
);
|
|
71
|
-
const cleanDbTypeAns = dbTypeAns.toLowerCase().trim();
|
|
72
|
-
if (
|
|
73
|
-
cleanDbTypeAns === "sqlite" ||
|
|
74
|
-
cleanDbTypeAns === "sqlite3" ||
|
|
75
|
-
cleanDbTypeAns === "sql" ||
|
|
76
|
-
cleanDbTypeAns === "lite"
|
|
77
|
-
) {
|
|
78
|
-
dbType = "sqlite";
|
|
79
|
-
} else if (
|
|
80
|
-
cleanDbTypeAns === "postgres" ||
|
|
81
|
-
cleanDbTypeAns === "postgresql" ||
|
|
82
|
-
cleanDbTypeAns === "pg" ||
|
|
83
|
-
cleanDbTypeAns === "psql" ||
|
|
84
|
-
cleanDbTypeAns === "pgsql"
|
|
85
|
-
) {
|
|
86
|
-
dbType = "postgres";
|
|
87
|
-
} else if (
|
|
88
|
-
cleanDbTypeAns === "mysql" ||
|
|
89
|
-
cleanDbTypeAns === "mariadb" ||
|
|
90
|
-
cleanDbTypeAns === "maria" ||
|
|
91
|
-
cleanDbTypeAns === "my"
|
|
92
|
-
) {
|
|
93
|
-
dbType = "mysql";
|
|
94
|
-
} else if (
|
|
95
|
-
cleanDbTypeAns === "none" ||
|
|
96
|
-
cleanDbTypeAns === "no" ||
|
|
97
|
-
cleanDbTypeAns === "null" ||
|
|
98
|
-
cleanDbTypeAns === "false" ||
|
|
99
|
-
cleanDbTypeAns === "0"
|
|
100
|
-
) {
|
|
101
|
-
dbType = "none";
|
|
102
|
-
} else {
|
|
103
|
-
console.log(colors.yellow(`[WARN] Unknown database '${dbTypeAns}'. Defaulting to 'sqlite'.`));
|
|
104
|
-
dbType = "sqlite";
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if (dbType === "sqlite") {
|
|
108
|
-
dbName = await ask("Database Name", dbName);
|
|
109
|
-
const defaultDbFile = `database/${dbName}.db`;
|
|
110
|
-
dbFile = await ask("Database File Path", defaultDbFile);
|
|
111
|
-
const dbDir = path.dirname(path.join(this.appDir, dbFile));
|
|
112
|
-
if (!fs.existsSync(dbDir)) {
|
|
113
|
-
fs.mkdirSync(dbDir, { recursive: true });
|
|
114
|
-
}
|
|
115
|
-
} else if (dbType === "mysql") {
|
|
116
|
-
dbName = await ask("Database Name", dbName);
|
|
117
|
-
dbUser = await ask("Database User", "root");
|
|
118
|
-
dbPassword = await ask("Database Password", "root");
|
|
119
|
-
const defaultDbPort = 3306;
|
|
120
|
-
const dbPortInput = await ask("Database Port", defaultDbPort);
|
|
121
|
-
dbPort = parseInt(dbPortInput, 10);
|
|
122
|
-
if (Number.isNaN(dbPort)) {
|
|
123
|
-
dbPort = defaultDbPort;
|
|
124
|
-
}
|
|
125
|
-
} else if (dbType === "postgres") {
|
|
126
|
-
dbName = await ask("Database Name", dbName);
|
|
127
|
-
dbUser = await ask("Database User", "postgres");
|
|
128
|
-
dbPassword = await ask("Database Password", "root");
|
|
129
|
-
const defaultDbPort = 5432;
|
|
130
|
-
const dbPortInput = await ask("Database Port", defaultDbPort);
|
|
131
|
-
dbPort = parseInt(dbPortInput, 10);
|
|
132
|
-
if (Number.isNaN(dbPort)) {
|
|
133
|
-
dbPort = defaultDbPort;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
const cacheChoice = await ask("Cache Engine (memory [Default] / file / redis / none)", "memory");
|
|
138
|
-
const cleanCache = cacheChoice.toLowerCase().trim();
|
|
139
|
-
cacheMode = cleanCache.startsWith("r")
|
|
140
|
-
? "redis"
|
|
141
|
-
: cleanCache.startsWith("f")
|
|
142
|
-
? "file"
|
|
143
|
-
: cleanCache.startsWith("n")
|
|
144
|
-
? "none"
|
|
145
|
-
: "memory";
|
|
146
|
-
} catch (error) {
|
|
147
|
-
console.error(colors.red("[ERROR] Error reading configuration input:"), error.message);
|
|
148
|
-
rl.close();
|
|
149
|
-
return;
|
|
150
|
-
} finally {
|
|
151
|
-
rl.close();
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
const itemsToCopy = [
|
|
155
|
-
"index.js",
|
|
156
|
-
"app",
|
|
157
|
-
"public",
|
|
158
|
-
".env_example",
|
|
159
|
-
"AGENTS.md",
|
|
160
|
-
"jsconfig.json",
|
|
161
|
-
".vscode",
|
|
162
|
-
];
|
|
163
|
-
|
|
164
|
-
try {
|
|
165
|
-
itemsToCopy.forEach((item) => {
|
|
166
|
-
const src = path.join(this.sourceDir, item);
|
|
167
|
-
const dest = path.join(this.appDir, item);
|
|
168
|
-
|
|
169
|
-
if (fs.existsSync(src)) {
|
|
170
|
-
if (!fs.existsSync(dest)) {
|
|
171
|
-
this.copyRecursive(src, dest);
|
|
172
|
-
console.log(colors.green(`[OK] Copied ${item} to root.`));
|
|
173
|
-
} else {
|
|
174
|
-
console.log(colors.yellow(`[SKIP] ${item} already exists, skipping.`));
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
const gitignoreContent = "node_modules\nlogs\n.env\napp/cache\npackage-lock.json\n*.db\n*.sqlite\n*.sqlite-wal\n*.sqlite-shm\n*.db-wal\n*.db-shm\nbackups/*.sql\nbackups/*.db\n";
|
|
180
|
-
const gitignoreDest = path.join(this.appDir, ".gitignore");
|
|
181
|
-
const gitignoreSrc = path.join(this.sourceDir, ".gitignore");
|
|
182
|
-
|
|
183
|
-
if (!fs.existsSync(gitignoreDest)) {
|
|
184
|
-
if (fs.existsSync(gitignoreSrc)) {
|
|
185
|
-
fs.copyFileSync(gitignoreSrc, gitignoreDest);
|
|
186
|
-
console.log(colors.green("[OK] Copied .gitignore to root."));
|
|
187
|
-
} else {
|
|
188
|
-
fs.writeFileSync(gitignoreDest, gitignoreContent, "utf-8");
|
|
189
|
-
console.log(colors.green("[OK] Created .gitignore file."));
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
const envPath = path.join(this.appDir, ".env");
|
|
194
|
-
const jwtSecret = crypto.randomBytes(32).toString("hex");
|
|
195
|
-
|
|
196
|
-
let dbEnvBlock = "";
|
|
197
|
-
if (dbType === "sqlite") {
|
|
198
|
-
dbEnvBlock = `# Database Configuration\nDB_TYPE="sqlite"\nDB_FILE="${dbFile}"\nDATABASE_URL="sqlite:${dbFile}"`;
|
|
199
|
-
} else if (dbType === "mysql") {
|
|
200
|
-
dbEnvBlock = `# Database Configuration\nDB_TYPE="mysql"\nDB_HOST="localhost"\nDB_PORT=${dbPort}\nDB_NAME="${dbName}"\nDB_USER="${dbUser}"\nDB_PASSWORD="${dbPassword}"\nDATABASE_URL="mysql://${dbUser}:${dbPassword}@localhost:${dbPort}/${dbName}"`;
|
|
201
|
-
} else if (dbType === "postgres") {
|
|
202
|
-
dbEnvBlock = `# Database Configuration\nDB_TYPE="postgres"\nDB_HOST="localhost"\nDB_PORT=${dbPort}\nDB_NAME="${dbName}"\nDB_USER="${dbUser}"\nDB_PASSWORD="${dbPassword}"\nDATABASE_URL="postgresql://${dbUser}:${dbPassword}@localhost:${dbPort}/${dbName}?schema=public"`;
|
|
203
|
-
} else {
|
|
204
|
-
dbEnvBlock = `# Database Configuration\nDB_TYPE="none"`;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
const envContent = `# Server and Application Configuration
|
|
208
|
-
DEBUG=true
|
|
209
|
-
PORT=${port}
|
|
210
|
-
HOST="localhost"
|
|
211
|
-
APP_URL="${appUrl}"
|
|
212
|
-
VERSION="1.0.0"
|
|
213
|
-
|
|
214
|
-
# Application Metadata
|
|
215
|
-
TITLE="${title}"
|
|
216
|
-
DESCRIPTION="Bluebird Application"
|
|
217
|
-
|
|
218
|
-
# Security Configuration
|
|
219
|
-
JWT_SECRET="${jwtSecret}"
|
|
220
|
-
|
|
221
|
-
# Cache Configuration
|
|
222
|
-
# Options: "memory" (Fast in-memory RAM, default), "file" (Filesystem cache), "redis" (Distributed cache), "none" (Disabled)
|
|
223
|
-
CACHE_MODE="${cacheMode}"
|
|
224
|
-
CACHE_MAX_KEYS=1000
|
|
225
|
-
|
|
226
|
-
# Redis Configuration (Used when CACHE_MODE="redis" or { driver: "redis" })
|
|
227
|
-
REDIS_HOST="localhost"
|
|
228
|
-
REDIS_PORT=6379
|
|
229
|
-
REDIS_PASSWORD=""
|
|
230
|
-
|
|
231
|
-
# PM2 Clustering Configuration
|
|
232
|
-
PM2_APP_NAME="bluebird-app"
|
|
233
|
-
PM2_INSTANCES=1
|
|
234
|
-
PM2_MAX_MEMORY="512M"
|
|
235
|
-
|
|
236
|
-
${dbEnvBlock}
|
|
237
|
-
`;
|
|
238
|
-
|
|
239
|
-
if (!fs.existsSync(envPath)) {
|
|
240
|
-
fs.writeFileSync(envPath, envContent, "utf-8");
|
|
241
|
-
console.log(colors.green("[OK] Created and configured .env file."));
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
this.updatePackageJson();
|
|
245
|
-
|
|
246
|
-
const packagesToInstall = [];
|
|
247
|
-
if (dbType === "postgres") packagesToInstall.push("pg");
|
|
248
|
-
if (dbType === "mysql") packagesToInstall.push("mysql2");
|
|
249
|
-
if (cacheMode === "redis") packagesToInstall.push("redis");
|
|
250
|
-
|
|
251
|
-
if (packagesToInstall.length > 0) {
|
|
252
|
-
console.log(colors.cyan(`[INFO] Installing packages: ${packagesToInstall.join(" ")}...`));
|
|
253
|
-
try {
|
|
254
|
-
execSync(`npm install ${packagesToInstall.join(" ")}`, {
|
|
255
|
-
stdio: "inherit",
|
|
256
|
-
cwd: this.appDir,
|
|
257
|
-
});
|
|
258
|
-
console.log(colors.green(`[OK] Successfully installed ${packagesToInstall.join(" ")}.`));
|
|
259
|
-
} catch {
|
|
260
|
-
console.warn(colors.yellow("[WARN] Automatic package installation failed. Run 'npm install' manually."));
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
console.log(colors.blue("\nBluebird initialization completed!"));
|
|
265
|
-
console.log(colors.white("Next steps:"));
|
|
266
|
-
console.log(colors.bold(" npm run dev"));
|
|
267
|
-
} catch (error) {
|
|
268
|
-
console.error(colors.red("[ERROR] Error during initialization:"), error.message);
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
/**
|
|
273
|
-
* Updates package.json with scripts and dependencies.
|
|
274
|
-
* Creates package.json if it does not yet exist.
|
|
275
|
-
*/
|
|
276
|
-
updatePackageJson() {
|
|
277
|
-
const pkgPath = path.join(this.appDir, "package.json");
|
|
278
|
-
let pkg = {};
|
|
279
|
-
|
|
280
|
-
if (fs.existsSync(pkgPath)) {
|
|
281
|
-
try {
|
|
282
|
-
pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
|
|
283
|
-
} catch {}
|
|
284
|
-
} else {
|
|
285
|
-
const appName =
|
|
286
|
-
path.basename(this.appDir).toLowerCase().replace(/[^a-z0-9_-]/g, "-") ||
|
|
287
|
-
"bluebird-app";
|
|
288
|
-
pkg = {
|
|
289
|
-
name: appName,
|
|
290
|
-
version: "1.0.0",
|
|
291
|
-
type: "module",
|
|
292
|
-
dependencies: {
|
|
293
|
-
"@seip/bluebird-js": "^0.0
|
|
294
|
-
},
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
pkg.scripts = pkg.scripts || {};
|
|
299
|
-
const entryFile = "index.js";
|
|
300
|
-
|
|
301
|
-
const scriptsToAdd = {
|
|
302
|
-
dev: `node --watch --env-file=.env ${entryFile}`,
|
|
303
|
-
start: `node --env-file=.env ${entryFile}`,
|
|
304
|
-
init: "bluebird-js",
|
|
305
|
-
doctor: "bluebird-js doctor",
|
|
306
|
-
route: "bluebird-js make:route",
|
|
307
|
-
view: "bluebird-js make:view",
|
|
308
|
-
model: "bluebird-js make:model",
|
|
309
|
-
"make:model": "bluebird-js make:model",
|
|
310
|
-
migrate: "bluebird-js migrate",
|
|
311
|
-
"migrate:status": "bluebird-js migrate:status",
|
|
312
|
-
"migrate:rollback": "bluebird-js migrate:rollback",
|
|
313
|
-
seed: "bluebird-js seed",
|
|
314
|
-
ecosystem: "bluebird-js make:ecosystem",
|
|
315
|
-
};
|
|
316
|
-
|
|
317
|
-
for (const [key, value] of Object.entries(scriptsToAdd)) {
|
|
318
|
-
pkg.scripts[key] = value;
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
if (pkg.type !== "module") {
|
|
322
|
-
pkg.type = "module";
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
if (!pkg.dependencies) {
|
|
326
|
-
pkg.dependencies = {};
|
|
327
|
-
}
|
|
328
|
-
if (!pkg.dependencies["@seip/bluebird-js"]) {
|
|
329
|
-
pkg.dependencies["@seip/bluebird-js"] = "^0.0
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
|
|
333
|
-
console.log(colors.green("[OK] Configured package.json with scripts and dependencies."));
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
/**
|
|
337
|
-
* Copies a file or directory recursively.
|
|
338
|
-
* @param {string} src - Source path.
|
|
339
|
-
* @param {string} dest - Destination path.
|
|
340
|
-
*/
|
|
341
|
-
copyRecursive(src, dest) {
|
|
342
|
-
const stats = fs.statSync(src);
|
|
343
|
-
const isDirectory = stats.isDirectory();
|
|
344
|
-
|
|
345
|
-
if (isDirectory) {
|
|
346
|
-
if (!fs.existsSync(dest)) {
|
|
347
|
-
fs.mkdirSync(dest, { recursive: true });
|
|
348
|
-
}
|
|
349
|
-
fs.readdirSync(src).forEach((childItemName) => {
|
|
350
|
-
if (
|
|
351
|
-
childItemName === "node_modules" ||
|
|
352
|
-
childItemName === "dist" ||
|
|
353
|
-
childItemName === ".git" ||
|
|
354
|
-
childItemName === "cache"
|
|
355
|
-
) {
|
|
356
|
-
return;
|
|
357
|
-
}
|
|
358
|
-
this.copyRecursive(
|
|
359
|
-
path.join(src, childItemName),
|
|
360
|
-
path.join(dest, childItemName)
|
|
361
|
-
);
|
|
362
|
-
});
|
|
363
|
-
} else {
|
|
364
|
-
fs.copyFileSync(src, dest);
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
/**
|
|
370
|
-
* Scaffolds React Islands architecture with Vite.
|
|
371
|
-
*/
|
|
372
|
-
function setupReactIslands() {
|
|
373
|
-
const appDir = process.cwd();
|
|
374
|
-
console.log(colors.cyan("[INFO] Setting up React Islands with Vite..."));
|
|
375
|
-
|
|
376
|
-
try {
|
|
377
|
-
execSync("npm install react react-dom", { stdio: "inherit", cwd: appDir });
|
|
378
|
-
execSync("npm install -D vite @vitejs/plugin-react", { stdio: "inherit", cwd: appDir });
|
|
379
|
-
console.log(colors.green("[OK] Installed React and Vite dependencies."));
|
|
380
|
-
} catch (err) {
|
|
381
|
-
console.warn(colors.yellow("[WARN] Package installation failed. Run 'npm install react react-dom && npm install -D vite @vitejs/plugin-react' manually."));
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
const viteConfigPath = path.join(appDir, "vite.config.js");
|
|
385
|
-
if (!fs.existsSync(viteConfigPath)) {
|
|
386
|
-
const viteConfigContent = `import { defineConfig } from "vite";
|
|
387
|
-
import react from "@vitejs/plugin-react";
|
|
388
|
-
|
|
389
|
-
export default defineConfig({
|
|
390
|
-
plugins: [react()],
|
|
391
|
-
build: {
|
|
392
|
-
outDir: "public/dist",
|
|
393
|
-
emptyOutDir: true,
|
|
394
|
-
manifest: true,
|
|
395
|
-
rollupOptions: {
|
|
396
|
-
input: "src/islands/main.jsx",
|
|
397
|
-
},
|
|
398
|
-
},
|
|
399
|
-
server: {
|
|
400
|
-
port: 5173,
|
|
401
|
-
strictPort: true,
|
|
402
|
-
cors: true,
|
|
403
|
-
},
|
|
404
|
-
});
|
|
405
|
-
`;
|
|
406
|
-
fs.writeFileSync(viteConfigPath, viteConfigContent, "utf-8");
|
|
407
|
-
console.log(colors.green("[OK] Created vite.config.js"));
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
const islandsDir = path.join(appDir, "src/islands");
|
|
411
|
-
if (!fs.existsSync(islandsDir)) {
|
|
412
|
-
fs.mkdirSync(islandsDir, { recursive: true });
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
const mainPath = path.join(islandsDir, "main.jsx");
|
|
416
|
-
if (!fs.existsSync(mainPath)) {
|
|
417
|
-
const mainContent = `import React from "react";
|
|
418
|
-
import ReactDOM from "react-dom/client";
|
|
419
|
-
import RadioPlayer from "./RadioPlayer.jsx";
|
|
420
|
-
import LiveCounter from "./LiveCounter.jsx";
|
|
421
|
-
|
|
422
|
-
window.__BLUEBIRD_ISLANDS__ = window.__BLUEBIRD_ISLANDS__ || {};
|
|
423
|
-
|
|
424
|
-
window.__BLUEBIRD_ISLANDS__["RadioPlayer"] = RadioPlayer;
|
|
425
|
-
window.__BLUEBIRD_ISLANDS__["LiveCounter"] = LiveCounter;
|
|
426
|
-
|
|
427
|
-
window.__BLUEBIRD_MOUNT__ = (el, Component, props) => {
|
|
428
|
-
const root = ReactDOM.createRoot(el);
|
|
429
|
-
root.render(React.createElement(Component, props));
|
|
430
|
-
return () => root.unmount();
|
|
431
|
-
};
|
|
432
|
-
|
|
433
|
-
if (window.Bluebird && typeof window.Bluebird.hydrate === "function") {
|
|
434
|
-
window.Bluebird.hydrate();
|
|
435
|
-
}
|
|
436
|
-
`;
|
|
437
|
-
fs.writeFileSync(mainPath, mainContent, "utf-8");
|
|
438
|
-
console.log(colors.green("[OK] Created src/islands/main.jsx"));
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
const radioPath = path.join(islandsDir, "RadioPlayer.jsx");
|
|
442
|
-
if (!fs.existsSync(radioPath)) {
|
|
443
|
-
const radioContent = `import React, { useState, useEffect } from "react";
|
|
444
|
-
|
|
445
|
-
export default function RadioPlayer({ title = "Bluebird Radio", streamUrl = "" }) {
|
|
446
|
-
const [isPlaying, setIsPlaying] = useState(false);
|
|
447
|
-
const [currentTrack, setCurrentTrack] = useState("Live Broadcast #1");
|
|
448
|
-
const [listeners, setListeners] = useState(142);
|
|
449
|
-
|
|
450
|
-
useEffect(() => {
|
|
451
|
-
const interval = setInterval(() => {
|
|
452
|
-
setListeners((prev) => prev + Math.floor(Math.random() * 5) - 2);
|
|
453
|
-
}, 4000);
|
|
454
|
-
|
|
455
|
-
const unsubscribe = window.Bluebird?.on?.("radio:track", (track) => {
|
|
456
|
-
if (track) setCurrentTrack(track);
|
|
457
|
-
});
|
|
458
|
-
|
|
459
|
-
return () => {
|
|
460
|
-
clearInterval(interval);
|
|
461
|
-
if (unsubscribe) unsubscribe();
|
|
462
|
-
};
|
|
463
|
-
}, []);
|
|
464
|
-
|
|
465
|
-
const togglePlay = () => {
|
|
466
|
-
setIsPlaying((prev) => !prev);
|
|
467
|
-
window.Bluebird?.emit?.("radio:state", { playing: !isPlaying, track: currentTrack });
|
|
468
|
-
};
|
|
469
|
-
|
|
470
|
-
return (
|
|
471
|
-
<div style={{
|
|
472
|
-
background: "linear-gradient(135deg, #0f172a 0%, #1e293b 100%)",
|
|
473
|
-
color: "#f8fafc",
|
|
474
|
-
padding: "1.25rem",
|
|
475
|
-
borderRadius: "1rem",
|
|
476
|
-
border: "1px solid #334155",
|
|
477
|
-
boxShadow: "0 10px 25px -5px rgba(0,0,0,0.3)",
|
|
478
|
-
display: "flex",
|
|
479
|
-
alignItems: "center",
|
|
480
|
-
justifyContent: "space-between",
|
|
481
|
-
gap: "1rem",
|
|
482
|
-
fontFamily: "system-ui, -apple-system, sans-serif"
|
|
483
|
-
}}>
|
|
484
|
-
<div style={{ display: "flex", alignItems: "center", gap: "1rem" }}>
|
|
485
|
-
<button
|
|
486
|
-
onClick={togglePlay}
|
|
487
|
-
style={{
|
|
488
|
-
width: "3rem",
|
|
489
|
-
height: "3rem",
|
|
490
|
-
borderRadius: "50%",
|
|
491
|
-
border: "none",
|
|
492
|
-
background: isPlaying ? "#ef4444" : "#3b82f6",
|
|
493
|
-
color: "#ffffff",
|
|
494
|
-
fontSize: "1.25rem",
|
|
495
|
-
cursor: "pointer",
|
|
496
|
-
display: "flex",
|
|
497
|
-
alignItems: "center",
|
|
498
|
-
justifyContent: "center",
|
|
499
|
-
boxShadow: isPlaying ? "0 0 15px rgba(239, 68, 68, 0.5)" : "0 0 15px rgba(59, 130, 246, 0.5)"
|
|
500
|
-
}}
|
|
501
|
-
>
|
|
502
|
-
{isPlaying ? "āø" : "ā¶"}
|
|
503
|
-
</button>
|
|
504
|
-
<div>
|
|
505
|
-
<div style={{ fontSize: "0.875rem", fontWeight: 700, color: "#93c5fd" }}>{title}</div>
|
|
506
|
-
<div style={{ fontSize: "1rem", fontWeight: 600 }}>{currentTrack}</div>
|
|
507
|
-
<div style={{ fontSize: "0.75rem", color: "#94a3b8" }}>{listeners} active listeners ⢠Live Stream</div>
|
|
508
|
-
</div>
|
|
509
|
-
</div>
|
|
510
|
-
<div style={{
|
|
511
|
-
padding: "0.25rem 0.75rem",
|
|
512
|
-
borderRadius: "9999px",
|
|
513
|
-
background: isPlaying ? "rgba(34, 197, 94, 0.2)" : "rgba(148, 163, 184, 0.2)",
|
|
514
|
-
color: isPlaying ? "#4ade80" : "#94a3b8",
|
|
515
|
-
fontSize: "0.75rem",
|
|
516
|
-
fontWeight: 700,
|
|
517
|
-
textTransform: "uppercase"
|
|
518
|
-
}}>
|
|
519
|
-
{isPlaying ? "ā On Air" : "ā Paused"}
|
|
520
|
-
</div>
|
|
521
|
-
</div>
|
|
522
|
-
);
|
|
523
|
-
}
|
|
524
|
-
`;
|
|
525
|
-
fs.writeFileSync(radioPath, radioContent, "utf-8");
|
|
526
|
-
console.log(colors.green("[OK] Created src/islands/RadioPlayer.jsx (sample persistent island)"));
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
const counterPath = path.join(islandsDir, "LiveCounter.jsx");
|
|
530
|
-
if (!fs.existsSync(counterPath)) {
|
|
531
|
-
const counterContent = `import React, { useState } from "react";
|
|
532
|
-
|
|
533
|
-
export default function LiveCounter({ initial = 0, label = "Interactive Counter" }) {
|
|
534
|
-
const [count, setCount] = useState(initial);
|
|
535
|
-
|
|
536
|
-
const increment = () => {
|
|
537
|
-
const next = count + 1;
|
|
538
|
-
setCount(next);
|
|
539
|
-
window.Bluebird?.emit?.("counter:change", next);
|
|
540
|
-
};
|
|
541
|
-
|
|
542
|
-
const decrement = () => {
|
|
543
|
-
const next = count - 1;
|
|
544
|
-
setCount(next);
|
|
545
|
-
window.Bluebird?.emit?.("counter:change", next);
|
|
546
|
-
};
|
|
547
|
-
|
|
548
|
-
return (
|
|
549
|
-
<div style={{
|
|
550
|
-
display: "inline-flex",
|
|
551
|
-
alignItems: "center",
|
|
552
|
-
gap: "0.75rem",
|
|
553
|
-
padding: "0.5rem 1rem",
|
|
554
|
-
background: "#f1f5f9",
|
|
555
|
-
borderRadius: "0.75rem",
|
|
556
|
-
border: "1px solid #cbd5e1",
|
|
557
|
-
fontFamily: "system-ui, sans-serif"
|
|
558
|
-
}}>
|
|
559
|
-
<span style={{ fontWeight: 600, color: "#334155" }}>{label}:</span>
|
|
560
|
-
<button onClick={decrement} style={{ padding: "0.25rem 0.5rem", borderRadius: "0.375rem", border: "1px solid #94a3b8", cursor: "pointer" }}>-</button>
|
|
561
|
-
<span style={{ minWidth: "1.5rem", textAlign: "center", fontWeight: 700, color: "#0f172a" }}>{count}</span>
|
|
562
|
-
<button onClick={increment} style={{ padding: "0.25rem 0.5rem", borderRadius: "0.375rem", border: "1px solid #94a3b8", cursor: "pointer" }}>+</button>
|
|
563
|
-
</div>
|
|
564
|
-
);
|
|
565
|
-
}
|
|
566
|
-
`;
|
|
567
|
-
fs.writeFileSync(counterPath, counterContent, "utf-8");
|
|
568
|
-
console.log(colors.green("[OK] Created src/islands/LiveCounter.jsx"));
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
const demoViewPath = path.join(appDir, "app/views/islands-demo.html");
|
|
572
|
-
if (!fs.existsSync(demoViewPath)) {
|
|
573
|
-
const demoContent = `<!DOCTYPE html>
|
|
574
|
-
<html lang="en">
|
|
575
|
-
<head>
|
|
576
|
-
<meta charset="UTF-8">
|
|
577
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
578
|
-
<title>{{ title }}</title>
|
|
579
|
-
<meta name="description" content="{{ description }}">
|
|
580
|
-
<link rel="stylesheet" href="/css/bluebird.min.css">
|
|
581
|
-
{{{ bluebirdHead }}}
|
|
582
|
-
</head>
|
|
583
|
-
<body style="padding: 2rem; max-width: 800px; margin: 0 auto; font-family: system-ui, sans-serif;">
|
|
584
|
-
<header style="margin-bottom: 2rem; border-bottom: 1px solid #e2e8f0; padding-bottom: 1rem;">
|
|
585
|
-
<h1>{{ title }}</h1>
|
|
586
|
-
<p style="color: #64748b;">{{ description }}</p>
|
|
587
|
-
<nav style="display: flex; gap: 1rem; margin-top: 1rem;">
|
|
588
|
-
<a href="/islands-demo">Demo Home</a>
|
|
589
|
-
<a href="/about">About Us (Test Navigation)</a>
|
|
590
|
-
</nav>
|
|
591
|
-
</header>
|
|
592
|
-
|
|
593
|
-
<main style="display: flex; flex-direction: column; gap: 2rem;">
|
|
594
|
-
<section>
|
|
595
|
-
<h2>1. Persistent Audio Stream Island</h2>
|
|
596
|
-
<p style="color: #64748b; font-size: 0.9rem;">
|
|
597
|
-
Click Play, then navigate to other pages above. Notice the audio player keeps playing without interrupting!
|
|
598
|
-
</p>
|
|
599
|
-
<div data-island="RadioPlayer" data-persist="true" data-props='{"title": "Bluebird Live FM"}'></div>
|
|
600
|
-
</section>
|
|
601
|
-
|
|
602
|
-
<section>
|
|
603
|
-
<h2>2. Standard Reactive Island</h2>
|
|
604
|
-
<p style="color: #64748b; font-size: 0.9rem;">
|
|
605
|
-
Interactive state-driven React component rendered inside pure SSR HTML.
|
|
606
|
-
</p>
|
|
607
|
-
<div data-island="LiveCounter" data-props='{"initial": 10, "label": "Session Taps"}'></div>
|
|
608
|
-
</section>
|
|
609
|
-
</main>
|
|
610
|
-
|
|
611
|
-
<script src="/js/bluebird-client.js"></script>
|
|
612
|
-
</body>
|
|
613
|
-
</html>
|
|
614
|
-
`;
|
|
615
|
-
fs.writeFileSync(demoViewPath, demoContent, "utf-8");
|
|
616
|
-
console.log(colors.green("[OK] Created app/views/islands-demo.html"));
|
|
617
|
-
}
|
|
618
|
-
|
|
619
|
-
const pkgPath = path.join(appDir, "package.json");
|
|
620
|
-
if (fs.existsSync(pkgPath)) {
|
|
621
|
-
try {
|
|
622
|
-
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
|
|
623
|
-
pkg.scripts = pkg.scripts || {};
|
|
624
|
-
pkg.scripts["build:client"] = "vite build";
|
|
625
|
-
pkg.scripts["dev:client"] = "vite";
|
|
626
|
-
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
|
|
627
|
-
console.log(colors.green("[OK] Added 'build:client' and 'dev:client' scripts to package.json"));
|
|
628
|
-
} catch {}
|
|
629
|
-
}
|
|
630
|
-
|
|
631
|
-
console.log(colors.bold.green("\nReact Islands setup complete!"));
|
|
632
|
-
console.log(colors.white("Next steps:"));
|
|
633
|
-
console.log(colors.cyan(" 1. In development, start Vite in a separate terminal:"));
|
|
634
|
-
console.log(colors.bold(" npm run dev:client"));
|
|
635
|
-
console.log(colors.cyan(" 2. In production, compile your islands before starting:"));
|
|
636
|
-
console.log(colors.bold(" npm run build:client"));
|
|
637
|
-
console.log(colors.cyan(" 3. View the live demo by registering a route in app/routes/web.js:"));
|
|
638
|
-
console.log(colors.bold(' routerWeb.get("/islands-demo", Render.view("islands-demo", { title: "Islands Demo", description: "Bluebird React Islands" }));\n'));
|
|
639
|
-
}
|
|
640
|
-
|
|
641
|
-
/**
|
|
642
|
-
* Handles adding on-demand modules and dependencies.
|
|
643
|
-
* @param {string} [feature]
|
|
644
|
-
*/
|
|
645
|
-
function addCommand(feature) {
|
|
646
|
-
if (!feature) {
|
|
647
|
-
console.log(colors.yellow("Usage: npx bluebird-js add <feature>"));
|
|
648
|
-
console.log("Available features:");
|
|
649
|
-
console.log(" react | islands - Installs React + Vite with Islands architecture");
|
|
650
|
-
console.log(" upload | multer - Installs multer for file uploads");
|
|
651
|
-
console.log(" ws | websocket - Installs ws for WebSockets");
|
|
652
|
-
console.log(" redis - Installs redis for distributed caching and sessions");
|
|
653
|
-
console.log(" sqlite - Installs better-sqlite3 (fallback for older environments)");
|
|
654
|
-
console.log(" mysql - Installs mysql2 for MySQL database");
|
|
655
|
-
console.log(" postgres | pg - Installs pg for PostgreSQL database");
|
|
656
|
-
console.log(" bcrypt - Installs bcrypt for password hashing");
|
|
657
|
-
console.log(" swagger - Installs swagger-ui-express for API docs");
|
|
658
|
-
console.log(" helmet - Installs helmet for advanced security headers");
|
|
659
|
-
console.log(" ejs - Installs ejs for server-side template rendering");
|
|
660
|
-
return;
|
|
661
|
-
}
|
|
662
|
-
|
|
663
|
-
const cleanFeature = feature.toLowerCase().trim();
|
|
664
|
-
|
|
665
|
-
if (
|
|
666
|
-
cleanFeature === "react" ||
|
|
667
|
-
cleanFeature === "react-islands" ||
|
|
668
|
-
cleanFeature === "islands"
|
|
669
|
-
) {
|
|
670
|
-
setupReactIslands();
|
|
671
|
-
return;
|
|
672
|
-
}
|
|
673
|
-
|
|
674
|
-
const packageMap = {
|
|
675
|
-
upload: "multer",
|
|
676
|
-
multer: "multer",
|
|
677
|
-
ws: "ws",
|
|
678
|
-
websocket: "ws",
|
|
679
|
-
websockets: "ws",
|
|
680
|
-
redis: "redis",
|
|
681
|
-
sqlite: "better-sqlite3",
|
|
682
|
-
"better-sqlite3": "better-sqlite3",
|
|
683
|
-
mysql: "mysql2",
|
|
684
|
-
mysql2: "mysql2",
|
|
685
|
-
mariadb: "mysql2",
|
|
686
|
-
maria: "mysql2",
|
|
687
|
-
postgres: "pg",
|
|
688
|
-
postgresql: "pg",
|
|
689
|
-
pg: "pg",
|
|
690
|
-
psql: "pg",
|
|
691
|
-
pgsql: "pg",
|
|
692
|
-
psgr: "pg",
|
|
693
|
-
postgre: "pg",
|
|
694
|
-
postgr: "pg",
|
|
695
|
-
bcrypt: "bcrypt",
|
|
696
|
-
swagger: "swagger-ui-express swagger-jsdoc",
|
|
697
|
-
helmet: "helmet",
|
|
698
|
-
ejs: "ejs",
|
|
699
|
-
};
|
|
700
|
-
|
|
701
|
-
const pkgName = packageMap[cleanFeature];
|
|
702
|
-
if (!pkgName) {
|
|
703
|
-
console.error(colors.red(`[ERROR] Unknown feature '${feature}'.`));
|
|
704
|
-
console.log("Run 'npx bluebird-js add' to see available features.");
|
|
705
|
-
return;
|
|
706
|
-
}
|
|
707
|
-
|
|
708
|
-
console.log(colors.cyan(`[INFO] Installing ${pkgName}...`));
|
|
709
|
-
try {
|
|
710
|
-
execSync(`npm install ${pkgName}`, { stdio: "inherit", cwd: process.cwd() });
|
|
711
|
-
console.log(colors.green(`[OK] Successfully installed ${pkgName}.`));
|
|
712
|
-
} catch (err) {
|
|
713
|
-
console.error(colors.red(`[ERROR] Failed to install ${pkgName}:`), err.message);
|
|
714
|
-
}
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
/**
|
|
718
|
-
* Displays CLI command overview.
|
|
719
|
-
*/
|
|
720
|
-
function showHelp() {
|
|
721
|
-
console.log(colors.bold.cyan("\nš¦ Bluebird Framework CLI Reference"));
|
|
722
|
-
console.log(colors.gray("āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā"));
|
|
723
|
-
console.log(` ${colors.green("npx bluebird-js")} Interactive project initialization`);
|
|
724
|
-
console.log(` ${colors.green("npx bluebird-js doctor")} Runs system audit and HTTP smoke tests`);
|
|
725
|
-
console.log(` ${colors.green("npx bluebird-js make:model <Name>")} Generates a new BaseModel class`);
|
|
726
|
-
console.log(` ${colors.green("npx bluebird-js make:route <name> [--auth]")} Scaffolds REST route with validation`);
|
|
727
|
-
console.log(` ${colors.green("npx bluebird-js make:view <name> [--ejs]")} Scaffolds HTML or EJS template`);
|
|
728
|
-
console.log(` ${colors.green("npx bluebird-js make:migration <name> [--model <M>]")} Creates new SQL migration`);
|
|
729
|
-
console.log(` ${colors.green("npx bluebird-js migrate")} Applies pending SQL migrations`);
|
|
730
|
-
console.log(` ${colors.green("npx bluebird-js migrate:status")} Displays applied migration batches`);
|
|
731
|
-
console.log(` ${colors.green("npx bluebird-js migrate:rollback")} Reverts the latest migration batch`);
|
|
732
|
-
console.log(` ${colors.green("npx bluebird-js make:seed <name>")} Creates a new database seed file`);
|
|
733
|
-
console.log(` ${colors.green("npx bluebird-js seed")} Executes all seed files`);
|
|
734
|
-
console.log(` ${colors.green("npx bluebird-js nginx:conf [domain] [port] [root]")} Generates Host Nginx reverse proxy`);
|
|
735
|
-
console.log(` ${colors.green("npx bluebird-js make:ecosystem [--start]")} Generates PM2 cluster config`);
|
|
736
|
-
console.log(` ${colors.green("npx bluebird-js add <module>")} Installs optional on-demand package
|
|
737
|
-
${colors.green("npx bluebird-js add react-islands")} Installs React + Vite with Islands architecture`);
|
|
738
|
-
console.log(colors.gray("āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā\n"));
|
|
739
|
-
}
|
|
740
|
-
|
|
741
|
-
const initializer = new ProjectInit();
|
|
742
|
-
|
|
743
|
-
const args = process.argv.slice(2);
|
|
744
|
-
const command = args[0];
|
|
745
|
-
|
|
746
|
-
if (command === "make:ecosystem" || command === "ecosystem") {
|
|
747
|
-
import("./ecosystem.js");
|
|
748
|
-
} else if (command === "make:view" || command === "view") {
|
|
749
|
-
import("./view.js");
|
|
750
|
-
} else if (command === "route" || command === "make:route") {
|
|
751
|
-
import("./route.js");
|
|
752
|
-
} else if (command === "model" || command === "make:model") {
|
|
753
|
-
import("./model.js");
|
|
754
|
-
} else if (command === "doctor") {
|
|
755
|
-
import("./doctor.js");
|
|
756
|
-
} else if (
|
|
757
|
-
command === "nginx:conf" ||
|
|
758
|
-
command === "nginx:host" ||
|
|
759
|
-
command === "nginx"
|
|
760
|
-
) {
|
|
761
|
-
import("./nginx.js");
|
|
762
|
-
} else if (
|
|
763
|
-
command === "migrate" ||
|
|
764
|
-
command === "migrate:status" ||
|
|
765
|
-
command === "migrate:rollback" ||
|
|
766
|
-
command === "seed" ||
|
|
767
|
-
command === "make:migration" ||
|
|
768
|
-
command === "make:seed"
|
|
769
|
-
) {
|
|
770
|
-
import("./migrate.js");
|
|
771
|
-
} else if (command === "swagger-install") {
|
|
772
|
-
addCommand("swagger");
|
|
773
|
-
} else if (command === "add") {
|
|
774
|
-
addCommand(args[1]);
|
|
775
|
-
} else if (command === "help" || command === "--help" || command === "-h") {
|
|
776
|
-
showHelp();
|
|
777
|
-
} else {
|
|
778
|
-
initializer.run();
|
|
779
|
-
}
|
|
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 { stdin as input, stdout as output } from "node:process";
|
|
7
|
+
import crypto from "node:crypto";
|
|
8
|
+
import { execSync } from "node:child_process";
|
|
9
|
+
import colors from "../util/colors.js";
|
|
10
|
+
|
|
11
|
+
try {
|
|
12
|
+
process.loadEnvFile?.();
|
|
13
|
+
} catch {}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Initializes a new Bluebird project with interactive configuration.
|
|
17
|
+
*/
|
|
18
|
+
class ProjectInit {
|
|
19
|
+
constructor() {
|
|
20
|
+
this.appDir = process.cwd();
|
|
21
|
+
this.sourceDir = path.resolve(import.meta.dirname, "../../");
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Runs the project initialization process.
|
|
26
|
+
*/
|
|
27
|
+
async run() {
|
|
28
|
+
console.log(colors.cyan("Starting Bluebird project initialization..."));
|
|
29
|
+
|
|
30
|
+
const rl = readline.createInterface({ input, output });
|
|
31
|
+
|
|
32
|
+
let title = "Bluebird App";
|
|
33
|
+
let port = 3000;
|
|
34
|
+
let appUrl = "http://localhost:3000";
|
|
35
|
+
let dbType = "sqlite";
|
|
36
|
+
let dbName = "blue_bird";
|
|
37
|
+
let dbFile = "database/blue_bird.db";
|
|
38
|
+
let dbUser = "root";
|
|
39
|
+
let dbPassword = "root";
|
|
40
|
+
let dbPort = 3306;
|
|
41
|
+
let cacheMode = "memory";
|
|
42
|
+
|
|
43
|
+
try {
|
|
44
|
+
const isAutoYes = process.argv.includes("--yes") || process.argv.includes("-y");
|
|
45
|
+
|
|
46
|
+
const ask = async (query, defaultValue) => {
|
|
47
|
+
if (isAutoYes) return defaultValue;
|
|
48
|
+
const formattedQuery =
|
|
49
|
+
defaultValue !== undefined
|
|
50
|
+
? `${query} [${defaultValue}]: `
|
|
51
|
+
: `${query}: `;
|
|
52
|
+
const answer = await rl.question(formattedQuery);
|
|
53
|
+
return answer.trim() || defaultValue;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
title = await ask("Project Title", title);
|
|
57
|
+
|
|
58
|
+
const portInput = await ask("Server Port", port);
|
|
59
|
+
port = parseInt(portInput, 10);
|
|
60
|
+
if (Number.isNaN(port)) {
|
|
61
|
+
port = 3000;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const defaultAppUrl = `http://localhost:${port}`;
|
|
65
|
+
appUrl = await ask("Application URL", defaultAppUrl);
|
|
66
|
+
|
|
67
|
+
const dbTypeAns = await ask(
|
|
68
|
+
"Which database do you want to configure? (sqlite / mysql / postgres / none)",
|
|
69
|
+
"sqlite"
|
|
70
|
+
);
|
|
71
|
+
const cleanDbTypeAns = dbTypeAns.toLowerCase().trim();
|
|
72
|
+
if (
|
|
73
|
+
cleanDbTypeAns === "sqlite" ||
|
|
74
|
+
cleanDbTypeAns === "sqlite3" ||
|
|
75
|
+
cleanDbTypeAns === "sql" ||
|
|
76
|
+
cleanDbTypeAns === "lite"
|
|
77
|
+
) {
|
|
78
|
+
dbType = "sqlite";
|
|
79
|
+
} else if (
|
|
80
|
+
cleanDbTypeAns === "postgres" ||
|
|
81
|
+
cleanDbTypeAns === "postgresql" ||
|
|
82
|
+
cleanDbTypeAns === "pg" ||
|
|
83
|
+
cleanDbTypeAns === "psql" ||
|
|
84
|
+
cleanDbTypeAns === "pgsql"
|
|
85
|
+
) {
|
|
86
|
+
dbType = "postgres";
|
|
87
|
+
} else if (
|
|
88
|
+
cleanDbTypeAns === "mysql" ||
|
|
89
|
+
cleanDbTypeAns === "mariadb" ||
|
|
90
|
+
cleanDbTypeAns === "maria" ||
|
|
91
|
+
cleanDbTypeAns === "my"
|
|
92
|
+
) {
|
|
93
|
+
dbType = "mysql";
|
|
94
|
+
} else if (
|
|
95
|
+
cleanDbTypeAns === "none" ||
|
|
96
|
+
cleanDbTypeAns === "no" ||
|
|
97
|
+
cleanDbTypeAns === "null" ||
|
|
98
|
+
cleanDbTypeAns === "false" ||
|
|
99
|
+
cleanDbTypeAns === "0"
|
|
100
|
+
) {
|
|
101
|
+
dbType = "none";
|
|
102
|
+
} else {
|
|
103
|
+
console.log(colors.yellow(`[WARN] Unknown database '${dbTypeAns}'. Defaulting to 'sqlite'.`));
|
|
104
|
+
dbType = "sqlite";
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (dbType === "sqlite") {
|
|
108
|
+
dbName = await ask("Database Name", dbName);
|
|
109
|
+
const defaultDbFile = `database/${dbName}.db`;
|
|
110
|
+
dbFile = await ask("Database File Path", defaultDbFile);
|
|
111
|
+
const dbDir = path.dirname(path.join(this.appDir, dbFile));
|
|
112
|
+
if (!fs.existsSync(dbDir)) {
|
|
113
|
+
fs.mkdirSync(dbDir, { recursive: true });
|
|
114
|
+
}
|
|
115
|
+
} else if (dbType === "mysql") {
|
|
116
|
+
dbName = await ask("Database Name", dbName);
|
|
117
|
+
dbUser = await ask("Database User", "root");
|
|
118
|
+
dbPassword = await ask("Database Password", "root");
|
|
119
|
+
const defaultDbPort = 3306;
|
|
120
|
+
const dbPortInput = await ask("Database Port", defaultDbPort);
|
|
121
|
+
dbPort = parseInt(dbPortInput, 10);
|
|
122
|
+
if (Number.isNaN(dbPort)) {
|
|
123
|
+
dbPort = defaultDbPort;
|
|
124
|
+
}
|
|
125
|
+
} else if (dbType === "postgres") {
|
|
126
|
+
dbName = await ask("Database Name", dbName);
|
|
127
|
+
dbUser = await ask("Database User", "postgres");
|
|
128
|
+
dbPassword = await ask("Database Password", "root");
|
|
129
|
+
const defaultDbPort = 5432;
|
|
130
|
+
const dbPortInput = await ask("Database Port", defaultDbPort);
|
|
131
|
+
dbPort = parseInt(dbPortInput, 10);
|
|
132
|
+
if (Number.isNaN(dbPort)) {
|
|
133
|
+
dbPort = defaultDbPort;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const cacheChoice = await ask("Cache Engine (memory [Default] / file / redis / none)", "memory");
|
|
138
|
+
const cleanCache = cacheChoice.toLowerCase().trim();
|
|
139
|
+
cacheMode = cleanCache.startsWith("r")
|
|
140
|
+
? "redis"
|
|
141
|
+
: cleanCache.startsWith("f")
|
|
142
|
+
? "file"
|
|
143
|
+
: cleanCache.startsWith("n")
|
|
144
|
+
? "none"
|
|
145
|
+
: "memory";
|
|
146
|
+
} catch (error) {
|
|
147
|
+
console.error(colors.red("[ERROR] Error reading configuration input:"), error.message);
|
|
148
|
+
rl.close();
|
|
149
|
+
return;
|
|
150
|
+
} finally {
|
|
151
|
+
rl.close();
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const itemsToCopy = [
|
|
155
|
+
"index.js",
|
|
156
|
+
"app",
|
|
157
|
+
"public",
|
|
158
|
+
".env_example",
|
|
159
|
+
"AGENTS.md",
|
|
160
|
+
"jsconfig.json",
|
|
161
|
+
".vscode",
|
|
162
|
+
];
|
|
163
|
+
|
|
164
|
+
try {
|
|
165
|
+
itemsToCopy.forEach((item) => {
|
|
166
|
+
const src = path.join(this.sourceDir, item);
|
|
167
|
+
const dest = path.join(this.appDir, item);
|
|
168
|
+
|
|
169
|
+
if (fs.existsSync(src)) {
|
|
170
|
+
if (!fs.existsSync(dest)) {
|
|
171
|
+
this.copyRecursive(src, dest);
|
|
172
|
+
console.log(colors.green(`[OK] Copied ${item} to root.`));
|
|
173
|
+
} else {
|
|
174
|
+
console.log(colors.yellow(`[SKIP] ${item} already exists, skipping.`));
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
const gitignoreContent = "node_modules\nlogs\n.env\napp/cache\npackage-lock.json\n*.db\n*.sqlite\n*.sqlite-wal\n*.sqlite-shm\n*.db-wal\n*.db-shm\nbackups/*.sql\nbackups/*.db\n";
|
|
180
|
+
const gitignoreDest = path.join(this.appDir, ".gitignore");
|
|
181
|
+
const gitignoreSrc = path.join(this.sourceDir, ".gitignore");
|
|
182
|
+
|
|
183
|
+
if (!fs.existsSync(gitignoreDest)) {
|
|
184
|
+
if (fs.existsSync(gitignoreSrc)) {
|
|
185
|
+
fs.copyFileSync(gitignoreSrc, gitignoreDest);
|
|
186
|
+
console.log(colors.green("[OK] Copied .gitignore to root."));
|
|
187
|
+
} else {
|
|
188
|
+
fs.writeFileSync(gitignoreDest, gitignoreContent, "utf-8");
|
|
189
|
+
console.log(colors.green("[OK] Created .gitignore file."));
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const envPath = path.join(this.appDir, ".env");
|
|
194
|
+
const jwtSecret = crypto.randomBytes(32).toString("hex");
|
|
195
|
+
|
|
196
|
+
let dbEnvBlock = "";
|
|
197
|
+
if (dbType === "sqlite") {
|
|
198
|
+
dbEnvBlock = `# Database Configuration\nDB_TYPE="sqlite"\nDB_FILE="${dbFile}"\nDATABASE_URL="sqlite:${dbFile}"`;
|
|
199
|
+
} else if (dbType === "mysql") {
|
|
200
|
+
dbEnvBlock = `# Database Configuration\nDB_TYPE="mysql"\nDB_HOST="localhost"\nDB_PORT=${dbPort}\nDB_NAME="${dbName}"\nDB_USER="${dbUser}"\nDB_PASSWORD="${dbPassword}"\nDATABASE_URL="mysql://${dbUser}:${dbPassword}@localhost:${dbPort}/${dbName}"`;
|
|
201
|
+
} else if (dbType === "postgres") {
|
|
202
|
+
dbEnvBlock = `# Database Configuration\nDB_TYPE="postgres"\nDB_HOST="localhost"\nDB_PORT=${dbPort}\nDB_NAME="${dbName}"\nDB_USER="${dbUser}"\nDB_PASSWORD="${dbPassword}"\nDATABASE_URL="postgresql://${dbUser}:${dbPassword}@localhost:${dbPort}/${dbName}?schema=public"`;
|
|
203
|
+
} else {
|
|
204
|
+
dbEnvBlock = `# Database Configuration\nDB_TYPE="none"`;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const envContent = `# Server and Application Configuration
|
|
208
|
+
DEBUG=true
|
|
209
|
+
PORT=${port}
|
|
210
|
+
HOST="localhost"
|
|
211
|
+
APP_URL="${appUrl}"
|
|
212
|
+
VERSION="1.0.0"
|
|
213
|
+
|
|
214
|
+
# Application Metadata
|
|
215
|
+
TITLE="${title}"
|
|
216
|
+
DESCRIPTION="Bluebird Application"
|
|
217
|
+
|
|
218
|
+
# Security Configuration
|
|
219
|
+
JWT_SECRET="${jwtSecret}"
|
|
220
|
+
|
|
221
|
+
# Cache Configuration
|
|
222
|
+
# Options: "memory" (Fast in-memory RAM, default), "file" (Filesystem cache), "redis" (Distributed cache), "none" (Disabled)
|
|
223
|
+
CACHE_MODE="${cacheMode}"
|
|
224
|
+
CACHE_MAX_KEYS=1000
|
|
225
|
+
|
|
226
|
+
# Redis Configuration (Used when CACHE_MODE="redis" or { driver: "redis" })
|
|
227
|
+
REDIS_HOST="localhost"
|
|
228
|
+
REDIS_PORT=6379
|
|
229
|
+
REDIS_PASSWORD=""
|
|
230
|
+
|
|
231
|
+
# PM2 Clustering Configuration
|
|
232
|
+
PM2_APP_NAME="bluebird-app"
|
|
233
|
+
PM2_INSTANCES=1
|
|
234
|
+
PM2_MAX_MEMORY="512M"
|
|
235
|
+
|
|
236
|
+
${dbEnvBlock}
|
|
237
|
+
`;
|
|
238
|
+
|
|
239
|
+
if (!fs.existsSync(envPath)) {
|
|
240
|
+
fs.writeFileSync(envPath, envContent, "utf-8");
|
|
241
|
+
console.log(colors.green("[OK] Created and configured .env file."));
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
this.updatePackageJson();
|
|
245
|
+
|
|
246
|
+
const packagesToInstall = [];
|
|
247
|
+
if (dbType === "postgres") packagesToInstall.push("pg");
|
|
248
|
+
if (dbType === "mysql") packagesToInstall.push("mysql2");
|
|
249
|
+
if (cacheMode === "redis") packagesToInstall.push("redis");
|
|
250
|
+
|
|
251
|
+
if (packagesToInstall.length > 0) {
|
|
252
|
+
console.log(colors.cyan(`[INFO] Installing packages: ${packagesToInstall.join(" ")}...`));
|
|
253
|
+
try {
|
|
254
|
+
execSync(`npm install ${packagesToInstall.join(" ")}`, {
|
|
255
|
+
stdio: "inherit",
|
|
256
|
+
cwd: this.appDir,
|
|
257
|
+
});
|
|
258
|
+
console.log(colors.green(`[OK] Successfully installed ${packagesToInstall.join(" ")}.`));
|
|
259
|
+
} catch {
|
|
260
|
+
console.warn(colors.yellow("[WARN] Automatic package installation failed. Run 'npm install' manually."));
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
console.log(colors.blue("\nBluebird initialization completed!"));
|
|
265
|
+
console.log(colors.white("Next steps:"));
|
|
266
|
+
console.log(colors.bold(" npm run dev"));
|
|
267
|
+
} catch (error) {
|
|
268
|
+
console.error(colors.red("[ERROR] Error during initialization:"), error.message);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Updates package.json with scripts and dependencies.
|
|
274
|
+
* Creates package.json if it does not yet exist.
|
|
275
|
+
*/
|
|
276
|
+
updatePackageJson() {
|
|
277
|
+
const pkgPath = path.join(this.appDir, "package.json");
|
|
278
|
+
let pkg = {};
|
|
279
|
+
|
|
280
|
+
if (fs.existsSync(pkgPath)) {
|
|
281
|
+
try {
|
|
282
|
+
pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
|
|
283
|
+
} catch {}
|
|
284
|
+
} else {
|
|
285
|
+
const appName =
|
|
286
|
+
path.basename(this.appDir).toLowerCase().replace(/[^a-z0-9_-]/g, "-") ||
|
|
287
|
+
"bluebird-app";
|
|
288
|
+
pkg = {
|
|
289
|
+
name: appName,
|
|
290
|
+
version: "1.0.0",
|
|
291
|
+
type: "module",
|
|
292
|
+
dependencies: {
|
|
293
|
+
"@seip/bluebird-js": "^0.1.0",
|
|
294
|
+
},
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
pkg.scripts = pkg.scripts || {};
|
|
299
|
+
const entryFile = "index.js";
|
|
300
|
+
|
|
301
|
+
const scriptsToAdd = {
|
|
302
|
+
dev: `node --watch --env-file=.env ${entryFile}`,
|
|
303
|
+
start: `node --env-file=.env ${entryFile}`,
|
|
304
|
+
init: "bluebird-js",
|
|
305
|
+
doctor: "bluebird-js doctor",
|
|
306
|
+
route: "bluebird-js make:route",
|
|
307
|
+
view: "bluebird-js make:view",
|
|
308
|
+
model: "bluebird-js make:model",
|
|
309
|
+
"make:model": "bluebird-js make:model",
|
|
310
|
+
migrate: "bluebird-js migrate",
|
|
311
|
+
"migrate:status": "bluebird-js migrate:status",
|
|
312
|
+
"migrate:rollback": "bluebird-js migrate:rollback",
|
|
313
|
+
seed: "bluebird-js seed",
|
|
314
|
+
ecosystem: "bluebird-js make:ecosystem",
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
for (const [key, value] of Object.entries(scriptsToAdd)) {
|
|
318
|
+
pkg.scripts[key] = value;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
if (pkg.type !== "module") {
|
|
322
|
+
pkg.type = "module";
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
if (!pkg.dependencies) {
|
|
326
|
+
pkg.dependencies = {};
|
|
327
|
+
}
|
|
328
|
+
if (!pkg.dependencies["@seip/bluebird-js"]) {
|
|
329
|
+
pkg.dependencies["@seip/bluebird-js"] = "^0.1.0";
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
|
|
333
|
+
console.log(colors.green("[OK] Configured package.json with scripts and dependencies."));
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Copies a file or directory recursively.
|
|
338
|
+
* @param {string} src - Source path.
|
|
339
|
+
* @param {string} dest - Destination path.
|
|
340
|
+
*/
|
|
341
|
+
copyRecursive(src, dest) {
|
|
342
|
+
const stats = fs.statSync(src);
|
|
343
|
+
const isDirectory = stats.isDirectory();
|
|
344
|
+
|
|
345
|
+
if (isDirectory) {
|
|
346
|
+
if (!fs.existsSync(dest)) {
|
|
347
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
348
|
+
}
|
|
349
|
+
fs.readdirSync(src).forEach((childItemName) => {
|
|
350
|
+
if (
|
|
351
|
+
childItemName === "node_modules" ||
|
|
352
|
+
childItemName === "dist" ||
|
|
353
|
+
childItemName === ".git" ||
|
|
354
|
+
childItemName === "cache"
|
|
355
|
+
) {
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
this.copyRecursive(
|
|
359
|
+
path.join(src, childItemName),
|
|
360
|
+
path.join(dest, childItemName)
|
|
361
|
+
);
|
|
362
|
+
});
|
|
363
|
+
} else {
|
|
364
|
+
fs.copyFileSync(src, dest);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* Scaffolds React Islands architecture with Vite.
|
|
371
|
+
*/
|
|
372
|
+
function setupReactIslands() {
|
|
373
|
+
const appDir = process.cwd();
|
|
374
|
+
console.log(colors.cyan("[INFO] Setting up React Islands with Vite..."));
|
|
375
|
+
|
|
376
|
+
try {
|
|
377
|
+
execSync("npm install react react-dom", { stdio: "inherit", cwd: appDir });
|
|
378
|
+
execSync("npm install -D vite @vitejs/plugin-react", { stdio: "inherit", cwd: appDir });
|
|
379
|
+
console.log(colors.green("[OK] Installed React and Vite dependencies."));
|
|
380
|
+
} catch (err) {
|
|
381
|
+
console.warn(colors.yellow("[WARN] Package installation failed. Run 'npm install react react-dom && npm install -D vite @vitejs/plugin-react' manually."));
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
const viteConfigPath = path.join(appDir, "vite.config.js");
|
|
385
|
+
if (!fs.existsSync(viteConfigPath)) {
|
|
386
|
+
const viteConfigContent = `import { defineConfig } from "vite";
|
|
387
|
+
import react from "@vitejs/plugin-react";
|
|
388
|
+
|
|
389
|
+
export default defineConfig({
|
|
390
|
+
plugins: [react()],
|
|
391
|
+
build: {
|
|
392
|
+
outDir: "public/dist",
|
|
393
|
+
emptyOutDir: true,
|
|
394
|
+
manifest: true,
|
|
395
|
+
rollupOptions: {
|
|
396
|
+
input: "src/islands/main.jsx",
|
|
397
|
+
},
|
|
398
|
+
},
|
|
399
|
+
server: {
|
|
400
|
+
port: 5173,
|
|
401
|
+
strictPort: true,
|
|
402
|
+
cors: true,
|
|
403
|
+
},
|
|
404
|
+
});
|
|
405
|
+
`;
|
|
406
|
+
fs.writeFileSync(viteConfigPath, viteConfigContent, "utf-8");
|
|
407
|
+
console.log(colors.green("[OK] Created vite.config.js"));
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
const islandsDir = path.join(appDir, "src/islands");
|
|
411
|
+
if (!fs.existsSync(islandsDir)) {
|
|
412
|
+
fs.mkdirSync(islandsDir, { recursive: true });
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
const mainPath = path.join(islandsDir, "main.jsx");
|
|
416
|
+
if (!fs.existsSync(mainPath)) {
|
|
417
|
+
const mainContent = `import React from "react";
|
|
418
|
+
import ReactDOM from "react-dom/client";
|
|
419
|
+
import RadioPlayer from "./RadioPlayer.jsx";
|
|
420
|
+
import LiveCounter from "./LiveCounter.jsx";
|
|
421
|
+
|
|
422
|
+
window.__BLUEBIRD_ISLANDS__ = window.__BLUEBIRD_ISLANDS__ || {};
|
|
423
|
+
|
|
424
|
+
window.__BLUEBIRD_ISLANDS__["RadioPlayer"] = RadioPlayer;
|
|
425
|
+
window.__BLUEBIRD_ISLANDS__["LiveCounter"] = LiveCounter;
|
|
426
|
+
|
|
427
|
+
window.__BLUEBIRD_MOUNT__ = (el, Component, props) => {
|
|
428
|
+
const root = ReactDOM.createRoot(el);
|
|
429
|
+
root.render(React.createElement(Component, props));
|
|
430
|
+
return () => root.unmount();
|
|
431
|
+
};
|
|
432
|
+
|
|
433
|
+
if (window.Bluebird && typeof window.Bluebird.hydrate === "function") {
|
|
434
|
+
window.Bluebird.hydrate();
|
|
435
|
+
}
|
|
436
|
+
`;
|
|
437
|
+
fs.writeFileSync(mainPath, mainContent, "utf-8");
|
|
438
|
+
console.log(colors.green("[OK] Created src/islands/main.jsx"));
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
const radioPath = path.join(islandsDir, "RadioPlayer.jsx");
|
|
442
|
+
if (!fs.existsSync(radioPath)) {
|
|
443
|
+
const radioContent = `import React, { useState, useEffect } from "react";
|
|
444
|
+
|
|
445
|
+
export default function RadioPlayer({ title = "Bluebird Radio", streamUrl = "" }) {
|
|
446
|
+
const [isPlaying, setIsPlaying] = useState(false);
|
|
447
|
+
const [currentTrack, setCurrentTrack] = useState("Live Broadcast #1");
|
|
448
|
+
const [listeners, setListeners] = useState(142);
|
|
449
|
+
|
|
450
|
+
useEffect(() => {
|
|
451
|
+
const interval = setInterval(() => {
|
|
452
|
+
setListeners((prev) => prev + Math.floor(Math.random() * 5) - 2);
|
|
453
|
+
}, 4000);
|
|
454
|
+
|
|
455
|
+
const unsubscribe = window.Bluebird?.on?.("radio:track", (track) => {
|
|
456
|
+
if (track) setCurrentTrack(track);
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
return () => {
|
|
460
|
+
clearInterval(interval);
|
|
461
|
+
if (unsubscribe) unsubscribe();
|
|
462
|
+
};
|
|
463
|
+
}, []);
|
|
464
|
+
|
|
465
|
+
const togglePlay = () => {
|
|
466
|
+
setIsPlaying((prev) => !prev);
|
|
467
|
+
window.Bluebird?.emit?.("radio:state", { playing: !isPlaying, track: currentTrack });
|
|
468
|
+
};
|
|
469
|
+
|
|
470
|
+
return (
|
|
471
|
+
<div style={{
|
|
472
|
+
background: "linear-gradient(135deg, #0f172a 0%, #1e293b 100%)",
|
|
473
|
+
color: "#f8fafc",
|
|
474
|
+
padding: "1.25rem",
|
|
475
|
+
borderRadius: "1rem",
|
|
476
|
+
border: "1px solid #334155",
|
|
477
|
+
boxShadow: "0 10px 25px -5px rgba(0,0,0,0.3)",
|
|
478
|
+
display: "flex",
|
|
479
|
+
alignItems: "center",
|
|
480
|
+
justifyContent: "space-between",
|
|
481
|
+
gap: "1rem",
|
|
482
|
+
fontFamily: "system-ui, -apple-system, sans-serif"
|
|
483
|
+
}}>
|
|
484
|
+
<div style={{ display: "flex", alignItems: "center", gap: "1rem" }}>
|
|
485
|
+
<button
|
|
486
|
+
onClick={togglePlay}
|
|
487
|
+
style={{
|
|
488
|
+
width: "3rem",
|
|
489
|
+
height: "3rem",
|
|
490
|
+
borderRadius: "50%",
|
|
491
|
+
border: "none",
|
|
492
|
+
background: isPlaying ? "#ef4444" : "#3b82f6",
|
|
493
|
+
color: "#ffffff",
|
|
494
|
+
fontSize: "1.25rem",
|
|
495
|
+
cursor: "pointer",
|
|
496
|
+
display: "flex",
|
|
497
|
+
alignItems: "center",
|
|
498
|
+
justifyContent: "center",
|
|
499
|
+
boxShadow: isPlaying ? "0 0 15px rgba(239, 68, 68, 0.5)" : "0 0 15px rgba(59, 130, 246, 0.5)"
|
|
500
|
+
}}
|
|
501
|
+
>
|
|
502
|
+
{isPlaying ? "āø" : "ā¶"}
|
|
503
|
+
</button>
|
|
504
|
+
<div>
|
|
505
|
+
<div style={{ fontSize: "0.875rem", fontWeight: 700, color: "#93c5fd" }}>{title}</div>
|
|
506
|
+
<div style={{ fontSize: "1rem", fontWeight: 600 }}>{currentTrack}</div>
|
|
507
|
+
<div style={{ fontSize: "0.75rem", color: "#94a3b8" }}>{listeners} active listeners ⢠Live Stream</div>
|
|
508
|
+
</div>
|
|
509
|
+
</div>
|
|
510
|
+
<div style={{
|
|
511
|
+
padding: "0.25rem 0.75rem",
|
|
512
|
+
borderRadius: "9999px",
|
|
513
|
+
background: isPlaying ? "rgba(34, 197, 94, 0.2)" : "rgba(148, 163, 184, 0.2)",
|
|
514
|
+
color: isPlaying ? "#4ade80" : "#94a3b8",
|
|
515
|
+
fontSize: "0.75rem",
|
|
516
|
+
fontWeight: 700,
|
|
517
|
+
textTransform: "uppercase"
|
|
518
|
+
}}>
|
|
519
|
+
{isPlaying ? "ā On Air" : "ā Paused"}
|
|
520
|
+
</div>
|
|
521
|
+
</div>
|
|
522
|
+
);
|
|
523
|
+
}
|
|
524
|
+
`;
|
|
525
|
+
fs.writeFileSync(radioPath, radioContent, "utf-8");
|
|
526
|
+
console.log(colors.green("[OK] Created src/islands/RadioPlayer.jsx (sample persistent island)"));
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
const counterPath = path.join(islandsDir, "LiveCounter.jsx");
|
|
530
|
+
if (!fs.existsSync(counterPath)) {
|
|
531
|
+
const counterContent = `import React, { useState } from "react";
|
|
532
|
+
|
|
533
|
+
export default function LiveCounter({ initial = 0, label = "Interactive Counter" }) {
|
|
534
|
+
const [count, setCount] = useState(initial);
|
|
535
|
+
|
|
536
|
+
const increment = () => {
|
|
537
|
+
const next = count + 1;
|
|
538
|
+
setCount(next);
|
|
539
|
+
window.Bluebird?.emit?.("counter:change", next);
|
|
540
|
+
};
|
|
541
|
+
|
|
542
|
+
const decrement = () => {
|
|
543
|
+
const next = count - 1;
|
|
544
|
+
setCount(next);
|
|
545
|
+
window.Bluebird?.emit?.("counter:change", next);
|
|
546
|
+
};
|
|
547
|
+
|
|
548
|
+
return (
|
|
549
|
+
<div style={{
|
|
550
|
+
display: "inline-flex",
|
|
551
|
+
alignItems: "center",
|
|
552
|
+
gap: "0.75rem",
|
|
553
|
+
padding: "0.5rem 1rem",
|
|
554
|
+
background: "#f1f5f9",
|
|
555
|
+
borderRadius: "0.75rem",
|
|
556
|
+
border: "1px solid #cbd5e1",
|
|
557
|
+
fontFamily: "system-ui, sans-serif"
|
|
558
|
+
}}>
|
|
559
|
+
<span style={{ fontWeight: 600, color: "#334155" }}>{label}:</span>
|
|
560
|
+
<button onClick={decrement} style={{ padding: "0.25rem 0.5rem", borderRadius: "0.375rem", border: "1px solid #94a3b8", cursor: "pointer" }}>-</button>
|
|
561
|
+
<span style={{ minWidth: "1.5rem", textAlign: "center", fontWeight: 700, color: "#0f172a" }}>{count}</span>
|
|
562
|
+
<button onClick={increment} style={{ padding: "0.25rem 0.5rem", borderRadius: "0.375rem", border: "1px solid #94a3b8", cursor: "pointer" }}>+</button>
|
|
563
|
+
</div>
|
|
564
|
+
);
|
|
565
|
+
}
|
|
566
|
+
`;
|
|
567
|
+
fs.writeFileSync(counterPath, counterContent, "utf-8");
|
|
568
|
+
console.log(colors.green("[OK] Created src/islands/LiveCounter.jsx"));
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
const demoViewPath = path.join(appDir, "app/views/islands-demo.html");
|
|
572
|
+
if (!fs.existsSync(demoViewPath)) {
|
|
573
|
+
const demoContent = `<!DOCTYPE html>
|
|
574
|
+
<html lang="en">
|
|
575
|
+
<head>
|
|
576
|
+
<meta charset="UTF-8">
|
|
577
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
578
|
+
<title>{{ title }}</title>
|
|
579
|
+
<meta name="description" content="{{ description }}">
|
|
580
|
+
<link rel="stylesheet" href="/css/bluebird.min.css">
|
|
581
|
+
{{{ bluebirdHead }}}
|
|
582
|
+
</head>
|
|
583
|
+
<body style="padding: 2rem; max-width: 800px; margin: 0 auto; font-family: system-ui, sans-serif;">
|
|
584
|
+
<header style="margin-bottom: 2rem; border-bottom: 1px solid #e2e8f0; padding-bottom: 1rem;">
|
|
585
|
+
<h1>{{ title }}</h1>
|
|
586
|
+
<p style="color: #64748b;">{{ description }}</p>
|
|
587
|
+
<nav style="display: flex; gap: 1rem; margin-top: 1rem;">
|
|
588
|
+
<a href="/islands-demo">Demo Home</a>
|
|
589
|
+
<a href="/about">About Us (Test Navigation)</a>
|
|
590
|
+
</nav>
|
|
591
|
+
</header>
|
|
592
|
+
|
|
593
|
+
<main style="display: flex; flex-direction: column; gap: 2rem;">
|
|
594
|
+
<section>
|
|
595
|
+
<h2>1. Persistent Audio Stream Island</h2>
|
|
596
|
+
<p style="color: #64748b; font-size: 0.9rem;">
|
|
597
|
+
Click Play, then navigate to other pages above. Notice the audio player keeps playing without interrupting!
|
|
598
|
+
</p>
|
|
599
|
+
<div data-island="RadioPlayer" data-persist="true" data-props='{"title": "Bluebird Live FM"}'></div>
|
|
600
|
+
</section>
|
|
601
|
+
|
|
602
|
+
<section>
|
|
603
|
+
<h2>2. Standard Reactive Island</h2>
|
|
604
|
+
<p style="color: #64748b; font-size: 0.9rem;">
|
|
605
|
+
Interactive state-driven React component rendered inside pure SSR HTML.
|
|
606
|
+
</p>
|
|
607
|
+
<div data-island="LiveCounter" data-props='{"initial": 10, "label": "Session Taps"}'></div>
|
|
608
|
+
</section>
|
|
609
|
+
</main>
|
|
610
|
+
|
|
611
|
+
<script src="/js/bluebird-client.js"></script>
|
|
612
|
+
</body>
|
|
613
|
+
</html>
|
|
614
|
+
`;
|
|
615
|
+
fs.writeFileSync(demoViewPath, demoContent, "utf-8");
|
|
616
|
+
console.log(colors.green("[OK] Created app/views/islands-demo.html"));
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
const pkgPath = path.join(appDir, "package.json");
|
|
620
|
+
if (fs.existsSync(pkgPath)) {
|
|
621
|
+
try {
|
|
622
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
|
|
623
|
+
pkg.scripts = pkg.scripts || {};
|
|
624
|
+
pkg.scripts["build:client"] = "vite build";
|
|
625
|
+
pkg.scripts["dev:client"] = "vite";
|
|
626
|
+
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
|
|
627
|
+
console.log(colors.green("[OK] Added 'build:client' and 'dev:client' scripts to package.json"));
|
|
628
|
+
} catch {}
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
console.log(colors.bold.green("\nReact Islands setup complete!"));
|
|
632
|
+
console.log(colors.white("Next steps:"));
|
|
633
|
+
console.log(colors.cyan(" 1. In development, start Vite in a separate terminal:"));
|
|
634
|
+
console.log(colors.bold(" npm run dev:client"));
|
|
635
|
+
console.log(colors.cyan(" 2. In production, compile your islands before starting:"));
|
|
636
|
+
console.log(colors.bold(" npm run build:client"));
|
|
637
|
+
console.log(colors.cyan(" 3. View the live demo by registering a route in app/routes/web.js:"));
|
|
638
|
+
console.log(colors.bold(' routerWeb.get("/islands-demo", Render.view("islands-demo", { title: "Islands Demo", description: "Bluebird React Islands" }));\n'));
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
/**
|
|
642
|
+
* Handles adding on-demand modules and dependencies.
|
|
643
|
+
* @param {string} [feature]
|
|
644
|
+
*/
|
|
645
|
+
function addCommand(feature) {
|
|
646
|
+
if (!feature) {
|
|
647
|
+
console.log(colors.yellow("Usage: npx bluebird-js add <feature>"));
|
|
648
|
+
console.log("Available features:");
|
|
649
|
+
console.log(" react | islands - Installs React + Vite with Islands architecture");
|
|
650
|
+
console.log(" upload | multer - Installs multer for file uploads");
|
|
651
|
+
console.log(" ws | websocket - Installs ws for WebSockets");
|
|
652
|
+
console.log(" redis - Installs redis for distributed caching and sessions");
|
|
653
|
+
console.log(" sqlite - Installs better-sqlite3 (fallback for older environments)");
|
|
654
|
+
console.log(" mysql - Installs mysql2 for MySQL database");
|
|
655
|
+
console.log(" postgres | pg - Installs pg for PostgreSQL database");
|
|
656
|
+
console.log(" bcrypt - Installs bcrypt for password hashing");
|
|
657
|
+
console.log(" swagger - Installs swagger-ui-express for API docs");
|
|
658
|
+
console.log(" helmet - Installs helmet for advanced security headers");
|
|
659
|
+
console.log(" ejs - Installs ejs for server-side template rendering");
|
|
660
|
+
return;
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
const cleanFeature = feature.toLowerCase().trim();
|
|
664
|
+
|
|
665
|
+
if (
|
|
666
|
+
cleanFeature === "react" ||
|
|
667
|
+
cleanFeature === "react-islands" ||
|
|
668
|
+
cleanFeature === "islands"
|
|
669
|
+
) {
|
|
670
|
+
setupReactIslands();
|
|
671
|
+
return;
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
const packageMap = {
|
|
675
|
+
upload: "multer",
|
|
676
|
+
multer: "multer",
|
|
677
|
+
ws: "ws",
|
|
678
|
+
websocket: "ws",
|
|
679
|
+
websockets: "ws",
|
|
680
|
+
redis: "redis",
|
|
681
|
+
sqlite: "better-sqlite3",
|
|
682
|
+
"better-sqlite3": "better-sqlite3",
|
|
683
|
+
mysql: "mysql2",
|
|
684
|
+
mysql2: "mysql2",
|
|
685
|
+
mariadb: "mysql2",
|
|
686
|
+
maria: "mysql2",
|
|
687
|
+
postgres: "pg",
|
|
688
|
+
postgresql: "pg",
|
|
689
|
+
pg: "pg",
|
|
690
|
+
psql: "pg",
|
|
691
|
+
pgsql: "pg",
|
|
692
|
+
psgr: "pg",
|
|
693
|
+
postgre: "pg",
|
|
694
|
+
postgr: "pg",
|
|
695
|
+
bcrypt: "bcrypt",
|
|
696
|
+
swagger: "swagger-ui-express swagger-jsdoc",
|
|
697
|
+
helmet: "helmet",
|
|
698
|
+
ejs: "ejs",
|
|
699
|
+
};
|
|
700
|
+
|
|
701
|
+
const pkgName = packageMap[cleanFeature];
|
|
702
|
+
if (!pkgName) {
|
|
703
|
+
console.error(colors.red(`[ERROR] Unknown feature '${feature}'.`));
|
|
704
|
+
console.log("Run 'npx bluebird-js add' to see available features.");
|
|
705
|
+
return;
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
console.log(colors.cyan(`[INFO] Installing ${pkgName}...`));
|
|
709
|
+
try {
|
|
710
|
+
execSync(`npm install ${pkgName}`, { stdio: "inherit", cwd: process.cwd() });
|
|
711
|
+
console.log(colors.green(`[OK] Successfully installed ${pkgName}.`));
|
|
712
|
+
} catch (err) {
|
|
713
|
+
console.error(colors.red(`[ERROR] Failed to install ${pkgName}:`), err.message);
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
/**
|
|
718
|
+
* Displays CLI command overview.
|
|
719
|
+
*/
|
|
720
|
+
function showHelp() {
|
|
721
|
+
console.log(colors.bold.cyan("\nš¦ Bluebird Framework CLI Reference"));
|
|
722
|
+
console.log(colors.gray("āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā"));
|
|
723
|
+
console.log(` ${colors.green("npx bluebird-js")} Interactive project initialization`);
|
|
724
|
+
console.log(` ${colors.green("npx bluebird-js doctor")} Runs system audit and HTTP smoke tests`);
|
|
725
|
+
console.log(` ${colors.green("npx bluebird-js make:model <Name>")} Generates a new BaseModel class`);
|
|
726
|
+
console.log(` ${colors.green("npx bluebird-js make:route <name> [--auth]")} Scaffolds REST route with validation`);
|
|
727
|
+
console.log(` ${colors.green("npx bluebird-js make:view <name> [--ejs]")} Scaffolds HTML or EJS template`);
|
|
728
|
+
console.log(` ${colors.green("npx bluebird-js make:migration <name> [--model <M>]")} Creates new SQL migration`);
|
|
729
|
+
console.log(` ${colors.green("npx bluebird-js migrate")} Applies pending SQL migrations`);
|
|
730
|
+
console.log(` ${colors.green("npx bluebird-js migrate:status")} Displays applied migration batches`);
|
|
731
|
+
console.log(` ${colors.green("npx bluebird-js migrate:rollback")} Reverts the latest migration batch`);
|
|
732
|
+
console.log(` ${colors.green("npx bluebird-js make:seed <name>")} Creates a new database seed file`);
|
|
733
|
+
console.log(` ${colors.green("npx bluebird-js seed")} Executes all seed files`);
|
|
734
|
+
console.log(` ${colors.green("npx bluebird-js nginx:conf [domain] [port] [root]")} Generates Host Nginx reverse proxy`);
|
|
735
|
+
console.log(` ${colors.green("npx bluebird-js make:ecosystem [--start]")} Generates PM2 cluster config`);
|
|
736
|
+
console.log(` ${colors.green("npx bluebird-js add <module>")} Installs optional on-demand package
|
|
737
|
+
${colors.green("npx bluebird-js add react-islands")} Installs React + Vite with Islands architecture`);
|
|
738
|
+
console.log(colors.gray("āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā\n"));
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
const initializer = new ProjectInit();
|
|
742
|
+
|
|
743
|
+
const args = process.argv.slice(2);
|
|
744
|
+
const command = args[0];
|
|
745
|
+
|
|
746
|
+
if (command === "make:ecosystem" || command === "ecosystem") {
|
|
747
|
+
import("./ecosystem.js");
|
|
748
|
+
} else if (command === "make:view" || command === "view") {
|
|
749
|
+
import("./view.js");
|
|
750
|
+
} else if (command === "route" || command === "make:route") {
|
|
751
|
+
import("./route.js");
|
|
752
|
+
} else if (command === "model" || command === "make:model") {
|
|
753
|
+
import("./model.js");
|
|
754
|
+
} else if (command === "doctor") {
|
|
755
|
+
import("./doctor.js");
|
|
756
|
+
} else if (
|
|
757
|
+
command === "nginx:conf" ||
|
|
758
|
+
command === "nginx:host" ||
|
|
759
|
+
command === "nginx"
|
|
760
|
+
) {
|
|
761
|
+
import("./nginx.js");
|
|
762
|
+
} else if (
|
|
763
|
+
command === "migrate" ||
|
|
764
|
+
command === "migrate:status" ||
|
|
765
|
+
command === "migrate:rollback" ||
|
|
766
|
+
command === "seed" ||
|
|
767
|
+
command === "make:migration" ||
|
|
768
|
+
command === "make:seed"
|
|
769
|
+
) {
|
|
770
|
+
import("./migrate.js");
|
|
771
|
+
} else if (command === "swagger-install") {
|
|
772
|
+
addCommand("swagger");
|
|
773
|
+
} else if (command === "add") {
|
|
774
|
+
addCommand(args[1]);
|
|
775
|
+
} else if (command === "help" || command === "--help" || command === "-h") {
|
|
776
|
+
showHelp();
|
|
777
|
+
} else {
|
|
778
|
+
initializer.run();
|
|
779
|
+
}
|