nativeview-codegen 0.1.0-rc.1

Multi-language ABI, policy, flat-op codec, and hybrid Direct-FFI code generator for Native View Engine.
Documentation
//! The template file set, shared by `build.rs` (which embeds it into the crate) and
//! [`super::verify_embedded_templates`] (which compares it to the checkout on disk).

use std::path::Path;

/// Every file under `dir`, as sorted `/`-separated paths relative to `dir`. Dotfiles and dot dirs
/// (`.DS_Store`, editor swap files) are no templates and are skipped.
pub(crate) fn template_files(dir: &Path) -> std::io::Result<Vec<String>> {
    let mut files = Vec::new();
    collect(dir, "", &mut files)?;
    files.sort_unstable();
    Ok(files)
}

fn collect(dir: &Path, prefix: &str, files: &mut Vec<String>) -> std::io::Result<()> {
    for entry in std::fs::read_dir(dir)? {
        let entry = entry?;
        let name = entry.file_name();
        let Some(name) = name.to_str() else {
            return Err(std::io::Error::new(
                std::io::ErrorKind::InvalidData,
                format!("non-UTF-8 template file name in {}", dir.display()),
            ));
        };
        if name.starts_with('.') {
            continue;
        }
        let relative = format!("{prefix}{name}");
        if entry.file_type()?.is_dir() {
            collect(&entry.path(), &format!("{relative}/"), files)?;
        } else {
            files.push(relative);
        }
    }
    Ok(())
}