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

Loading…
Cancel
Save