Your browser sucks, JavaScript disabled! Gunnar's console needs JavaScript and WebAssembly. Git over SSH on port 2222 does not.

nordisk/facett

facett-ops/src/pages.rs

//! **`cargo ops demo-wasm` / `deploy-pages` — the live web demo, built in the
//! pinned image and published as-built.**
//!
//! THE LAW: *a build thing builds in a container or a KVM, never on the host.* Until
//! 2026-09-29 both verbs were the old `nornir_pages::demo_wasm`, which spelled its own
//! host `cargo build --release -p facett-demo --target wasm32-…` and ran the HOST's
//! wasm-bindgen — a second writer of the `facett-demo-wasm` row, on the box's
//! toolchain. Since 2026-09-30 edda's `nornir_pages::demo_wasm(cfg, set, variant)`
//! IS the container road, so facett hands it the recipe and the row name:
//!
//! 1. the bundle is the `facett-demo-wasm` ROW, built by
//!    `nornir_build_thing::container_road` exactly as `cargo xtask build --variant
//!    facett-demo-wasm` builds it (`build_variant_in_container`, then the row's
//!    `[[build.wasm]]` bindgen stage in the same image) into the cell's `out_dir`;
//! 2. edda's `nornir_pages::stage_dist` refuses a dist without its bundle and writes
//!    the site shell (cache-busted `index.html`, `.domains`, `.nojekyll`);
//! 3. `deploy-pages` then hands that dist to the gix orphan commit + force-push.
//!
//! This module names no package, feature or triple: the row, its package (the
//! bundle's file stem) and its out dir are all the recipe's. It lives in facett-ops,
//! not xtask, because the page shell and the publish are not builds.

use std::path::{Path, PathBuf};

use facett_build_thing::nornir_build_thing::variant::{BuildVariant, BuildVariantSet};
use nornir_pages::PagesConfig;

/// The branch Codeberg Pages serves from.
pub const PAGES_BRANCH: &str = "pages";
/// The live URL (echoed in `--help` + the deploy banner).
pub const PAGES_URL: &str = "https://nordisk.codeberg.page/facett";

/// facett's per-repo gh-pages knobs — the page's divergence from the other
/// constellation demos; the page template, the shell files and the orphan-branch
/// push are the shared [`nornir_pages`] flow. `root` is the workspace root.
pub fn pages_cfg(root: &Path) -> PagesConfig {
    PagesConfig {
        // The bundle's file stem = the recipe's `DEMO_PACKAGE`, the crate the
        // `facett-demo-wasm` row builds.
        demo_crate: facett_build_thing::DEMO_PACKAGE,
        // The eframe canvas id the wasm entry (`facett-demo/src/main.rs::wasm_start`)
        // and the `index.html` loader agree on.
        canvas_id: "facett_demo",
        // The exported JS state-hook name (`__facett_state`) lifted onto `window`.
        state_export: "__facett_state",
        title: "facett — live web demo",
        description: "facett: reusable data-viewing components for egui — the live in-browser showcase (every component, every palette).",
        pages_url: PAGES_URL,
        pages_host: "nordisk.codeberg.page",
        pages_branch: PAGES_BRANCH,
        // The env var naming the push remote; unset → `origin`
        // (`ssh://git@git.gunnar.rs:2222/nordisk/facett.git`, SSH-only per the nordisk law).
        remote_env: "FACETT_PAGES_REMOTE",
        commit_label: "facett live web demo",
        // Read by nothing since edda's host road left (2026-09-30): the row's features
        // are the recipe's. Empty, and goes when edda drops the field.
        extra_build_args: &[],
        workspace_root: root.to_path_buf(),
    }
}

/// The declared demo row and the dist its `[[build.wasm]]` cell writes — edda's
/// `nornir_pages::demo_row` over the recipe's `DEMO_WASM_VARIANT`: refused BY NAME if
/// the recipe stops declaring either, or if the page would import files the cell does
/// not produce (a page whose `import` 404s is the silent-green deploy).
pub fn demo_row<'a>(set: &'a BuildVariantSet, root: &Path) -> Result<(&'a BuildVariant, PathBuf), String> {
    nornir_pages::demo_row(&pages_cfg(root), set, facett_build_thing::DEMO_WASM_VARIANT).map_err(|e| e.to_string())
}

/// **Build the demo bundle in the pinned image and stage the site shell** — edda's
/// `nornir_pages::demo_wasm` over the recipe's row (the container road:
/// `nornir_build_thing::container_road`, the same writer `cargo xtask build` uses).
/// Returns the dist dir. No host cargo, no host wasm-bindgen.
pub fn demo_bundle(root: &Path) -> Result<PathBuf, String> {
    let set = facett_build_thing::declared();
    set.validate_all_in(root).map_err(|e| format!("facett-build-thing is refused: {e:#}"))?;
    nornir_pages::demo_wasm(&pages_cfg(root), &set, facett_build_thing::DEMO_WASM_VARIANT).map_err(|e| e.to_string())
}

/// **Build in the image, then publish the dist to the `pages` branch** — edda's
/// `nornir_pages::deploy_pages` over the recipe's row. Returns the pushed pages commit.
pub fn deploy(root: &Path) -> Result<String, String> {
    let set = facett_build_thing::declared();
    set.validate_all_in(root).map_err(|e| format!("facett-build-thing is refused: {e:#}"))?;
    nornir_pages::deploy_pages(&pages_cfg(root), &set, facett_build_thing::DEMO_WASM_VARIANT).map_err(|e| e.to_string())
}