47 lines
1.2 KiB
TypeScript
47 lines
1.2 KiB
TypeScript
import type { Exercise, Stage, TopicCurriculum } from "./types"
|
|
|
|
const lecturaModules: Record<string, Stage> = {}
|
|
const numerosModules: Record<string, Stage> = {}
|
|
|
|
async function loadStages(
|
|
topic: string,
|
|
modules: Record<string, Stage>,
|
|
stageFiles: number[],
|
|
) {
|
|
for (const s of stageFiles) {
|
|
try {
|
|
const mod = await import(`./${topic}/etapa-${s}`)
|
|
modules[s] = mod.default
|
|
} catch {
|
|
// stage not yet implemented
|
|
}
|
|
}
|
|
}
|
|
|
|
let lecturaLoaded = false
|
|
let numerosLoaded = false
|
|
|
|
export function getAllLecturaExercises(): Exercise[] {
|
|
const stages = Object.values(getLecturaStages())
|
|
return stages.flatMap((s) => s.exercises || [])
|
|
}
|
|
|
|
export function getLecturaStages(): Record<string, Stage> {
|
|
return lecturaModules as Record<string, Stage>
|
|
}
|
|
|
|
export function getNumerosStages(): Record<string, Stage> {
|
|
return numerosModules as Record<string, Stage>
|
|
}
|
|
|
|
export async function initCurriculum() {
|
|
if (!lecturaLoaded) {
|
|
await loadStages("lectura", lecturaModules, [1, 2, 3, 4, 5, 6, 7, 8, 9])
|
|
lecturaLoaded = true
|
|
}
|
|
if (!numerosLoaded) {
|
|
await loadStages("numeros", numerosModules, [1, 2, 3, 4, 5, 6, 7, 8])
|
|
numerosLoaded = true
|
|
}
|
|
}
|