/** * 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"; import { type LayoutCritique } from "./layout-critic.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"; /** * When true, skill-compliance findings (atomic composition, motion tokens) * are promoted to critical severity and can block a write. Off by default — * those findings stay advisory (warning) so the gate only ever blocks on * the two hex/color checks and the token-pair contrast check. */ strictSkillCompliance?: boolean; } export interface Finding { severity: "critical" | "warning"; rule: string; file: string; message: string; fix?: string; docRef?: string; } export interface CodegenResult { entryFile: string; files: { path: string; content: string; }[]; spec: AnySpec; /** Severity-classified quality-gate findings. Always present. */ findings: Finding[]; /** True when a critical finding prevented this generation from writing files. */ blocked: boolean; /** AI layout critique (page specs only, when an API key is configured). Advisory — never blocks. */ critique?: LayoutCritique; } 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, --strict-skill-compliance 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. * A critical quality-gate finding (raw hex/color when tokens exist, a * token-pair contrast failure, or — in strict mode — a skill-compliance * violation) blocks the write: no files are written and no generation is * recorded. Pass opts.force to write anyway. * * @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, opts?: { force?: boolean; }): Promise; /** * Preview mode — generates code in memory without writing files to disk. * Returns the same CodegenResult so callers can inspect file paths and * contents. Quality-gate findings ARE computed here (so --preview isn't * blind to what would block a real generate), but the AI critique is not * run in preview, to avoid burning an AI call on every dry-run iteration. */ 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; }