glacier-web-cli 0.5.0

Command-line tool for creating and running Glacier applications.
//! Lists the component library's files (`templates/ui/`, laid out as in an
//! app) for `glacier new` to copy into each new app.

use std::path::{Path, PathBuf};

fn main() {
    let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("templates/ui");
    println!("cargo:rerun-if-changed={}", root.display());
    let mut files = Vec::new();
    walk(&root, &mut files);
    files.sort();
    let mut out = String::from(
        "/// The component library's files: (path in the app, contents).\npub const UI_FILES: &[(&str, &[u8])] = &[\n",
    );
    for file in &files {
        let relative = file
            .strip_prefix(&root)
            .unwrap()
            .to_string_lossy()
            .replace('\\', "/");
        out.push_str(&format!(
            "    ({relative:?}, include_bytes!({:?})),\n",
            file.display().to_string()
        ));
    }
    out.push_str("];\n");
    let target = PathBuf::from(std::env::var("OUT_DIR").unwrap()).join("ui_files.rs");
    std::fs::write(target, out).unwrap();
}

fn walk(dir: &Path, files: &mut Vec<PathBuf>) {
    for entry in std::fs::read_dir(dir).unwrap().flatten() {
        let path = entry.path();
        println!("cargo:rerun-if-changed={}", path.display());
        if path.is_dir() {
            walk(&path, files);
        } else {
            files.push(path);
        }
    }
}