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 design;
14pub mod exports;
15pub mod manifest;
16pub mod media;
17pub mod serve;
18pub mod yres;
19pub mod yui;
20pub mod yui_component;
21pub mod yui_grid;
22pub mod yui_vm;
23
24/// Writes generated `code` to `path` (creating its directory) unless it's
25/// already there — unchanged files keep their mtime, so cargo doesn't
26/// rebuild for nothing.
27pub(crate) fn write_if_changed(path: &std::path::Path, code: &str) -> Result<(), String> {
28    if std::fs::read_to_string(path).ok().as_deref() == Some(code) {
29        return Ok(());
30    }
31    if let Some(dir) = path.parent() {
32        std::fs::create_dir_all(dir).map_err(|e| format!("{}: {e}", dir.display()))?;
33    }
34    std::fs::write(path, code).map_err(|e| format!("{}: {e}", path.display()))
35}