Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions api/src/lib/mapSourcePaths.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { existsSync } from "fs";
import path from "path";

/**
* Resolves the on-disk mapas_source directory.
* OPENAO_MAPS_SOURCE overrides for tests / alternate checkouts.
*/
export function resolveMapsSourceDir(): string {
const override = process.env.OPENAO_MAPS_SOURCE?.trim();
if (override) {
return path.resolve(override);
}

const candidates = [
path.resolve(__dirname, ".."),
path.resolve(__dirname, "..", "..", "src"),
];

for (const candidate of candidates) {
if (existsSync(path.join(candidate, "mapas_source"))) {
return path.join(candidate, "mapas_source");
}
}

return path.join(candidates[0], "mapas_source");
}

export function mapDir(mapNum: number, mapsSourceDir = resolveMapsSourceDir()): string {
return path.join(mapsSourceDir, `mapa_${mapNum}`);
}
Loading