feat: local-cpl-sim system

This commit is contained in:
ISA
2025-09-04 12:26:06 +02:00
parent 02a0ce5891
commit 0286670b81
6 changed files with 36 additions and 9 deletions

View File

@@ -137,14 +137,21 @@ function tryServeSpecialMocks(res, relPath) {
}
}
if (rp === "CPL/SERVICE/systemVoltTemp.js") {
const mockPath = path.join(
const base = path.join(
process.cwd(),
"mocks",
"device-cgi-simulator",
"SERVICE",
"systemVoltTempMockData.js"
"SERVICE"
);
if (exists(mockPath)) return streamRaw(res, mockPath);
const preferred = path.join(base, "systemVoltTemp.js");
if (exists(preferred)) return streamRaw(res, preferred);
const mockPath = path.join(base, "systemVoltTempMockData.js");
if (exists(mockPath)) {
// Transform variable name to expected win_systemVoltTemp when streaming
return streamTransform(res, mockPath, (txt) =>
txt.replace(/win_systemVoltTempMockData/g, "win_systemVoltTemp")
);
}
}
if (rp === "CPL/SERVICE/last20Messages.js") {
const mockPath = path.join(
@@ -238,6 +245,21 @@ function streamRaw(res, filePath) {
return true;
}
function streamTransform(res, filePath, transformFn) {
const ext = path.extname(filePath).toLowerCase();
const type = contentTypeByExt(ext);
const headers = { "Content-Type": type, "Cache-Control": "no-cache" };
res.writeHead(200, headers);
try {
const txt = fs.readFileSync(filePath, "utf8");
const out = transformFn(txt);
res.end(out);
} catch {
res.end();
}
return true;
}
function resolvePlaceholders(filePath, content) {
const rel = getRelFromRoot(filePath);
const serviceSystem =