Skip to content

Commit 325d0ea

Browse files
committed
feat: added system requirements checker
1 parent 4b578c1 commit 325d0ea

4 files changed

Lines changed: 112 additions & 0 deletions

File tree

package-lock.json

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"openai": "^5.10.2",
4343
"qrcode-terminal": "^0.12.0",
4444
"redis": "^5.6.0",
45+
"semver": "^7.7.2",
4546
"systeminformation": "^5.27.7",
4647
"whatsapp-web.js": "^1.31.0",
4748
"youtubei.js": "^15.0.0"
@@ -51,6 +52,7 @@
5152
"@types/dotenv": "^6.1.1",
5253
"@types/node": "^24.0.14",
5354
"@types/npmlog": "^7.0.0",
55+
"@types/semver": "^7.7.1",
5456
"prisma": "^6.12.0",
5557
"ts-node": "^10.9.2",
5658
"typescript": "^5.8.3"
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import { execSync } from "child_process";
2+
import * as process from "process";
3+
import semver from "semver";
4+
import log from "./log";
5+
import url from "url";
6+
7+
function checkNodeVersion() {
8+
const current = process.versions.node;
9+
const required = ">=24.0.0";
10+
if (!semver.satisfies(current, required)) {
11+
log.warn("Requirements", `Node.js ${required} required, found ${current}`);
12+
} else {
13+
log.info("Requirements", `Node.js version OK: ${current}`);
14+
}
15+
}
16+
17+
function safePrintDBUrl(dbUrl: string, fallback: string) {
18+
try {
19+
const parsed = new url.URL(dbUrl);
20+
return `${parsed.protocol}//${parsed.hostname}:${parsed.port || ""}`;
21+
} catch {
22+
return fallback;
23+
}
24+
}
25+
26+
function checkMySQL() {
27+
const dbUrl = process.env.DATABASE_URL || "mysql://root@127.0.0.1:3306";
28+
try {
29+
const version = execSync("mysql --version").toString().trim();
30+
log.info(
31+
"Requirements",
32+
`MySQL available at ${safePrintDBUrl(dbUrl, "mysql://127.0.0.1:3306")} | ${version}`,
33+
);
34+
} catch {
35+
log.error("Requirements", "MySQL is required but not found (install mysql-client or ensure server is accessible).");
36+
process.exit(1);
37+
}
38+
}
39+
40+
function checkRedis() {
41+
const redisUrl = process.env.REDIS_URL || "redis://localhost:6379";
42+
try {
43+
const version = execSync("redis-cli --version").toString().trim();
44+
log.info(
45+
"Requirements",
46+
`Redis available at ${safePrintDBUrl(redisUrl, "redis://localhost:6379")} | ${version}`,
47+
);
48+
} catch {
49+
log.error("Requirements", "Redis is required but not found (install redis-cli or ensure server is running).");
50+
process.exit(1);
51+
}
52+
}
53+
54+
function checkChrome() {
55+
try {
56+
const version = execSync("google-chrome-stable --version").toString().trim();
57+
log.info("Requirements", `Google Chrome installed | ${version}`);
58+
} catch {
59+
try {
60+
const version = execSync("chromium --version").toString().trim();
61+
log.info("Requirements", `Chromium installed | ${version}`);
62+
} catch {
63+
log.error("Requirements", "Google Chrome/Chromium is required but not found.");
64+
process.exit(1);
65+
}
66+
}
67+
}
68+
69+
function checkFFMPEG() {
70+
try {
71+
const version = execSync("ffmpeg -version").toString().split("\n")[0].trim();
72+
log.info("Requirements", `FFmpeg installed | ${version}`);
73+
} catch {
74+
log.warn("Requirements", "FFmpeg not found. Some features may not work.");
75+
}
76+
}
77+
78+
export function checkRequirements() {
79+
log.info("Requirements", "Checking system requirements...");
80+
checkNodeVersion();
81+
checkMySQL();
82+
checkRedis();
83+
checkChrome();
84+
checkFFMPEG();
85+
log.info("Requirements", "System check complete.");
86+
}

src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import dotenv from "dotenv";
22
dotenv.config();
33

4+
import { checkRequirements } from "./components/utils/requirements";
45
import { Message } from "whatsapp-web.js";
56
import fs from "fs";
67
import path from "path";
@@ -20,6 +21,8 @@ import {
2021
greetings,
2122
} from "./components/utils/data";
2223

24+
checkRequirements();
25+
2326
const commandPrefix = process.env.COMMAND_PREFIX || "!";
2427
const botName = process.env.PROJECT_CANIS_ALIAS || "Canis";
2528
const autoReload = process.env.AUTO_RELOAD === "true";

0 commit comments

Comments
 (0)