cuenv_cubes/
lib.rs

1//! # cuenv-cubes
2//!
3//! CUE Cubes - code generation and project scaffolding from CUE templates.
4//!
5//! This crate provides a code generation system based on CUE Cubes that:
6//! - Uses schema-wrapped code blocks (e.g., `schema.#TypeScript`, `schema.#JSON`)
7//! - Supports managed (always regenerated) and scaffold (generate once) file modes
8//! - Integrates with `cuenv sync cubes` command
9//!
10//! ## What is a CUE Cube?
11//!
12//! A Cube is a CUE-based template that generates multiple project files.
13//! Define your files in CUE with type-safe schemas, then sync them with
14//! `cuenv sync cubes`.
15//!
16//! ## Example
17//!
18//! ```cue
19//! schema.#Project & {
20//!     name: "my-service"
21//!     cube: {
22//!         files: {
23//!             "package.json": schema.#JSON & {
24//!                 mode: "managed"
25//!                 content: """{"name": "my-service"}"""
26//!             }
27//!         }
28//!     }
29//! }
30//! ```
31
32#![warn(missing_docs)]
33#![warn(clippy::all)]
34#![warn(clippy::pedantic)]
35
36pub mod config;
37pub mod cube;
38pub mod formatter;
39pub mod generator;
40
41pub use cube::Cube;
42pub use generator::{GenerateOptions, Generator};
43
44use thiserror::Error;
45
46/// Errors that can occur during code generation
47#[derive(Error, Debug)]
48pub enum CodegenError {
49    /// Error loading or evaluating CUE Cube
50    #[error("Cube error: {0}")]
51    Cube(String),
52
53    /// Error during file generation
54    #[error("Generation error: {0}")]
55    Generation(String),
56
57    /// Error during formatting
58    #[error("Formatting error: {0}")]
59    Formatting(String),
60
61    /// IO error
62    #[error("IO error: {0}")]
63    Io(#[from] std::io::Error),
64
65    /// JSON error
66    #[error("JSON error: {0}")]
67    Json(#[from] serde_json::Error),
68}
69
70/// Result type for codegen operations
71pub type Result<T> = std::result::Result<T, CodegenError>;