-
Notifications
You must be signed in to change notification settings - Fork 497
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* support lts/* * Remove redundant line * Add test * Slight refactor
- Loading branch information
Showing
17 changed files
with
183 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
lts/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
eval "$(fnm env --multi)" | ||
|
||
fnm install | ||
fnm use | ||
|
||
fnm ls | grep latest- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
type item = { | ||
version: string, | ||
date: string, | ||
files: list(string), | ||
lts: option(string), | ||
}; | ||
|
||
let item_of_yojson = (json: Yojson.Safe.t) => { | ||
open Yojson.Safe.Util; | ||
let version = json |> member("version") |> to_string; | ||
let files = json |> member("files") |> to_list |> List.map(to_string); | ||
let date = json |> member("date") |> to_string; | ||
let lts = | ||
Base.Option.try_with(() => { | ||
json |> member("lts") |> to_string |> String.lowercase_ascii | ||
}); | ||
Ok({version, date, files, lts}); | ||
}; | ||
|
||
[@deriving of_yojson({strict: false})] | ||
type t = list(item); | ||
|
||
let parseVersionListing = body => { | ||
Base.Result.try_with(() => Yojson.Safe.from_string(body)) | ||
|> Base.Result.map_error(~f=Printexc.to_string) | ||
|> Base.Result.bind(~f=x => of_yojson(x)); | ||
}; | ||
|
||
let fromHttp = () => { | ||
let url = | ||
Config.FNM_NODE_DIST_MIRROR.get() |> Printf.sprintf("%s/index.json"); | ||
let%lwt {Http.body, _} = Http.makeRequest(url); | ||
parseVersionListing(body) |> Lwt.return; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
type item = { | ||
version: string, | ||
lts: string, | ||
}; | ||
|
||
let item_to_lts = (item: VersionListing.item) => { | ||
item.lts |> Base.Option.map(~f=lts => {lts, version: item.version}); | ||
}; | ||
|
||
type get_latest_lts_errors = | ||
| Cant_parse_remote_version_listing(string) | ||
| Cant_find_latest_lts; | ||
|
||
exception Problem_with_finding_latest_lts(get_latest_lts_errors); | ||
|
||
let getLatest = () => { | ||
let%lwt versions = VersionListing.fromHttp(); | ||
versions | ||
|> Base.Result.map_error(~f=err => Cant_parse_remote_version_listing(err)) | ||
|> Base.Result.bind(~f=parsed => { | ||
parsed | ||
|> Base.List.filter_map(~f=item_to_lts) | ||
|> Base.List.max_elt(~compare=(a, b) => | ||
Versions.compare(a.version, b.version) | ||
) | ||
|> Base.Result.of_option(~error=Cant_find_latest_lts) | ||
}) | ||
|> Lwt.return; | ||
}; |
Oops, something went wrong.