package drom_lib

  1. Overview
  2. Docs

Source file commandOdoc.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
(**************************************************************************)
(*                                                                        *)
(*    Copyright 2020 OCamlPro & Origin Labs                               *)
(*                                                                        *)
(*  All rights reserved. This file is distributed under the terms of the  *)
(*  GNU Lesser General Public License version 2.1, with the special       *)
(*  exception on linking described in the file LICENSE.                   *)
(*                                                                        *)
(**************************************************************************)

open Ez_file.V1
open Ezcmd.V2
open EZCMD.TYPES
open EzFile.OP

let cmd_name = "odoc"

let make_odoc p =
  Misc.call [| "opam"; "exec"; "--"; "dune"; "build"; "@doc" |];
  let dir = Misc.odoc_target p in
  let odoc_target = Format.sprintf "_drom/docs/%s" dir in
  EzFile.make_dir ~p:true odoc_target;
  Misc.call
    [| "rsync"; "-auv"; "--delete"; "_build/default/_doc/_html/."; odoc_target |];
  odoc_target

let action ~args ~open_www () =
  let (p : Types.project) = Build.build ~dev_deps:true ~args () in
  let odoc_target = make_odoc p in
  if !open_www then
    Misc.call [| "xdg-open"; odoc_target // "index.html" |]

let cmd =
  let args, specs = Build.build_args () in
  let open_www = ref false in
  EZCMD.sub cmd_name
    (fun () -> action ~args ~open_www ())
    ~args: (
      [ ( [ "view" ],
          Arg.Set open_www,
          EZCMD.info "Open a browser on the documentation" )
      ]
      @ specs
    )
    ~doc:
      "Generate API documentation using odoc in the _drom/docs/doc directory"