specta-elm 0.0.1

Yey! now your Rust types in Elm ;)
Documentation
mod error;
pub use error::{Error, ErrorTraceFrame};

mod module;
mod types;

mod elm;
pub use elm::Elm;
pub use elm::Project;

mod export;
pub use export::Exporter;
pub use export::IntoExporter as Output;
pub use export::SingleFileOutput as SingleFileExporter;
pub use export::TypesFileOutput as TypesFileExporter;

#[allow(dead_code)]
#[cfg(test)]
mod test {

    use std::process::Command;

    use crate::Elm;
    use crate::Project;
    use crate::SingleFileExporter;
    use crate::types;
    use fs_extra::dir;
    use fs_extra::dir::CopyOptions;
    use specta::Types;
    use tempfile::tempdir;

    #[test]
    fn elm_bin_check() {
        assert!(Command::new("elmo").arg("--versiono").status().is_err());
        assert!(Command::new("elm").arg("--version").status().is_ok());
    }

    #[test]
    fn elm_test_project_ready() {
        assert!(Project::try_from("test/elm-project").is_ok());
    }

    // fn do_stuff_in_tmp_project<'a, F>(stuff_to_do: &[F])
    // where
    //     F: Fn(&'a str) -> bool,
    // {
    //     let dir = tempdir().expect("what? failed to create tmpdir");
    //
    //     let opt = CopyOptions::default().overwrite(true);
    //     let copydir_res = dir::copy("test/elm-project", dir.path(), &opt);
    //     assert!(copydir_res.is_ok());
    //     copydir_res.unwrap();
    //
    //     let args = ("Maps", Types::default().register::<MapTrioska>(), "map = AMap");
    //
    //     let project_path = dir.path().to_path_buf().join("elm-project");
    // }

    #[test]
    fn compile_types_for_test_project() {
        let maybe_dir = tempdir();
        assert!(maybe_dir.is_ok());
        let dir = maybe_dir.unwrap();

        let opt = CopyOptions::default().overwrite(true);
        let copydir_res = dir::copy("test/elm-project", dir.path(), &opt);
        assert!(copydir_res.is_ok());
        copydir_res.unwrap();

        let project_path = dir.path().to_path_buf().join("elm-project");

        let types = Types::default().register::<types::map::test::MapTrioska>();
        let maybe_elm =
            Elm::init(types, &project_path.to_string_lossy()).export(SingleFileExporter("Map.elm"));
        assert!(maybe_elm.is_ok());

        maybe_elm.unwrap();
        //make src/Main.elm --output=dist/app.js --debug
        // cd here!
        dbg!(
            std::fs::read_dir(&project_path.join("src"))
                .unwrap()
                .map(|e| e.unwrap().file_name())
                .collect::<Vec<_>>()
        );
        let maybe_compiles = Command::new("elm")
            .current_dir(project_path)
            .arg("make")
            .arg("src/Main.elm")
            .arg("--output=success.js")
            .output();

        assert!(maybe_compiles.is_ok());
        let output = maybe_compiles.unwrap();
        dbg!("AAAH: {}", String::from_utf8_lossy(&output.stdout));

        assert!(output.status.success())

        // assert!(maybe_compiles.is_ok())
    }
}