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