Browse Source
* support lts/* * Remove redundant line * Add test * Slight refactorremotes/origin/add-simple-redirecting-site
![gal@spitfire.co.il](/assets/img/avatar_default.png)
![GitHub](/assets/img/avatar_default.png)
17 changed files with 183 additions and 51 deletions
@ -0,0 +1,10 @@ |
|||||||
|
#!/bin/bash |
||||||
|
|
||||||
|
set -e |
||||||
|
|
||||||
|
eval "$(fnm env --multi)" |
||||||
|
|
||||||
|
fnm install |
||||||
|
fnm use |
||||||
|
|
||||||
|
fnm ls | grep latest- |
@ -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; |
||||||
|
}; |
@ -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; |
||||||
|
}; |
Loading…
Reference in new issue