Skip to main content

alef_core/config/
mod.rs

1use serde::{Deserialize, Serialize};
2
3pub mod build_defaults;
4pub mod clean_defaults;
5pub mod derive;
6pub mod dto;
7pub mod e2e;
8pub mod extras;
9pub mod languages;
10pub mod legacy;
11pub mod lint_defaults;
12pub mod new_config;
13pub mod output;
14pub mod publish;
15pub mod raw_crate;
16pub mod resolve_helpers;
17pub mod resolved;
18pub mod setup_defaults;
19pub mod test_defaults;
20pub mod tools;
21pub mod trait_bridge;
22pub mod update_defaults;
23pub mod validation;
24pub mod workspace;
25
26// Re-exports for backward compatibility — all types were previously flat in config.rs.
27pub use derive::{derive_go_module_from_repo, derive_repo_org, derive_reverse_dns_package};
28pub use dto::{
29    CsharpDtoStyle, DtoConfig, ElixirDtoStyle, GoDtoStyle, JavaDtoStyle, NodeDtoStyle, PhpDtoStyle, PythonDtoStyle,
30    RDtoStyle, RubyDtoStyle,
31};
32pub use e2e::E2eConfig;
33pub use extras::{AdapterConfig, AdapterParam, AdapterPattern, Language};
34pub use languages::{
35    CSharpConfig, CustomModulesConfig, CustomRegistration, CustomRegistrationsConfig, DartConfig, DartStyle,
36    ElixirConfig, FfiConfig, GleamConfig, GleamElementConstructor, GleamElementField, GoConfig, JavaConfig,
37    KotlinConfig, KotlinTarget, NodeConfig, PhpConfig, PythonConfig, RConfig, RubyConfig, StubsConfig, SwiftConfig,
38    WasmConfig, ZigConfig,
39};
40pub use legacy::{LegacyConfigError, LegacyKey, detect_legacy_keys};
41pub use new_config::{NewAlefConfig, ResolveError};
42pub use output::{
43    BuildCommandConfig, CleanConfig, ExcludeConfig, IncludeConfig, LintConfig, OutputConfig, OutputTemplate,
44    ReadmeConfig, ScaffoldCargo, ScaffoldCargoEnvValue, ScaffoldCargoTargets, ScaffoldConfig, SetupConfig, SyncConfig,
45    TestConfig, TextReplacement, UpdateConfig,
46};
47pub use publish::{PublishConfig, PublishLanguageConfig, VendorMode};
48pub use raw_crate::RawCrateConfig;
49pub use resolve_helpers::{detect_serde_available, resolve_output_dir};
50pub use resolved::ResolvedCrateConfig;
51pub use tools::{DEFAULT_RUST_DEV_TOOLS, LangContext, ToolsConfig, require_tool, require_tools};
52pub use trait_bridge::{BridgeBinding, TraitBridgeConfig};
53pub use workspace::WorkspaceConfig;
54
55/// A source crate group for multi-crate extraction.
56#[derive(Debug, Clone, Serialize, Deserialize)]
57pub struct SourceCrate {
58    /// Crate name (hyphens converted to underscores for rust_path).
59    pub name: String,
60    /// Source files belonging to this crate.
61    pub sources: Vec<std::path::PathBuf>,
62}
63
64fn default_true() -> bool {
65    true
66}
67
68/// Controls which generation passes alef runs.
69/// All flags default to `true`; set to `false` to skip a pass.
70/// Can be overridden per-language via `[generate_overrides.<lang>]`.
71#[derive(Debug, Clone, Serialize, Deserialize)]
72pub struct GenerateConfig {
73    /// Generate low-level struct wrappers, From impls, module init (default: true)
74    #[serde(default = "default_true")]
75    pub bindings: bool,
76    /// Generate error type hierarchies from thiserror enums (default: true)
77    #[serde(default = "default_true")]
78    pub errors: bool,
79    /// Generate config builder constructors from Default types (default: true)
80    #[serde(default = "default_true")]
81    pub configs: bool,
82    /// Generate async/sync function pairs with runtime management (default: true)
83    #[serde(default = "default_true")]
84    pub async_wrappers: bool,
85    /// Generate recursive type marshaling helpers (default: true)
86    #[serde(default = "default_true")]
87    pub type_conversions: bool,
88    /// Generate package manifests (pyproject.toml, package.json, etc.) (default: true)
89    #[serde(default = "default_true")]
90    pub package_metadata: bool,
91    /// Generate idiomatic public API wrappers (default: true)
92    #[serde(default = "default_true")]
93    pub public_api: bool,
94    /// Generate `From<BindingType> for CoreType` reverse conversions (default: true).
95    /// Set to false when the binding layer only returns core types and never accepts them.
96    #[serde(default = "default_true")]
97    pub reverse_conversions: bool,
98}
99
100impl Default for GenerateConfig {
101    fn default() -> Self {
102        Self {
103            bindings: true,
104            errors: true,
105            configs: true,
106            async_wrappers: true,
107            type_conversions: true,
108            package_metadata: true,
109            public_api: true,
110            reverse_conversions: true,
111        }
112    }
113}
114
115/// Post-generation formatting configuration.
116/// After code generation, alef can automatically run language-native formatters
117/// on the emitted package directories to ensure CI formatter checks pass.
118#[derive(Debug, Clone, Serialize, Deserialize)]
119pub struct FormatConfig {
120    /// Enable post-generation formatting (default: true).
121    /// Set to false to skip formatting for all languages, or use per-language
122    /// overrides in `[format.<lang>]` to disable specific formatters.
123    #[serde(default = "default_true")]
124    pub enabled: bool,
125    /// Optional custom command override. If set, this command is run instead
126    /// of the language's default formatter. Must be a shell command string
127    /// (e.g., "prettier --write .").
128    #[serde(default)]
129    pub command: Option<String>,
130}
131
132impl Default for FormatConfig {
133    fn default() -> Self {
134        Self {
135            enabled: true,
136            command: None,
137        }
138    }
139}