25 lines
648 B
TypeScript
25 lines
648 B
TypeScript
|
|
import type { SandboxDefinition } from "./types"
|
||
|
|
|
||
|
|
type SandboxManifestModule = {
|
||
|
|
default: SandboxDefinition
|
||
|
|
}
|
||
|
|
|
||
|
|
const manifestModules = import.meta.glob<SandboxManifestModule>(
|
||
|
|
"../../sandboxes/*/*/sandbox.ts",
|
||
|
|
{ eager: true }
|
||
|
|
)
|
||
|
|
|
||
|
|
const sandboxDefinitions = new Map<string, SandboxDefinition>()
|
||
|
|
|
||
|
|
for (const module of Object.values(manifestModules)) {
|
||
|
|
const definition = module.default
|
||
|
|
if (sandboxDefinitions.has(definition.id)) {
|
||
|
|
throw new Error(`Duplicate sandbox id: ${definition.id}`)
|
||
|
|
}
|
||
|
|
sandboxDefinitions.set(definition.id, definition)
|
||
|
|
}
|
||
|
|
|
||
|
|
export function getSandboxDefinition(id: string) {
|
||
|
|
return sandboxDefinitions.get(id)
|
||
|
|
}
|