use super::{DetectResult, ProjectDef};
use std::path::Path;

use anyhow::Result;

pub const DEF: ProjectDef = ProjectDef {
    name: "vite",
    detect: detect,
    build_cmd: &["npm", "run", "build"],
    run_cmd: &["npx", "vite", "preview"],
};

fn detect(dir: &Path) -> Result<DetectResult> {
    let matched = dir.join("vite.config.js").exists()
        || dir.join("vite.config.ts").exists()
        || dir.join("vite.config.mjs").exists()
        || dir.join("vite.config.cjs").exists();

    if matched {
        Ok(DetectResult::matched()
            .with_alert("Generic Vite project detected. Configure a custom run command for production use."))
    } else {
        Ok(DetectResult::no_match())
    }
}
