yog-cli 0.52.0

Yog build tool — `yog build` compiles a mod and packages it as .yog.
//! The `yog` CLI's internals: `yog.toml` parsing, the generated
//! `.yog-build/` workspace, `.yres` resources, `content/` blocks and items,
//! `.yui` screens and `#[yog_export]` crates.
//!
//! Not for external use — a library only so the `yog` binary, its tests and
//! its benches share the code. No API stability, not published separately.

// What the binary, tests and benches reach is documented (the rest is `pub(crate)`).
#![warn(missing_docs)]

mod consts;
pub mod content;
pub mod design;
pub mod diagnostics;
pub mod files;
pub mod media;
pub mod project;
pub mod script;
pub mod serve;
pub mod ui;
pub mod yres;

/// `path` with `/` between its parts, whatever the system's separator.
pub fn slash_path(path: &std::path::Path) -> String {
    path.to_string_lossy().replace('\\', yog_ids::sep::PATH)
}

/// `path` as a project shows it: relative to its `root`, `/`-separated.
pub(crate) fn shown_path(root: &std::path::Path, path: &std::path::Path) -> String {
    slash_path(path.strip_prefix(root).unwrap_or(path))
}

/// Writes generated `code` to `path` unless it's already there
/// ([`yog_codegen::write_if_changed`]), the error naming the file.
pub(crate) fn write_if_changed(
    path: &std::path::Path,
    code: impl AsRef<[u8]>,
) -> Result<(), String> {
    yog_codegen::write_if_changed(path, code)
        .map(drop)
        .map_err(|e| format!("{}: {e}", path.display()))
}