|
| 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 | +} |
0 commit comments