Skip to main content

idt/installers/
deno.rs

1use std::path::Path;
2
3use ytil_sys::Arch;
4use ytil_sys::Os;
5use ytil_sys::SysInfo;
6
7use crate::downloaders::http::deflate::ChecksumSource;
8use crate::downloaders::http::deflate::HttpDeflateOption;
9use crate::installers::Installer;
10use crate::installers::SystemDependent;
11
12pub struct Deno<'a> {
13    pub bin_dir: &'a Path,
14    pub sys_info: &'a SysInfo,
15}
16
17impl SystemDependent for Deno<'_> {
18    fn target_arch_and_os(&self) -> (&str, &str) {
19        let SysInfo { os, arch } = self.sys_info;
20        let os = match os {
21            Os::MacOs => "apple-darwin",
22            Os::Linux => "unknown-linux",
23        };
24        let arch = match arch {
25            Arch::Arm => "aarch64",
26            Arch::X86 => "x86_64",
27        };
28        (arch, os)
29    }
30}
31
32impl Installer for Deno<'_> {
33    fn bin_name(&self) -> &'static str {
34        "deno"
35    }
36
37    fn install(&self) -> rootcause::Result<()> {
38        let repo = format!("{0}land/{0}", self.bin_name());
39        let latest_release = crate::downloaders::http::github::get_latest_release_tag(&repo)?;
40
41        let (arch, os) = self.target_arch_and_os();
42
43        let filename = format!("{}-{arch}-{os}.zip", self.bin_name());
44        let checksums_url =
45            format!("https://github.com/{repo}/releases/download/{latest_release}/{filename}.sha256sum");
46
47        let target = crate::downloaders::http::run(
48            &format!("https://github.com/{repo}/releases/download/{latest_release}/{filename}"),
49            &HttpDeflateOption::ExtractZip {
50                dest_dir: self.bin_dir,
51                dest_name: Some(self.bin_name()),
52            },
53            Some(&ChecksumSource {
54                checksums_url: &checksums_url,
55                filename: &filename,
56            }),
57        )?;
58
59        ytil_sys::file::chmod_x(&target)?;
60
61        Ok(())
62    }
63}