from __future__ import annotations

from pathlib import Path

from fastgws.helpers import project_root

from .emit_docs import emit_docs
from .emit_meta import emit_generated
from .emit_pyi import emit_pyi
from .manifest import fixture_path, load_manifest
from .normalize import load_fixture_doc, normalize_service


def build_all(root: str | Path | None = None):
    root = project_root(root)
    services = [normalize_service(entry, load_fixture_doc(fixture_path(entry, root))) for entry in load_manifest(root)]
    emit_generated(services, root)
    emit_docs(services, root)
    emit_pyi(services, root)
    return services
