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, GoConfig, JavaConfig, KotlinConfig, KotlinTarget, NodeConfig, PhpConfig,
37    PythonConfig, RConfig, RubyConfig, StubsConfig, SwiftConfig, WasmConfig, ZigConfig,
38};
39pub use legacy::{LegacyConfigError, LegacyKey, detect_legacy_keys};
40pub use new_config::{NewAlefConfig, ResolveError};
41pub use output::{
42    BuildCommandConfig, CleanConfig, ExcludeConfig, IncludeConfig, LintConfig, OutputConfig, OutputTemplate,
43    ReadmeConfig, ScaffoldCargo, ScaffoldCargoEnvValue, ScaffoldCargoTargets, ScaffoldConfig, SetupConfig, SyncConfig,
44    TestConfig, TextReplacement, UpdateConfig,
45};
46pub use publish::{PublishConfig, PublishLanguageConfig, VendorMode};
47pub use raw_crate::RawCrateConfig;
48pub use resolve_helpers::{detect_serde_available, resolve_output_dir};
49pub use resolved::ResolvedCrateConfig;
50pub use tools::{DEFAULT_RUST_DEV_TOOLS, LangContext, ToolsConfig, require_tool, require_tools};
51pub use trait_bridge::{BridgeBinding, TraitBridgeConfig};
52pub use workspace::WorkspaceConfig;
53
54/// A source crate group for multi-crate extraction.
55#[derive(Debug, Clone, Serialize, Deserialize)]
56pub struct SourceCrate {
57    /// Crate name (hyphens converted to underscores for rust_path).
58    pub name: String,
59    /// Source files belonging to this crate.
60    pub sources: Vec<std::path::PathBuf>,
61}
62
63fn default_true() -> bool {
64    true
65}
66
67/// Controls which generation passes alef runs.
68/// All flags default to `true`; set to `false` to skip a pass.
69/// Can be overridden per-language via `[generate_overrides.<lang>]`.
70#[derive(Debug, Clone, Serialize, Deserialize)]
71pub struct GenerateConfig {
72    /// Generate low-level struct wrappers, From impls, module init (default: true)
73    #[serde(default = "default_true")]
74    pub bindings: bool,
75    /// Generate error type hierarchies from thiserror enums (default: true)
76    #[serde(default = "default_true")]
77    pub errors: bool,
78    /// Generate config builder constructors from Default types (default: true)
79    #[serde(default = "default_true")]
80    pub configs: bool,
81    /// Generate async/sync function pairs with runtime management (default: true)
82    #[serde(default = "default_true")]
83    pub async_wrappers: bool,
84    /// Generate recursive type marshaling helpers (default: true)
85    #[serde(default = "default_true")]
86    pub type_conversions: bool,
87    /// Generate package manifests (pyproject.toml, package.json, etc.) (default: true)
88    #[serde(default = "default_true")]
89    pub package_metadata: bool,
90    /// Generate idiomatic public API wrappers (default: true)
91    #[serde(default = "default_true")]
92    pub public_api: bool,
93    /// Generate `From<BindingType> for CoreType` reverse conversions (default: true).
94    /// Set to false when the binding layer only returns core types and never accepts them.
95    #[serde(default = "default_true")]
96    pub reverse_conversions: bool,
97}
98
99impl Default for GenerateConfig {
100    fn default() -> Self {
101        Self {
102            bindings: true,
103            errors: true,
104            configs: true,
105            async_wrappers: true,
106            type_conversions: true,
107            package_metadata: true,
108            public_api: true,
109            reverse_conversions: true,
110        }
111    }
112}
113
114/// Post-generation formatting configuration.
115/// After code generation, alef can automatically run language-native formatters
116/// on the emitted package directories to ensure CI formatter checks pass.
117#[derive(Debug, Clone, Serialize, Deserialize)]
118pub struct FormatConfig {
119    /// Enable post-generation formatting (default: true).
120    /// Set to false to skip formatting for all languages, or use per-language
121    /// overrides in `[format.<lang>]` to disable specific formatters.
122    #[serde(default = "default_true")]
123    pub enabled: bool,
124    /// Optional custom command override. If set, this command is run instead
125    /// of the language's default formatter. Must be a shell command string
126    /// (e.g., "prettier --write .").
127    #[serde(default)]
128    pub command: Option<String>,
129}
130
131impl Default for FormatConfig {
132    fn default() -> Self {
133        Self {
134            enabled: true,
135            command: None,
136        }
137    }
138}