Skip to main content

yog_cli/
lib.rs

1//! The `yog` CLI's internals: `yog.toml` parsing, the generated
2//! `.yog-build/` workspace, `.yres` resources, `content/` blocks and items,
3//! `.yui` screens and `#[yog_export]` crates.
4//!
5//! Not for external use — a library only so the `yog` binary, its tests and
6//! its benches share the code. No API stability, not published separately.
7
8pub mod bench;
9pub mod book_page;
10pub mod recipe_area;
11pub mod cargo_toml;
12pub mod content;
13pub mod exports;
14pub mod manifest;
15pub mod yres;
16pub mod yui;
17pub mod yui_component;
18pub mod yui_grid;
19pub mod yui_vm;
20
21/// Writes generated `code` to `path` (creating its directory) unless it's
22/// already there — unchanged files keep their mtime, so cargo doesn't
23/// rebuild for nothing.
24pub(crate) fn write_if_changed(path: &std::path::Path, code: &str) -> Result<(), String> {
25    if std::fs::read_to_string(path).ok().as_deref() == Some(code) {
26        return Ok(());
27    }
28    if let Some(dir) = path.parent() {
29        std::fs::create_dir_all(dir).map_err(|e| format!("{}: {e}", dir.display()))?;
30    }
31    std::fs::write(path, code).map_err(|e| format!("{}: {e}", path.display()))
32}