/** * Code Generator — Orchestrates spec-to-code generation for all spec types. * * Inputs: * - AnySpec (ComponentSpec | PageSpec | DataVizSpec | DesignSpec | IASpec) * - CodegenContext: project context + design system tokens * - CodegenConfig: output directory, registry reference, optional event callback * * Outputs: * - CodegenResult: entryFile path, list of written files, original spec * * Key responsibilities: * 1. Hash-based cache invalidation — skip unchanged specs to avoid redundant writes * 2. Route to sub-generators (shadcn-mapper, dataviz-generator, page-generator) * 3. Write generated files to disk under atomic-design-correct output folders * 4. Check that referenced shadcn components are installed in components/ui/ * 5. Record generation state in the registry for status/watch commands * * All output uses shadcn/ui primitives + Tailwind utility classes. * No CSS modules, styled-components, or inline style objects are emitted. */ import type { MemoireEvent } from "../engine/core.js"; import type { Registry, DesignSystem } from "../engine/registry.js"; import type { AnySpec } from "../specs/types.js"; import type { ProjectContext } from "../engine/project-context.js"; export interface CodegenConfig { outputDir: string; registry: Registry; onEvent?: (event: MemoireEvent) => void; /** Skip .stories.tsx generation — useful for projects not using Storybook */ noStories?: boolean; /** Output framework: react (default), vue, svelte */ framework?: "react" | "vue" | "svelte"; } export interface CodegenResult { entryFile: string; files: { path: string; content: string; }[]; spec: AnySpec; } export interface CodegenContext { project: ProjectContext; designSystem: DesignSystem; } export declare class CodeGenerator { private log; private config; constructor(config: CodegenConfig); /** Override generation options at runtime (e.g. --no-stories, --framework from CLI). */ setOptions(opts: Partial>): void; /** * Generate code from a spec and write all output files to disk. * * Skips generation when spec + design system hash matches a previous run. * Returns a CodegenResult describing the written files. * * @param spec - Any Mémoire spec (component, page, dataviz, design, ia). * @param ctx - Codegen context with project and design system data. */ generate(spec: AnySpec, ctx: CodegenContext): Promise; /** * Preview mode — generates code in memory without writing files to disk. * Returns the same CodegenResult so callers can inspect file paths and contents. */ preview(spec: AnySpec, ctx: CodegenContext): Promise; /** * Maps atomic level to output folder following Atomic Design methodology. * Delegates to the shared atomicLevelToFolder() utility. */ private getAtomicDir; /** * Check that each shadcnBase component exists in the project's components/ui/. * Emits a warn event for any that are missing so the user can install them. */ private checkShadcnInstalled; private generateComponentFiles; /** * Variation-aware component generation. When `spec.variantAxes` is declared, * expand the cartesian product and emit one file per variant under * `/variants/{id}.tsx`, a shared barrel, a Storybook story with one * export per variant, and a `variants/manifest.json` for the preview gallery. * * `priorVariants` context is threaded through per-variant generation so any * future AI-augmented codegen path can diversify against already-generated * siblings. Today the template generator ignores the context but the hook * is in place. */ private generateVariantFiles; private generatePageFiles; private generateDataVizFiles; private emitEvent; }