Gesamte Mono-Repo des Baukastens (alle apps/clients, examples/tests und packages)
dh_heyart
vor 7 Std. 7b1747b3214ec3de482f775cede2649c26e836a9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { readdir, readFile } from "node:fs/promises";
import { join } from "node:path";
import {
    CUSTOMER_NUMBER_PATTERN,
    type CustomerNumber,
    type FileInfo,
} from "@dh-software/baukasten-types";
 
/**
 * Lists the customer-number folders directly under `baseDir` (the baukasten
 * "configurations" directory). Folder names that are not pure customer numbers
 * (e.g. the "66666 (example customer nr)" template) are ignored.
 */
export async function listCustomerNumbers(baseDir: string): Promise<CustomerNumber[]> {
    const entries = await readdir(baseDir, { withFileTypes: true });
    return entries
        .filter((entry) => entry.isDirectory() && CUSTOMER_NUMBER_PATTERN.test(entry.name))
        .map((entry) => entry.name);
}
 
/** Reads and parses a single customer's fileinfo.json. */
export async function readFileInfo(
    baseDir: string,
    customerNumber: CustomerNumber,
): Promise<FileInfo> {
    const fileInfoPath = join(baseDir, customerNumber, "fileinfo.json");
    const raw = await readFile(fileInfoPath, "utf-8");
    return JSON.parse(raw) as FileInfo;
}