Skip to main content

vorpal_sdk/artifact/
nodejs.rs

1use crate::{
2    api::artifact::ArtifactSystem::{Aarch64Darwin, Aarch64Linux, X8664Darwin, X8664Linux},
3    artifact::{step, Artifact, ArtifactSource},
4    context::ConfigContext,
5};
6use anyhow::{bail, Result};
7
8#[derive(Default)]
9pub struct NodeJS {}
10
11impl NodeJS {
12    pub fn new() -> Self {
13        Self::default()
14    }
15
16    pub async fn build(self, context: &mut ConfigContext) -> Result<String> {
17        let name = "nodejs";
18
19        let system = context.get_system();
20
21        let source_target = match system {
22            Aarch64Darwin => "darwin-arm64",
23            Aarch64Linux => "linux-arm64",
24            X8664Darwin => "darwin-x64",
25            X8664Linux => "linux-x64",
26            _ => bail!("unsupported {name} system: {}", system.as_str_name()),
27        };
28
29        let source_version = "22.22.0";
30        let source_path = format!(
31            "https://sdk.vorpal.build/source/node-v{source_version}-{source_target}.tar.gz"
32        );
33
34        let source = ArtifactSource::new(name, source_path.as_str()).build();
35
36        let step_script = format!(
37            "cp -pr \"./source/{name}/node-v{source_version}-{source_target}/.\" \"$VORPAL_OUTPUT\""
38        );
39        let steps = vec![step::shell(context, vec![], vec![], step_script, vec![]).await?];
40        let systems = vec![Aarch64Darwin, Aarch64Linux, X8664Darwin, X8664Linux];
41
42        Artifact::new(name, steps, systems)
43            .with_aliases(vec![format!("{name}:{source_version}")])
44            .with_sources(vec![source])
45            .build(context)
46            .await
47    }
48}