| 1596 | } |
| 1597 | |
| 1598 | function loadLabMetadata(root: string) { |
| 1599 | const result = new Map<string, { description?: string }>(); |
| 1600 | const labsPath = path.join(root, "labs"); |
| 1601 | if (!existsSync(labsPath)) return result; |
| 1602 | |
| 1603 | for (const labId of readdirSync(labsPath)) { |
| 1604 | const metadataPath = path.join(labsPath, labId, "lab.toml"); |
| 1605 | if (!existsSync(metadataPath)) continue; |
| 1606 | |
| 1607 | const metadata = Bun.TOML.parse(readFileSync(metadataPath, "utf8")) as Record< |
| 1608 | string, |
| 1609 | unknown |
| 1610 | >; |
| 1611 | if ( |
| 1612 | metadata.description !== undefined && |
| 1613 | (typeof metadata.description !== "string" || metadata.description.length === 0) |
| 1614 | ) { |
| 1615 | throw new Error(`Invalid lab description in ${metadataPath}`); |
| 1616 | } |
| 1617 | |
| 1618 | result.set(labId, { description: metadata.description }); |
| 1619 | } |
| 1620 | |
| 1621 | return result; |
| 1622 | } |
| 1623 | |
| 1624 | function minDefined(values: Array<number | undefined>) { |
| 1625 | let result: number | undefined; |