Browse Source

Create alias from version range (fix #185) (#201)

Based on #194 to benefit from the `LocalVersionResolver` module. So I guess this PR should be merged first. This should fix #185
remotes/origin/add-simple-redirecting-site
Corentin Leruth 5 years ago committed by GitHub
parent
commit
b7ed348541
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 39
      executable/Alias.re

39
executable/Alias.re

@ -2,33 +2,36 @@ open Fnm;
let run = (~name, ~version) => { let run = (~name, ~version) => {
let version = Versions.format(version); let version = Versions.format(version);
let versionPath = let%lwt matchingLocalVersions =
Filename.concat( LocalVersionResolver.getMatchingLocalVersions(version);
Filename.concat(Directories.nodeVersions, version),
"installation",
);
let%lwt versionInstalled = Lwt_unix.file_exists(versionPath);
if (!versionInstalled) { switch (Base.List.hd(matchingLocalVersions)) {
Logger.error( | Some(latestMatchingLocalVersion) =>
<Pastel color=Pastel.Red>
"Can't find a version installed in "
versionPath
</Pastel>,
);
Lwt.return_error(1);
} else {
Logger.info( Logger.info(
<Pastel> <Pastel>
"Aliasing " "Aliasing "
<Pastel color=Pastel.Cyan> name </Pastel> <Pastel color=Pastel.Cyan> name </Pastel>
" to " " to "
<Pastel color=Pastel.Cyan> version </Pastel> <Pastel color=Pastel.Cyan> {latestMatchingLocalVersion.name} </Pastel>
</Pastel>, </Pastel>,
); );
let%lwt () = Versions.Aliases.set(~alias=name, ~versionPath); let%lwt () =
Versions.Aliases.set(
~alias=name,
~versionPath=
Filename.concat(
latestMatchingLocalVersion.fullPath,
"installation",
),
);
Lwt.return_ok(); Lwt.return_ok();
| None =>
Logger.error(
<Pastel color=Pastel.Red>
"No installed versions found that match your criteria."
</Pastel>,
);
Lwt.return_error(1);
}; };
}; };

Loading…
Cancel
Save