this repo has no description
1let json ~html_dir ~pkg ?(redirections = Hashtbl.create 0) () =
2 let files =
3 let lib_dir = Odoc_unit.pkg_dir pkg in
4 let lib_dir = Fpath.( // ) html_dir lib_dir in
5 let files =
6 Bos.OS.Dir.fold_contents
7 ~elements:(`Sat (fun x -> Ok (Fpath.has_ext "html" x)))
8 (fun path acc ->
9 `String
10 (Fpath.to_string (Fpath.rem_prefix lib_dir path |> Option.get))
11 :: acc)
12 [] lib_dir
13 |> function
14 | Ok e -> e
15 | Error (`Msg err) ->
16 Logs.err (fun m ->
17 m "Got an error while collecting files for status.json: %s" err);
18 []
19 in
20 `List files
21 in
22 let name = `String pkg.Packages.name in
23 let version = `String pkg.Packages.version in
24 let failed = `Bool false in
25 let redirections =
26 Hashtbl.fold
27 (fun old_path new_path acc ->
28 `Assoc
29 [
30 ("old_path", `String (Fpath.to_string old_path));
31 ("new_path", `String (Fpath.to_string new_path));
32 ]
33 :: acc)
34 redirections []
35 in
36 let redirections = `List redirections in
37 `Assoc
38 [
39 ("name", name);
40 ("version", version);
41 ("files", files);
42 ("failed", failed);
43 ("redirections", redirections);
44 ]
45
46let file ~html_dir ~pkg ?(redirections = Hashtbl.create 0) () =
47 let json = json ~html_dir ~pkg ~redirections () in
48 let json = Yojson.Safe.pretty_to_string json in
49 let status_path = Fpath.(html_dir // Odoc_unit.pkg_dir pkg / "status.json") in
50 match Bos.OS.File.write status_path json with
51 | Ok () -> ()
52 | Error (`Msg msg) ->
53 Logs.err (fun m ->
54 m "Error when generating status.json for %s: %s" pkg.name msg)