@seip/bluebird-js 0.0.1 → 0.1.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/.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/ecosystem.js
CHANGED
|
@@ -1,162 +1,162 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import fs from "node:fs";
|
|
4
|
-
import path from "node:path";
|
|
5
|
-
import { execSync } from "node:child_process";
|
|
6
|
-
import colors from "../util/colors.js";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Parses .env file into a key-value map.
|
|
10
|
-
* @param {string} envPath
|
|
11
|
-
* @returns {Record<string, string>}
|
|
12
|
-
*/
|
|
13
|
-
function parseEnv(envPath) {
|
|
14
|
-
const env = {};
|
|
15
|
-
if (!fs.existsSync(envPath)) return env;
|
|
16
|
-
const lines = fs.readFileSync(envPath, "utf-8").split("\n");
|
|
17
|
-
for (const line of lines) {
|
|
18
|
-
const trimmed = line.trim();
|
|
19
|
-
if (!trimmed || trimmed.startsWith("#") || !trimmed.includes("=")) continue;
|
|
20
|
-
const idx = trimmed.indexOf("=");
|
|
21
|
-
const key = trimmed.substring(0, idx).trim();
|
|
22
|
-
let val = trimmed.substring(idx + 1).trim();
|
|
23
|
-
if ((val.startsWith('"') && val.endsWith('"')) || (val.startsWith("'") && val.endsWith("'"))) {
|
|
24
|
-
val = val.slice(1, -1);
|
|
25
|
-
}
|
|
26
|
-
env[key] = val;
|
|
27
|
-
}
|
|
28
|
-
return env;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Detects job files inside app/jobs/ directory.
|
|
33
|
-
* @param {string} jobsDir
|
|
34
|
-
* @returns {string[]} Relative paths to job files.
|
|
35
|
-
*/
|
|
36
|
-
function detectJobs(jobsDir) {
|
|
37
|
-
if (!fs.existsSync(jobsDir)) return [];
|
|
38
|
-
try {
|
|
39
|
-
return fs
|
|
40
|
-
.readdirSync(jobsDir)
|
|
41
|
-
.filter((f) => f.endsWith(".js") || f.endsWith(".mjs"))
|
|
42
|
-
.map((f) => path.join("app/jobs", f).replace(/\\/g, "/"));
|
|
43
|
-
} catch {
|
|
44
|
-
return [];
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Generates the PM2 ecosystem.config.cjs file for standalone deployments.
|
|
50
|
-
*/
|
|
51
|
-
function makeEcosystem() {
|
|
52
|
-
const cwd = process.cwd();
|
|
53
|
-
const envPath = path.join(cwd, ".env");
|
|
54
|
-
const outputPath = path.join(cwd, "ecosystem.config.cjs");
|
|
55
|
-
|
|
56
|
-
const env = parseEnv(envPath);
|
|
57
|
-
const instances = parseInt(env.PM2_INSTANCES || "1", 10);
|
|
58
|
-
const execMode = instances > 1 ? "cluster" : "fork";
|
|
59
|
-
const appName = (env.PM2_APP_NAME || env.TITLE || path.basename(cwd) || "bluebird-app")
|
|
60
|
-
.toLowerCase()
|
|
61
|
-
.replace(/[^a-z0-9_-]/g, "-");
|
|
62
|
-
|
|
63
|
-
const entryScript = "index.js";
|
|
64
|
-
|
|
65
|
-
const jobsDir = path.join(cwd, "app/jobs");
|
|
66
|
-
const jobs = detectJobs(jobsDir);
|
|
67
|
-
|
|
68
|
-
const mainApp = {
|
|
69
|
-
name: appName,
|
|
70
|
-
script: entryScript,
|
|
71
|
-
instances,
|
|
72
|
-
exec_mode: execMode,
|
|
73
|
-
node_args: "--env-file=.env",
|
|
74
|
-
env: {
|
|
75
|
-
NODE_ENV: "production",
|
|
76
|
-
DEBUG: "false",
|
|
77
|
-
},
|
|
78
|
-
max_memory_restart: env.PM2_MAX_MEMORY || "512M",
|
|
79
|
-
error_file: "logs/pm2-error.log",
|
|
80
|
-
out_file: "logs/pm2-out.log",
|
|
81
|
-
log_date_format: "YYYY-MM-DD HH:mm:ss",
|
|
82
|
-
autorestart: true,
|
|
83
|
-
watch: false,
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
const workerApps = jobs.map((jobFile) => {
|
|
87
|
-
const jobName = path.basename(jobFile, path.extname(jobFile));
|
|
88
|
-
return {
|
|
89
|
-
name: `${appName}-worker-${jobName}`,
|
|
90
|
-
script: jobFile,
|
|
91
|
-
instances: 1,
|
|
92
|
-
exec_mode: "fork",
|
|
93
|
-
node_args: "--env-file=.env",
|
|
94
|
-
env: {
|
|
95
|
-
NODE_ENV: "production",
|
|
96
|
-
DEBUG: "false",
|
|
97
|
-
},
|
|
98
|
-
max_memory_restart: "256M",
|
|
99
|
-
error_file: `logs/pm2-worker-${jobName}-error.log`,
|
|
100
|
-
out_file: `logs/pm2-worker-${jobName}-out.log`,
|
|
101
|
-
log_date_format: "YYYY-MM-DD HH:mm:ss",
|
|
102
|
-
autorestart: true,
|
|
103
|
-
watch: false,
|
|
104
|
-
};
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
const allApps = [mainApp, ...workerApps];
|
|
108
|
-
|
|
109
|
-
const fileContent = `/**
|
|
110
|
-
* Generated by: npx bluebird-js make:ecosystem
|
|
111
|
-
* Deployment mode: ${execMode} (PM2_INSTANCES=${instances})
|
|
112
|
-
*
|
|
113
|
-
* Usage:
|
|
114
|
-
* pm2 start ecosystem.config.cjs
|
|
115
|
-
* pm2 reload ecosystem.config.cjs --update-env
|
|
116
|
-
* pm2 delete ecosystem.config.cjs
|
|
117
|
-
*/
|
|
118
|
-
|
|
119
|
-
module.exports = {
|
|
120
|
-
apps: ${JSON.stringify(allApps, null, 4)}
|
|
121
|
-
};
|
|
122
|
-
`;
|
|
123
|
-
|
|
124
|
-
if (fs.existsSync(outputPath)) {
|
|
125
|
-
console.log(colors.yellow("[WARN] ecosystem.config.cjs already exists. Overwriting."));
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
try {
|
|
129
|
-
fs.mkdirSync(path.join(cwd, "logs"), { recursive: true });
|
|
130
|
-
fs.writeFileSync(outputPath, fileContent, "utf-8");
|
|
131
|
-
console.log(colors.green(`[OK] Generated ecosystem.config.cjs (${instances} instance(s), mode: ${execMode}, app: ${appName}).`));
|
|
132
|
-
|
|
133
|
-
if (jobs.length > 0) {
|
|
134
|
-
console.log(colors.cyan(`[INFO] Detected ${jobs.length} worker job(s):`));
|
|
135
|
-
jobs.forEach((j) => console.log(colors.gray(` - ${j}`)));
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
const shouldStart = process.argv.includes("--start");
|
|
139
|
-
if (shouldStart) {
|
|
140
|
-
console.log(colors.cyan("[INFO] Starting application with PM2 and saving process list..."));
|
|
141
|
-
try {
|
|
142
|
-
execSync("pm2 start ecosystem.config.cjs", { stdio: "inherit", cwd });
|
|
143
|
-
execSync("pm2 save", { stdio: "inherit", cwd });
|
|
144
|
-
console.log(colors.green(`[OK] Successfully started '${appName}' in PM2 and saved process state.`));
|
|
145
|
-
} catch (pm2Err) {
|
|
146
|
-
console.error(colors.red("[ERROR] Failed to run PM2 commands. Make sure PM2 is installed: npm install -g pm2"), pm2Err.message);
|
|
147
|
-
}
|
|
148
|
-
} else {
|
|
149
|
-
console.log("");
|
|
150
|
-
console.log(colors.bold("Next steps for production:"));
|
|
151
|
-
console.log(colors.gray(" pm2 start ecosystem.config.cjs"));
|
|
152
|
-
console.log(colors.gray(" pm2 save"));
|
|
153
|
-
console.log(colors.gray(" pm2 startup"));
|
|
154
|
-
console.log("");
|
|
155
|
-
console.log(colors.gray("Tip: Run 'npx bluebird-js make:ecosystem --start' to generate and launch immediately."));
|
|
156
|
-
}
|
|
157
|
-
} catch (err) {
|
|
158
|
-
console.error(colors.red("[ERROR] Failed to generate ecosystem.config.cjs:"), err.message);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
makeEcosystem();
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { execSync } from "node:child_process";
|
|
6
|
+
import colors from "../util/colors.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Parses .env file into a key-value map.
|
|
10
|
+
* @param {string} envPath
|
|
11
|
+
* @returns {Record<string, string>}
|
|
12
|
+
*/
|
|
13
|
+
function parseEnv(envPath) {
|
|
14
|
+
const env = {};
|
|
15
|
+
if (!fs.existsSync(envPath)) return env;
|
|
16
|
+
const lines = fs.readFileSync(envPath, "utf-8").split("\n");
|
|
17
|
+
for (const line of lines) {
|
|
18
|
+
const trimmed = line.trim();
|
|
19
|
+
if (!trimmed || trimmed.startsWith("#") || !trimmed.includes("=")) continue;
|
|
20
|
+
const idx = trimmed.indexOf("=");
|
|
21
|
+
const key = trimmed.substring(0, idx).trim();
|
|
22
|
+
let val = trimmed.substring(idx + 1).trim();
|
|
23
|
+
if ((val.startsWith('"') && val.endsWith('"')) || (val.startsWith("'") && val.endsWith("'"))) {
|
|
24
|
+
val = val.slice(1, -1);
|
|
25
|
+
}
|
|
26
|
+
env[key] = val;
|
|
27
|
+
}
|
|
28
|
+
return env;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Detects job files inside app/jobs/ directory.
|
|
33
|
+
* @param {string} jobsDir
|
|
34
|
+
* @returns {string[]} Relative paths to job files.
|
|
35
|
+
*/
|
|
36
|
+
function detectJobs(jobsDir) {
|
|
37
|
+
if (!fs.existsSync(jobsDir)) return [];
|
|
38
|
+
try {
|
|
39
|
+
return fs
|
|
40
|
+
.readdirSync(jobsDir)
|
|
41
|
+
.filter((f) => f.endsWith(".js") || f.endsWith(".mjs"))
|
|
42
|
+
.map((f) => path.join("app/jobs", f).replace(/\\/g, "/"));
|
|
43
|
+
} catch {
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Generates the PM2 ecosystem.config.cjs file for standalone deployments.
|
|
50
|
+
*/
|
|
51
|
+
function makeEcosystem() {
|
|
52
|
+
const cwd = process.cwd();
|
|
53
|
+
const envPath = path.join(cwd, ".env");
|
|
54
|
+
const outputPath = path.join(cwd, "ecosystem.config.cjs");
|
|
55
|
+
|
|
56
|
+
const env = parseEnv(envPath);
|
|
57
|
+
const instances = parseInt(env.PM2_INSTANCES || "1", 10);
|
|
58
|
+
const execMode = instances > 1 ? "cluster" : "fork";
|
|
59
|
+
const appName = (env.PM2_APP_NAME || env.TITLE || path.basename(cwd) || "bluebird-app")
|
|
60
|
+
.toLowerCase()
|
|
61
|
+
.replace(/[^a-z0-9_-]/g, "-");
|
|
62
|
+
|
|
63
|
+
const entryScript = "index.js";
|
|
64
|
+
|
|
65
|
+
const jobsDir = path.join(cwd, "app/jobs");
|
|
66
|
+
const jobs = detectJobs(jobsDir);
|
|
67
|
+
|
|
68
|
+
const mainApp = {
|
|
69
|
+
name: appName,
|
|
70
|
+
script: entryScript,
|
|
71
|
+
instances,
|
|
72
|
+
exec_mode: execMode,
|
|
73
|
+
node_args: "--env-file=.env",
|
|
74
|
+
env: {
|
|
75
|
+
NODE_ENV: "production",
|
|
76
|
+
DEBUG: "false",
|
|
77
|
+
},
|
|
78
|
+
max_memory_restart: env.PM2_MAX_MEMORY || "512M",
|
|
79
|
+
error_file: "logs/pm2-error.log",
|
|
80
|
+
out_file: "logs/pm2-out.log",
|
|
81
|
+
log_date_format: "YYYY-MM-DD HH:mm:ss",
|
|
82
|
+
autorestart: true,
|
|
83
|
+
watch: false,
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const workerApps = jobs.map((jobFile) => {
|
|
87
|
+
const jobName = path.basename(jobFile, path.extname(jobFile));
|
|
88
|
+
return {
|
|
89
|
+
name: `${appName}-worker-${jobName}`,
|
|
90
|
+
script: jobFile,
|
|
91
|
+
instances: 1,
|
|
92
|
+
exec_mode: "fork",
|
|
93
|
+
node_args: "--env-file=.env",
|
|
94
|
+
env: {
|
|
95
|
+
NODE_ENV: "production",
|
|
96
|
+
DEBUG: "false",
|
|
97
|
+
},
|
|
98
|
+
max_memory_restart: "256M",
|
|
99
|
+
error_file: `logs/pm2-worker-${jobName}-error.log`,
|
|
100
|
+
out_file: `logs/pm2-worker-${jobName}-out.log`,
|
|
101
|
+
log_date_format: "YYYY-MM-DD HH:mm:ss",
|
|
102
|
+
autorestart: true,
|
|
103
|
+
watch: false,
|
|
104
|
+
};
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
const allApps = [mainApp, ...workerApps];
|
|
108
|
+
|
|
109
|
+
const fileContent = `/**
|
|
110
|
+
* Generated by: npx bluebird-js make:ecosystem
|
|
111
|
+
* Deployment mode: ${execMode} (PM2_INSTANCES=${instances})
|
|
112
|
+
*
|
|
113
|
+
* Usage:
|
|
114
|
+
* pm2 start ecosystem.config.cjs
|
|
115
|
+
* pm2 reload ecosystem.config.cjs --update-env
|
|
116
|
+
* pm2 delete ecosystem.config.cjs
|
|
117
|
+
*/
|
|
118
|
+
|
|
119
|
+
module.exports = {
|
|
120
|
+
apps: ${JSON.stringify(allApps, null, 4)}
|
|
121
|
+
};
|
|
122
|
+
`;
|
|
123
|
+
|
|
124
|
+
if (fs.existsSync(outputPath)) {
|
|
125
|
+
console.log(colors.yellow("[WARN] ecosystem.config.cjs already exists. Overwriting."));
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
try {
|
|
129
|
+
fs.mkdirSync(path.join(cwd, "logs"), { recursive: true });
|
|
130
|
+
fs.writeFileSync(outputPath, fileContent, "utf-8");
|
|
131
|
+
console.log(colors.green(`[OK] Generated ecosystem.config.cjs (${instances} instance(s), mode: ${execMode}, app: ${appName}).`));
|
|
132
|
+
|
|
133
|
+
if (jobs.length > 0) {
|
|
134
|
+
console.log(colors.cyan(`[INFO] Detected ${jobs.length} worker job(s):`));
|
|
135
|
+
jobs.forEach((j) => console.log(colors.gray(` - ${j}`)));
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const shouldStart = process.argv.includes("--start");
|
|
139
|
+
if (shouldStart) {
|
|
140
|
+
console.log(colors.cyan("[INFO] Starting application with PM2 and saving process list..."));
|
|
141
|
+
try {
|
|
142
|
+
execSync("pm2 start ecosystem.config.cjs", { stdio: "inherit", cwd });
|
|
143
|
+
execSync("pm2 save", { stdio: "inherit", cwd });
|
|
144
|
+
console.log(colors.green(`[OK] Successfully started '${appName}' in PM2 and saved process state.`));
|
|
145
|
+
} catch (pm2Err) {
|
|
146
|
+
console.error(colors.red("[ERROR] Failed to run PM2 commands. Make sure PM2 is installed: npm install -g pm2"), pm2Err.message);
|
|
147
|
+
}
|
|
148
|
+
} else {
|
|
149
|
+
console.log("");
|
|
150
|
+
console.log(colors.bold("Next steps for production:"));
|
|
151
|
+
console.log(colors.gray(" pm2 start ecosystem.config.cjs"));
|
|
152
|
+
console.log(colors.gray(" pm2 save"));
|
|
153
|
+
console.log(colors.gray(" pm2 startup"));
|
|
154
|
+
console.log("");
|
|
155
|
+
console.log(colors.gray("Tip: Run 'npx bluebird-js make:ecosystem --start' to generate and launch immediately."));
|
|
156
|
+
}
|
|
157
|
+
} catch (err) {
|
|
158
|
+
console.error(colors.red("[ERROR] Failed to generate ecosystem.config.cjs:"), err.message);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
makeEcosystem();
|