[@@@module "%/../oar-init.ml"]
include Oar_init

let%include [@in (module Oar_kit)] [@in (module Oar_kit.Firebase) [@as? redirect]]
firebase_redirect ?doc ~mappings libname =
let unit_name = mk_unit_name ~scope:!scope__current libname.libname_name in
( match StringMap.find libname.libname_name !lib_to_unit with
| v -> failwith "trying to fulfill a library that has already been taken!"
| exception Not_found ->
lib_to_unit := StringMap.add libname.libname_name unit_name !lib_to_unit;
unit_to_doc := StringMap.add unit_name (\`redirect, doc) !unit_to_doc
);
match Hashtbl.find unit_ls unit_name with
| v -> failwith "duplicated unit name!"
| exception Not_found ->
Hashtbl.add unit_ls unit_name @@
\`firebase_redirect Io.(fun ?copy_public_to env ->
let cwd = Stdenv.cwd env in
copy_public_to |> Option.iter @@ fun (copy_public_root, process_mgr) ->
let copy_public_root' = remove_cwd @@ Fpath.to_string copy_public_root in
Fiber.List.iter (fun (`prefix prefix, `to_ to_) ->
Path.mkdirs ~exists_ok:true ~perm:0o700 Io.Path.(cwd / copy_public_root' / prefix);
Path.save ~create:(\`Exclusive 0o700) Path.(cwd / copy_public_root' / prefix / "index.html") ("
<html>
<head>
<script type=\"text/javascript\">
window.location.href = \"" ^ to_ ^ "\";
</script>
</head>
</html>
")
) mappings
)