| 437 | } |
| 438 | |
| 439 | async function validateSounds(): Promise<void> { |
| 440 | const problems = new Problems<string, "_additional">("Sounds", { |
| 441 | _additional: |
| 442 | "Sound files present but missing in frontend/src/ts/constants/sounds", |
| 443 | }); |
| 444 | |
| 445 | const soundFiles = new Set( |
| 446 | fs |
| 447 | .readdirSync("./static/sounds") |
| 448 | .filter((it) => it.startsWith("click")) |
| 449 | .flatMap((folder) => |
| 450 | fs |
| 451 | .readdirSync(`./static/sounds/${folder}`) |
| 452 | .map((it) => `${folder}/${it}`), |
| 453 | ), |
| 454 | ); |
| 455 | |
| 456 | //missing sound files |
| 457 | |
| 458 | Object.entries(clickSoundConfig).forEach(([key, value]) => { |
| 459 | value |
| 460 | .map((file) => file.substring("../sounds/".length)) |
| 461 | .filter((it) => !soundFiles.has(it)) |
| 462 | .forEach((file) => |
| 463 | problems.add( |
| 464 | `click${key}`, |
| 465 | `missing file frontend/static/sounds/${file}`, |
| 466 | ), |
| 467 | ); |
| 468 | }); |
| 469 | |
| 470 | //additional files |
| 471 | const expectedSoundFiles = new Set( |
| 472 | Object.values(clickSoundConfig).flatMap((it) => |
| 473 | it.map((file) => file.substring("../sounds/".length)), |
| 474 | ), |
| 475 | ); |
| 476 | [...soundFiles] |
| 477 | .filter((name) => !expectedSoundFiles.has(name)) |
| 478 | .forEach((file) => problems.add("_additional", file)); |
| 479 | |
| 480 | console.log(problems.toString()); |
| 481 | |
| 482 | if (problems.hasError()) { |
| 483 | throw new Error("sounds with errors"); |
| 484 | } |
| 485 | } |
| 486 | |
| 487 | type Validator = () => Promise<void>; |
| 488 | |