Skip to main content

flowey_lib_common/
download_mdbook_mermaid.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Download a copy of `mdbook-mermaid`
5
6use flowey::node::prelude::*;
7
8flowey_config! {
9    /// Config for the download_mdbook_mermaid node.
10    pub struct Config {
11        /// Version of `mdbook-mermaid` to install
12        pub version: Option<String>,
13    }
14}
15
16flowey_request! {
17    pub enum Request {
18        /// Get a path to `mdbook-mermaid`
19        GetMdbookMermaid(WriteVar<PathBuf>),
20    }
21}
22
23new_flow_node_with_config!(struct Node);
24
25impl FlowNodeWithConfig for Node {
26    type Request = Request;
27    type Config = Config;
28
29    fn imports(ctx: &mut ImportCtx<'_>) {
30        ctx.import::<crate::install_dist_pkg::Node>();
31        ctx.import::<crate::download_gh_release::Node>();
32    }
33
34    fn emit(
35        config: Config,
36        requests: Vec<Self::Request>,
37        ctx: &mut NodeCtx<'_>,
38    ) -> anyhow::Result<()> {
39        let (version, get_mdbook_mermaid) = crate::download_mdbook::collect_download_requests(
40            config.version,
41            requests,
42            |Request::GetMdbookMermaid(v)| v,
43        )?;
44
45        if get_mdbook_mermaid.is_empty() {
46            return Ok(());
47        }
48
49        crate::download_mdbook::download_mdbook_tool(
50            ctx,
51            "mdbook-mermaid",
52            "badboy",
53            "mdbook-mermaid",
54            &version,
55            get_mdbook_mermaid,
56        )
57    }
58}