Skip to content

Commit 1a0cfbf

Browse files
committed
Refactor file handling and update file names
1 parent a6d6c82 commit 1a0cfbf

25 files changed

Lines changed: 257 additions & 192 deletions

.gitignore

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,21 @@ __pycache__
2525

2626
# @ak/web-app
2727
/apps/web-app/VERSION
28-
/apps/web-app/cypress/io-empty/LUA/ce/databridge/exchange/ak*
28+
/apps/web-app/cypress/io-empty/LUA/ce/databridge/exchange/ce-*
29+
/apps/web-app/cypress/io-empty/LUA/ce/databridge/exchange/events-from-ce
30+
/apps/web-app/cypress/io-empty/LUA/ce/databridge/exchange/events-from-ce.pending
31+
/apps/web-app/cypress/io-empty/LUA/ce/databridge/exchange/log-from-ce
32+
/apps/web-app/cypress/io-empty/LUA/ce/databridge/exchange/commands-to-ce
33+
/apps/web-app/cypress/io-empty/LUA/ce/databridge/exchange/server-is-running
34+
/apps/web-app/cypress/io-empty/LUA/ce/databridge/exchange/server-state.*
2935
/apps/web-app/cypress/io/LUA/ce/databridge/exchange/ak*
36+
/apps/web-app/cypress/io/LUA/ce/databridge/exchange/ce-*
37+
/apps/web-app/cypress/io/LUA/ce/databridge/exchange/events-from-ce
38+
/apps/web-app/cypress/io/LUA/ce/databridge/exchange/events-from-ce.pending
39+
/apps/web-app/cypress/io/LUA/ce/databridge/exchange/log-from-ce
40+
/apps/web-app/cypress/io/LUA/ce/databridge/exchange/commands-to-ce
41+
/apps/web-app/cypress/io/LUA/ce/databridge/exchange/server-is-running
42+
/apps/web-app/cypress/io/LUA/ce/databridge/exchange/server-state.*
3043
/apps/web-app/cypress/io/ak*
3144
/apps/web-app/cypress/screenshots
3245
/apps/web-app/cypress/videos
@@ -39,9 +52,21 @@ __pycache__
3952
/apps/web-shared/resources/public
4053

4154
# compiled output
42-
/web-app/cypress/io/ak*
43-
/web-app/cypress/io/LUA/ce/databridge/exchange/ak*
55+
/web-app/cypress/io/LUA/ce/databridge/exchange/ce-*
56+
/web-app/cypress/io/LUA/ce/databridge/exchange/events-from-ce
57+
/web-app/cypress/io/LUA/ce/databridge/exchange/events-from-ce.pending
58+
/web-app/cypress/io/LUA/ce/databridge/exchange/log-from-ce
59+
/web-app/cypress/io/LUA/ce/databridge/exchange/commands-to-ce
60+
/web-app/cypress/io/LUA/ce/databridge/exchange/server-is-running
61+
/web-app/cypress/io/LUA/ce/databridge/exchange/server-state.*
4462
/web-app/cypress/io-empty/LUA/ce/databridge/exchange/ak*
63+
/web-app/cypress/io-empty/LUA/ce/databridge/exchange/ce-*
64+
/web-app/cypress/io-empty/LUA/ce/databridge/exchange/events-from-ce
65+
/web-app/cypress/io-empty/LUA/ce/databridge/exchange/events-from-ce.pending
66+
/web-app/cypress/io-empty/LUA/ce/databridge/exchange/log-from-ce
67+
/web-app/cypress/io-empty/LUA/ce/databridge/exchange/commands-to-ce
68+
/web-app/cypress/io-empty/LUA/ce/databridge/exchange/server-is-running
69+
/web-app/cypress/io-empty/LUA/ce/databridge/exchange/server-state.*
4570
/web-app/cypress/videos
4671
/web-app/cypress/screenshots
4772
/web-app/dist
@@ -76,7 +101,14 @@ __pycache__
76101
/lua/LUA/StorageUtilityValues.txt
77102
/lua/LUA/ce/anlagen
78103
/lua/LUA/ce/VERSION
79-
/lua/LUA/ce/databridge/exchange/ak*
104+
/lua/LUA/ce/databridge/exchange/ce-*
105+
/lua/LUA/ce/databridge/exchange/events-from-ce
106+
/lua/LUA/ce/databridge/exchange/events-from-ce.pending
107+
/lua/LUA/ce/databridge/exchange/log-from-ce
108+
/lua/LUA/ce/databridge/exchange/commands-to-ce
109+
/lua/LUA/ce/databridge/exchange/ce-version.txt
110+
/lua/LUA/ce/databridge/exchange/server-is-running
111+
/lua/LUA/ce/databridge/exchange/server-state.*
80112
/lua/LUA/comm_*
81113
/lua/modell-pakete
82114

apps/web-app/cypress.config.mjs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
import { defineConfig } from 'cypress';
22
import { rm } from 'node:fs';
3+
import { access } from 'node:fs/promises';
4+
5+
async function waitForFileMissing(fileName, timeoutMs = 5000) {
6+
const start = Date.now();
7+
8+
while (Date.now() - start < timeoutMs) {
9+
try {
10+
await access(fileName);
11+
} catch (error) {
12+
if (error && typeof error === 'object' && 'code' in error && error.code === 'ENOENT') {
13+
return true;
14+
}
15+
}
16+
17+
await new Promise((resolve) => setTimeout(resolve, 50));
18+
}
19+
20+
throw new Error(`Timed out waiting for file to disappear: ${fileName}`);
21+
}
322

423
export default defineConfig({
524
projectId: 'g5rj4e',
@@ -12,6 +31,9 @@ export default defineConfig({
1231
rm(fileName, () => {});
1332
return null;
1433
},
34+
waitForFileMissing(fileName) {
35+
return waitForFileMissing(fileName);
36+
},
1537
});
1638
},
1739
},

apps/web-app/cypress/e2e/modules/log/log_spec.cy.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe('Logger', () => {
2828
it('has no initial log', () => {
2929
cy.visit('/');
3030
cy.wait(500).then(() => {
31-
cy.readFile(simulator.fileNames.eepOutLog).then((a) => cy.log(a));
31+
cy.readFile(simulator.fileNames.logFromCe).then((a) => cy.log(a));
3232
getLogList().children().should('have.length', 0);
3333
});
3434
});
@@ -38,7 +38,7 @@ describe('Logger', () => {
3838
simulator.writeLogLine('Let us test something');
3939
cy.visit('/');
4040
cy.wait(500).then(() => {
41-
cy.readFile(simulator.fileNames.eepOutLog).then((a) => cy.log(a));
41+
cy.readFile(simulator.fileNames.logFromCe).then((a) => cy.log(a));
4242
getLogList().children().should('have.length', 1).first().contains('Let us test something');
4343
});
4444
});
@@ -47,7 +47,7 @@ describe('Logger', () => {
4747
simulator.writeLogLine('Äpfel, Überschuss, ÖPNV');
4848
cy.visit('/');
4949
cy.wait(500).then(() => {
50-
cy.readFile(simulator.fileNames.eepOutLog).then((a) => cy.log(a));
50+
cy.readFile(simulator.fileNames.logFromCe).then((a) => cy.log(a));
5151
getLogList().children().should('have.length', 1).first().contains('Äpfel, Überschuss, ÖPNV');
5252
});
5353
});
@@ -56,7 +56,7 @@ describe('Logger', () => {
5656
simulator.writeLogLine('Line 1\nLine 2\nLine 3');
5757
cy.visit('/');
5858
cy.wait(500).then(() => {
59-
cy.readFile(simulator.fileNames.eepOutLog).then((a) => cy.log(a));
59+
cy.readFile(simulator.fileNames.logFromCe).then((a) => cy.log(a));
6060
getLogList()
6161
.children()
6262
.should('have.length', 3)
@@ -73,7 +73,7 @@ describe('Logger', () => {
7373
simulator.writeLogLine('Line 1\nLine 2\nLine 3\nLine 4');
7474
cy.visit('/');
7575
cy.wait(500).then(() => {
76-
cy.readFile(simulator.fileNames.eepOutLog).then((a) => cy.log(a));
76+
cy.readFile(simulator.fileNames.logFromCe).then((a) => cy.log(a));
7777
getLogList()
7878
.children()
7979
.should('have.length', 4)
@@ -90,13 +90,13 @@ describe('Logger', () => {
9090
});
9191
describe('action', () => {
9292
it('"Reset Button" sends "clearlog" command to EEP', () => {
93-
cy.writeFile(simulator.fileNames.serverOutCommands, '');
93+
cy.writeFile(simulator.fileNames.commandsToCe, '');
9494
cy.visit('/');
9595
cy.wait(500).then(() => {
9696
cy.get('#open-log').click();
9797
cy.get('#delete-log').click();
9898
});
99-
cy.readFile(simulator.fileNames.serverOutCommands, 'latin1').should('eq', 'clearlog\n');
99+
cy.readFile(simulator.fileNames.commandsToCe, 'latin1').should('eq', 'clearlog\n');
100100
});
101101
});
102102

apps/web-app/cypress/fixtures/map-01-events/README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ Created with:
99

1010
1. **Close EEP-Web-Server** if running
1111

12-
2. **Create watching file** in the game folder of EEP to simulate the server
13-
`lua\ak\io\exchange\ak-server.iswatching`
12+
2. **Create server indicator file** in the game folder of EEP to simulate the server
13+
`lua\ce\databridge\exchange\server-is-running`
1414

1515
3. **Start EEP or reload the Lua Script**
1616
so EEP can write the event file
@@ -19,13 +19,12 @@ Created with:
1919
`cd web-server`
2020
`npm run persist-eep-state`
2121

22-
This will read the file `ak-eep-out.json` and write the output to the folder
22+
This will read the file `events-from-ce` and write the output to the folder
2323
`../web-app/cypress/fixtures/from-eep`
2424

2525
5. **Follow-up events can be parsed** with the following chain:
26-
2726
1. Let EEP run until the desired state is reached
28-
2. Remove the file `ak-eep-out-json.ready` in `lua\ak\io\exchange\`
27+
2. Remove the file `events-from-ce.pending` in `lua\ce\databridge\exchange\`
2928
(This will tell EEP to write events in the next cycle.)
3029
3. Let EEP run - so it can write the eventlog.
3130
4. Run `npm run persist-eep-state` in the `web-server` directory.

apps/web-app/cypress/test-helpers/eep-simulator.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { version } from '../../package.json';
22

33
export enum FileNames {
4-
eepOutJsonOut = 'cypress/io/LUA/ce/databridge/exchange/ak-eep-out.json',
5-
eepOutJsonOutFinished = 'cypress/io/LUA/ce/databridge/exchange/ak-eep-out-json.isfinished',
6-
eepOutLog = 'cypress/io/LUA/ce/databridge/exchange/ak-eep-out.log',
7-
serverOutCommands = 'cypress/io/LUA/ce/databridge/exchange/ak-eep-in.commands',
8-
serverWatching = 'cypress/io/LUA/ce/databridge/exchange/ak-server.iswatching',
4+
eventsFromCe = 'cypress/io/LUA/ce/databridge/exchange/events-from-ce',
5+
eventsFromCePending = 'cypress/io/LUA/ce/databridge/exchange/events-from-ce.pending',
6+
logFromCe = 'cypress/io/LUA/ce/databridge/exchange/log-from-ce',
7+
commandsToCe = 'cypress/io/LUA/ce/databridge/exchange/commands-to-ce',
8+
serverIsRunning = 'cypress/io/LUA/ce/databridge/exchange/server-is-running',
99
}
1010

1111
const resetMarker = '@@CE_LOG_RESET@@';
@@ -18,19 +18,19 @@ export default class EepSimulator {
1818

1919
reset = () => {
2020
this.eventCounter = 0;
21-
cy.task('deleteEepLogFile', FileNames.eepOutLog);
22-
cy.readFile(FileNames.eepOutLog).should('not.exist');
23-
cy.readFile(FileNames.serverWatching).should('exist');
24-
cy.writeFile(FileNames.eepOutLog, '', 'latin1');
25-
cy.writeFile(FileNames.serverOutCommands, '');
21+
cy.task('deleteEepLogFile', FileNames.logFromCe);
22+
cy.readFile(FileNames.logFromCe).should('not.exist');
23+
cy.readFile(FileNames.serverIsRunning).should('exist');
24+
cy.writeFile(FileNames.logFromCe, '', 'latin1');
25+
cy.writeFile(FileNames.commandsToCe, '');
2626
this.eepEvent('reset.json');
2727
};
2828

29-
loadFixtures = (fixtures: string[]) => {
30-
const res = <any>[];
29+
loadFixtures = (fixtures: string[]): Cypress.Chainable<any[]> => {
30+
const res: any[] = [];
3131
// could also use `res.push(f)` they should be equivalent
3232
fixtures.map((name, i) => cy.fixture(name).then((f) => (res[i] = f)));
33-
return cy.wrap(res);
33+
return cy.wrap<any[]>(res);
3434
};
3535

3636
simulateMap(mapName: string, startEvent: number, endEvent: number) {
@@ -41,7 +41,7 @@ export default class EepSimulator {
4141
}
4242
const eventJsons = this.loadFixtures(eventFileNames).then((jsons) => {
4343
cy.log(jsons.length.toLocaleString());
44-
cy.writeFile(FileNames.serverOutCommands, '');
44+
cy.writeFile(FileNames.commandsToCe, '');
4545
this.writeNewEepEventFile(jsons.map((x) => JSON.stringify(x)).join('\n'));
4646
});
4747
}
@@ -61,10 +61,10 @@ export default class EepSimulator {
6161

6262
// Append complete log lines like LogOutputFileWriter does.
6363
writeLogLine(line: string) {
64-
cy.readFile(FileNames.eepOutLog, 'latin1').then((oldLines) => {
64+
cy.readFile(FileNames.logFromCe, 'latin1').then((oldLines) => {
6565
cy.log(oldLines);
6666
const prefix = oldLines.length > 0 && !oldLines.endsWith('\n') ? oldLines + '\n' : oldLines;
67-
cy.writeFile(FileNames.eepOutLog, prefix + line + '\n', 'latin1');
67+
cy.writeFile(FileNames.logFromCe, prefix + line + '\n', 'latin1');
6868
cy.wait(100); // Give the web server some time to read new log lines
6969
});
7070
}
@@ -74,8 +74,8 @@ export default class EepSimulator {
7474
}
7575

7676
private writeNewEepEventFile(eventLines: string) {
77-
cy.writeFile(FileNames.eepOutJsonOut, eventLines, 'latin1');
78-
cy.writeFile(FileNames.eepOutJsonOutFinished, '');
79-
cy.readFile(FileNames.eepOutJsonOutFinished).should('not.exist');
77+
cy.writeFile(FileNames.eventsFromCe, eventLines, 'latin1');
78+
cy.writeFile(FileNames.eventsFromCePending, '');
79+
cy.task('waitForFileMissing', FileNames.eventsFromCePending);
8080
}
8181
}

apps/web-server/src/server/eep/helpers/EepStateReader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fs from 'fs';
22
import path from 'path';
33

44
const persistState = () => {
5-
const jsonFile = path.resolve('../lua/LUA/ce/databridge/exchange/ak-eep-out.json');
5+
const jsonFile = path.resolve('../lua/LUA/ce/databridge/exchange/events-from-ce');
66
const data: string = fs.readFileSync(jsonFile, { encoding: 'latin1' });
77
const eventLines: string[] = data.split('\n');
88
for (const line of eventLines) {

apps/web-server/src/server/eep/service/EepService.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ export default class EepService implements CacheService {
4949
}
5050

5151
private connectToFiles(): void {
52-
this.attachAkEepOutJsonFile();
53-
this.attachAkEepOutLogFile();
54-
this.createAkServerFile();
52+
this.attachEventsFromCeFile();
53+
this.attachLogFromCeFile();
54+
this.createServerIsRunningFile();
5555
this.deleteFileOnExit(FileNames.serverEventCounter);
5656
}
5757

5858
private disconnectFromFiles(): void {
5959
if (this.dir) {
60-
this.deleteFileIfExists(path.resolve(this.dir, FileNames.serverWatching));
60+
this.deleteFileIfExists(path.resolve(this.dir, FileNames.serverIsRunning));
6161
}
6262

6363
this.logFileMonitor.detach();
@@ -125,9 +125,9 @@ export default class EepService implements CacheService {
125125
}
126126
}
127127

128-
private attachAkEepOutJsonFile(): void {
129-
const jsonFile = path.resolve(this.dir, FileNames.eepOutJsonOut);
130-
const jsonReadyFile = path.resolve(this.dir, FileNames.eepOutJsonOutFinished);
128+
private attachEventsFromCeFile(): void {
129+
const jsonFile = path.resolve(this.dir, FileNames.eventsFromCe);
130+
const jsonReadyFile = path.resolve(this.dir, FileNames.eventsFromCePending);
131131

132132
// First start: Read the JSON file - ignore if EEP is ready
133133
if (!this.jsonFileWatcher) {
@@ -141,7 +141,7 @@ export default class EepService implements CacheService {
141141
// Watch in the directory, if the file is recreated
142142
this.jsonFileWatcher = fs.watch(this.dir, {}, (eventType: string, filename: string) => {
143143
// If the jsonReadyFile exists: Read the data and remove the file
144-
if (filename === FileNames.eepOutJsonOutFinished && fs.existsSync(jsonReadyFile)) {
144+
if (filename === FileNames.eventsFromCePending && fs.existsSync(jsonReadyFile)) {
145145
// console.log('Reading: ', jsonFile);
146146
this.readJsonFile(jsonFile, jsonReadyFile);
147147
}
@@ -174,19 +174,19 @@ export default class EepService implements CacheService {
174174
}
175175
}
176176

177-
private attachAkEepOutLogFile(): void {
178-
this.logFileMonitor.attach(path.resolve(this.dir, FileNames.eepOutLog));
177+
private attachLogFromCeFile(): void {
178+
this.logFileMonitor.attach(path.resolve(this.dir, FileNames.logFromCe));
179179
}
180180

181181
getCurrentLogLines = (): string => {
182182
return this.logFileMonitor.readCurrentLogLines();
183183
}
184184

185-
public createAkServerFile() {
186-
const watchFile = path.resolve(this.dir, FileNames.serverWatching);
187-
// Create the serverWatchingFile
185+
public createServerIsRunningFile() {
186+
const watchFile = path.resolve(this.dir, FileNames.serverIsRunning);
187+
// Create the server-is-running marker file
188188
fs.closeSync(fs.openSync(watchFile, 'w'));
189-
this.deleteFileOnExit(FileNames.serverWatching);
189+
this.deleteFileOnExit(FileNames.serverIsRunning);
190190
}
191191

192192
private deleteFileOnExit(fileName: string) {
@@ -219,7 +219,7 @@ export default class EepService implements CacheService {
219219
}
220220

221221
queueCommand = (command: string) => {
222-
const file = path.resolve(this.dir, FileNames.serverOutCommands);
222+
const file = path.resolve(this.dir, FileNames.commandsToCe);
223223
try {
224224
if (this.debug) console.log('Queuing: ' + command);
225225
fs.appendFileSync(file, command + '\n', { encoding: 'latin1' });
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
export enum FileNames {
2-
// TODO: rename all of these files to remove the ak- prefix and may be find a good pattern for the direction (from-ce, to-ce)
3-
eepOutJsonOut = 'ak-eep-out.json',
4-
eepOutJsonOutFinished = 'ak-eep-out-json.isfinished',
5-
eepOutLog = 'ak-eep-out.log',
6-
serverOutCommands = 'ak-eep-in.commands',
7-
serverWatching = 'ak-server.iswatching',
8-
serverCache = 'ak-eep-web-server-state.json',
9-
serverEventCounter = 'ak-eep-web-server-state.counter',
2+
eventsFromCe = 'events-from-ce',
3+
eventsFromCePending = 'events-from-ce.pending',
4+
logFromCe = 'log-from-ce',
5+
commandsToCe = 'commands-to-ce',
6+
serverIsRunning = 'server-is-running',
7+
serverCache = 'server-state.json',
8+
serverEventCounter = 'server-state.counter',
109
}

apps/web-server/src/server/eep/service/LogFileMonitor.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as path from 'node:path';
55
import { setTimeout as delay } from 'node:timers/promises';
66
import { LogFileMonitor } from './LogFileMonitor';
77

8-
const logFileName = 'ak-eep-out.log';
8+
const logFileName = 'log-from-ce';
99
const resetMarker = '@@CE_LOG_RESET@@';
1010

1111
async function waitFor(check: () => void, timeoutMs = 2000): Promise<void> {

docs/_anleitungen-installation/installation2-einrichten-von-eep-web.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ date: 2017-09-08
4040

4141
3. **Einrichtung in Lua prüfen**
4242

43-
Prüfe in der EEP-Installation, ob die Datei `LUA\ce\databridge\exchange\ak-eep-out.json` geschrieben wird.
43+
Prüfe in der EEP-Installation, ob die Datei `LUA\ce\databridge\exchange\events-from-ce` geschrieben wird.
4444

4545
_Hinweis_: Diese Datei wird angelegt wenn die Anlage im 3D-Modus läuft.
4646

0 commit comments

Comments
 (0)