Skip to main content

wowlab_docgen_cli/context/collectors/
package.rs

1use serde::Serialize;
2
3use super::{ContextEntry, to_value};
4use crate::RenderCtx;
5
6/// A script entry for template rendering.
7#[derive(Debug, Serialize)]
8// #t(rust_similar_structs) package-script template rows are distinct from Cargo alias rows despite sharing display fields
9pub struct ScriptEntry {
10    pub name: String,
11    pub command: String,
12}
13
14/// Collect package.json scripts.
15#[must_use]
16pub fn collect(ctx: &RenderCtx<'_>) -> Vec<ContextEntry> {
17    let scripts: Vec<ScriptEntry> = ctx
18        .metadata
19        .scripts
20        .iter()
21        .map(|s| ScriptEntry {
22            name: s.name.clone(),
23            command: s.command.clone(),
24        })
25        .collect();
26
27    if scripts.is_empty() {
28        return Vec::new();
29    }
30
31    vec![("scripts", to_value(&scripts))]
32}