Archived
f4abfe6fdc
Belated rename commit for foundation/el-ui — was missed in the workspace-wide crates→vessels pass earlier today. Same structural intent as the rename in the other repos: 'crates' is the Rust word, 'vessel' is El's, and the directory rename is the marker that this slot holds an El buildable unit even if its current contents are still Rust pending port. Plus the El ports themselves — manifest.el + src/main.el per sub- vessel (el-aop, el-auth, el-config, el-i18n, el-identity, el-layout, el-platform, el-publish, el-secrets, el-services, el-style, el-ui- compiler). The ui-compiler is a stub: elc only emits C right now; generating browser-target JS/Wasm is the biggest open language gap and gets its own project. Until then, el-ui-compiler emits a JS module that throws elc.backend_missing so callers fail loudly. Cross-repo path dependencies in Cargo.toml updated to vessels/.
115 lines
3.4 KiB
Rust
115 lines
3.4 KiB
Rust
/// Environment detection — which deployment context are we in?
|
|
|
|
/// The current deployment environment.
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
|
pub enum Environment {
|
|
/// Local developer machine. Verbose errors, hot reload, relaxed auth.
|
|
Development,
|
|
/// Pre-production environment. Production build, test data.
|
|
Staging,
|
|
/// Live production. Minimal logging, strict auth, performance mode.
|
|
Production,
|
|
}
|
|
|
|
impl Environment {
|
|
/// Detect from the `EL_ENV` environment variable (or `APP_ENV`, `RUST_ENV`).
|
|
///
|
|
/// Falls back to Development if unset or unrecognized.
|
|
pub fn current() -> Self {
|
|
let val = std::env::var("EL_ENV")
|
|
.or_else(|_| std::env::var("APP_ENV"))
|
|
.or_else(|_| std::env::var("RUST_ENV"))
|
|
.unwrap_or_default();
|
|
|
|
Self::from_str(&val)
|
|
}
|
|
|
|
/// Parse from a string.
|
|
pub fn from_str(s: &str) -> Self {
|
|
match s.to_lowercase().as_str() {
|
|
"production" | "prod" => Environment::Production,
|
|
"staging" | "stage" => Environment::Staging,
|
|
_ => Environment::Development,
|
|
}
|
|
}
|
|
|
|
/// The canonical name for this environment.
|
|
pub fn name(&self) -> &'static str {
|
|
match self {
|
|
Environment::Development => "development",
|
|
Environment::Staging => "staging",
|
|
Environment::Production => "production",
|
|
}
|
|
}
|
|
|
|
/// Whether this is a production environment.
|
|
pub fn is_production(&self) -> bool {
|
|
matches!(self, Environment::Production)
|
|
}
|
|
|
|
/// Whether this is a development environment.
|
|
pub fn is_development(&self) -> bool {
|
|
matches!(self, Environment::Development)
|
|
}
|
|
|
|
/// Whether debug features should be enabled.
|
|
pub fn debug_enabled(&self) -> bool {
|
|
!self.is_production()
|
|
}
|
|
}
|
|
|
|
impl std::fmt::Display for Environment {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
write!(f, "{}", self.name())
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn parse_production() {
|
|
assert_eq!(Environment::from_str("production"), Environment::Production);
|
|
assert_eq!(Environment::from_str("prod"), Environment::Production);
|
|
assert_eq!(Environment::from_str("PRODUCTION"), Environment::Production);
|
|
}
|
|
|
|
#[test]
|
|
fn parse_staging() {
|
|
assert_eq!(Environment::from_str("staging"), Environment::Staging);
|
|
assert_eq!(Environment::from_str("stage"), Environment::Staging);
|
|
}
|
|
|
|
#[test]
|
|
fn parse_development_fallback() {
|
|
assert_eq!(Environment::from_str("dev"), Environment::Development);
|
|
assert_eq!(Environment::from_str(""), Environment::Development);
|
|
assert_eq!(Environment::from_str("unknown"), Environment::Development);
|
|
}
|
|
|
|
#[test]
|
|
fn production_is_production() {
|
|
assert!(Environment::Production.is_production());
|
|
assert!(!Environment::Development.is_production());
|
|
}
|
|
|
|
#[test]
|
|
fn development_debug_enabled() {
|
|
assert!(Environment::Development.debug_enabled());
|
|
assert!(!Environment::Production.debug_enabled());
|
|
}
|
|
|
|
#[test]
|
|
fn environment_name() {
|
|
assert_eq!(Environment::Production.name(), "production");
|
|
assert_eq!(Environment::Staging.name(), "staging");
|
|
assert_eq!(Environment::Development.name(), "development");
|
|
}
|
|
|
|
#[test]
|
|
fn display() {
|
|
assert_eq!(format!("{}", Environment::Production), "production");
|
|
}
|
|
}
|