open Fnm; let mkDownloadsDir = () => { let exists = Lwt_unix.file_exists(Directories.downloads); if%lwt (exists |> Lwt.map(x => !x)) { Console.log( "Creating " Directories.downloads " for the first time" , ); let%lwt _ = System.mkdirp(Directories.downloads); Lwt.return(); } else { Lwt.return(); }; }; let main = (~version as versionName) => { let%lwt os = System.NodeOS.get() and arch = System.NodeArch.get() and versionName = switch (versionName) { | Some(versionName) => Lwt.return(versionName) | None => Nvmrc.getVersion() }; let versionName = Versions.format(versionName); Console.log( "Looking for node " versionName " for " {System.NodeOS.toString(os)} " " {System.NodeArch.toString(arch)} , ); let%lwt filepath = Versions.getFileToDownload(~version=versionName, ~os, ~arch); let tarDestination = Filename.concat(Directories.downloads, versionName ++ ".tar.gz"); Console.log( "Downloading " filepath " to " tarDestination , ); let%lwt _ = System.mkdirp(Filename.dirname(tarDestination)); let%lwt _ = Http.download(filepath, ~into=tarDestination); let extractionDestination = Filename.concat(Directories.nodeVersions, versionName); Console.log( "Extracting " tarDestination " to " extractionDestination , ); let%lwt _ = Compression.extractFile(tarDestination, ~into=extractionDestination); Lwt.return(); }; let run = (~version) => try%lwt (main(~version)) { | Versions.No_Download_For_System(os, arch) => Console.log( "Version exists, but can't find a file for your system:\n" " OS: " {System.NodeOS.toString(os)} "\n" " Architecture: " {System.NodeArch.toString(arch)} , ) |> Lwt.return | Versions.Version_not_found(version) => Console.log( "Version " version " not found!" , ) |> Lwt.return };