yog_cli/lib.rs
1//! The `yog` CLI's internals: `yog.toml` parsing, the generated
2//! `obj/` 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
8// What the binary, tests and benches reach is documented (the rest is `pub(crate)`).
9#![warn(missing_docs)]
10
11mod consts;
12pub mod content;
13pub mod design;
14pub mod diagnostics;
15pub mod files;
16pub mod media;
17pub mod project;
18pub mod script;
19pub mod serve;
20pub mod ui;
21pub mod yres;
22
23/// `path` with `/` between its parts, whatever the system's separator.
24pub fn slash_path(path: &std::path::Path) -> String {
25 path.to_string_lossy().replace('\\', yog_ids::sep::PATH)
26}
27
28/// `path` as a project shows it: relative to its `root`, `/`-separated.
29pub(crate) fn shown_path(root: &std::path::Path, path: &std::path::Path) -> String {
30 slash_path(path.strip_prefix(root).unwrap_or(path))
31}
32
33/// Writes generated `code` to `path` unless it's already there
34/// ([`yog_codegen::write_if_changed`]), the error naming the file.
35pub(crate) fn write_if_changed(
36 path: &std::path::Path,
37 code: impl AsRef<[u8]>,
38) -> Result<(), String> {
39 yog_codegen::write_if_changed(path, code)
40 .map(drop)
41 .map_err(|e| format!("{}: {e}", path.display()))
42}