mirror of
https://github.com/Pandipipas/scoreko-electron-dev.git
synced 2026-06-05 21:22:07 +00:00
41e4e91c4b
- Update .gitignore and .prettierignore to exclude additional cache and configuration files. - Revise README.md for clarity on build processes and runtime behavior. - Improve architecture documentation to reflect changes in startup flow and module responsibilities. - Modify troubleshooting guide to address common runtime issues and installation steps. - Enhance ESLint configuration to ignore more directories. - Update package.json scripts for better build and distribution processes. - Introduce build-scoreko-bundle.mjs for building the Scoreko bundle. - Implement prepare-nodecg-runtime.mjs for managing NodeCG runtime installation and updates. - Add runtime-provisioner.ts to handle user-specific NodeCG runtime provisioning. - Create tests for runtime provisioning to ensure correct behavior. - Refactor process-manager.ts and main.ts to integrate new runtime management logic.
103 lines
3.2 KiB
JavaScript
103 lines
3.2 KiB
JavaScript
#!/usr/bin/env node
|
|
import fs from "node:fs";
|
|
import net from "node:net";
|
|
import path from "node:path";
|
|
|
|
const cwd = process.cwd();
|
|
const nodecgRootPath = path.resolve(cwd, "lib", "nodecg");
|
|
|
|
const checks = [];
|
|
|
|
function addCheck(ok, title, details) {
|
|
checks.push({ ok, title, details });
|
|
}
|
|
|
|
function parsePort(name, fallback) {
|
|
const raw = process.env[name] ?? fallback;
|
|
const parsed = Number.parseInt(raw, 10);
|
|
if (!Number.isFinite(parsed) || parsed < 1 || parsed > 65535) {
|
|
addCheck(false, `${name} invalid`, `It must be an integer between 1 and 65535. Received value: '${raw}'.`);
|
|
return null;
|
|
}
|
|
|
|
addCheck(true, `${name} valid`, `${parsed}`);
|
|
return parsed;
|
|
}
|
|
|
|
function parseIntInRange(name, fallback, min, max) {
|
|
const raw = process.env[name] ?? String(fallback);
|
|
const parsed = Number.parseInt(raw, 10);
|
|
if (!Number.isFinite(parsed) || parsed < min || parsed > max) {
|
|
addCheck(false, `${name} invalid`, `It must be an integer between ${min} and ${max}. Received value: '${raw}'.`);
|
|
return;
|
|
}
|
|
|
|
addCheck(true, `${name} valid`, `${parsed}`);
|
|
}
|
|
|
|
function checkNodecgInstall() {
|
|
const indexPath = path.join(nodecgRootPath, "index.js");
|
|
const bootstrapPath = path.join(nodecgRootPath, "node_modules", "nodecg", "dist", "server", "bootstrap.js");
|
|
const manifestPath = path.join(nodecgRootPath, ".scoreko-runtime.json");
|
|
const bundleName = (process.env.NODECG_BUNDLE_NAME ?? "scoreko-dev").trim();
|
|
const bundlePath = path.join(nodecgRootPath, "bundles", bundleName);
|
|
|
|
addCheck(fs.existsSync(nodecgRootPath), "Packaged NodeCG runtime", nodecgRootPath);
|
|
addCheck(fs.existsSync(indexPath), "Runtime index.js", indexPath);
|
|
addCheck(fs.existsSync(bootstrapPath), "NodeCG bootstrap", bootstrapPath);
|
|
addCheck(fs.existsSync(manifestPath), "Runtime manifest", manifestPath);
|
|
addCheck(fs.existsSync(bundlePath), `Packaged bundle '${bundleName}'`, bundlePath);
|
|
|
|
try {
|
|
fs.accessSync(nodecgRootPath, fs.constants.R_OK | fs.constants.W_OK);
|
|
addCheck(true, "lib/nodecg permissions", "Read/write OK for local development");
|
|
} catch {
|
|
addCheck(false, "lib/nodecg permissions", "No read/write permissions in lib/nodecg");
|
|
}
|
|
}
|
|
|
|
function checkPortAvailability(port) {
|
|
return new Promise((resolve) => {
|
|
const server = net.createServer();
|
|
|
|
server.once("error", () => {
|
|
addCheck(false, `Port ${port}`, "It is in use. Free it or change NODECG_PORT.");
|
|
resolve();
|
|
});
|
|
|
|
server.listen(port, "127.0.0.1", () => {
|
|
server.close(() => {
|
|
addCheck(true, `Port ${port}`, "Available");
|
|
resolve();
|
|
});
|
|
});
|
|
});
|
|
}
|
|
|
|
async function main() {
|
|
const port = parsePort("NODECG_PORT", "9090");
|
|
parseIntInRange("ELECTRON_LOAD_DELAY_MS", 10000, 0, 600000);
|
|
parseIntInRange("NODECG_STARTUP_TIMEOUT_MS", 30000, 1000, 600000);
|
|
parseIntInRange("NODECG_KILL_TIMEOUT_MS", 2500, 0, 120000);
|
|
checkNodecgInstall();
|
|
|
|
if (port) {
|
|
await checkPortAvailability(port);
|
|
}
|
|
|
|
for (const check of checks) {
|
|
const icon = check.ok ? "OK" : "FAIL";
|
|
console.log(`${icon} ${check.title}: ${check.details}`);
|
|
}
|
|
|
|
const hasFailures = checks.some((check) => !check.ok);
|
|
if (hasFailures) {
|
|
process.exitCode = 1;
|
|
return;
|
|
}
|
|
|
|
console.log("\nDoctor finished: valid configuration.");
|
|
}
|
|
|
|
main();
|