omni_forge/image_builder/ensure/
ensure_npm.rs

1use super::common::get_platform;
2use std::io;
3use std::process::Command;
4
5pub fn install_node_platform() -> io::Result<()> {
6    let platform = get_platform();
7
8    match platform.as_str() {
9        "windows" => {
10            println!("Installing Node.js using winget...");
11            Command::new("winget")
12                .args(["install", "OpenJS.NodeJS"])
13                .status()?;
14        }
15        "darwin" => {
16            println!("Installing Node.js using Homebrew...");
17            Command::new("brew").args(["install", "node"]).status()?;
18        }
19        "linux" => {
20            println!("Installing Node.js using package manager...");
21            let apt_result = Command::new("apt")
22                .args(["install", "-y", "nodejs", "npm"])
23                .status();
24
25            if apt_result.is_err() {
26                let dnf_result = Command::new("dnf")
27                    .args(["install", "-y", "nodejs", "npm"])
28                    .status();
29
30                if dnf_result.is_err() {
31                    Command::new("pacman")
32                        .args(["-S", "--noconfirm", "nodejs", "npm"])
33                        .status()?;
34                }
35            }
36        }
37        _ => return Err(io::Error::new(io::ErrorKind::Other, "Unsupported platform")),
38    }
39
40    Ok(())
41}