···3131 let@ dir_to_copy = List.iter @~ dirs_to_copy in
3232 Forester.copy_contents_of_dir ~env @@ path_of_dir ~env dir_to_copy
33333434+let export ~env config_filename =
3535+ let config = Forester_frontend.Config.parse_forest_config_file config_filename in
3636+ let tree_dirs = paths_of_dirs ~env config.trees in
3737+ let asset_dirs = paths_of_dirs ~env config.assets in
3838+ Forester.plant_forest_from_dirs ~env ~host: config.host ~dev: false ~tree_dirs ~asset_dirs;
3939+ let host =
4040+ match config.host with
4141+ | Some host -> host
4242+ | None -> Reporter.fatalf Configuration_error "To export a forest, you must first fill in the `host' field in %s" config_filename
4343+ in
4444+ Forester.export ~env ~host ~asset_dirs
4545+3446let new_tree ~env config_filename dest_dir prefix template random =
3547 let@ () = Reporter.silence in
3648 let config = Forester_frontend.Config.parse_forest_config_file config_filename in
···169181 $ arg_no_theme
170182 )
171183184184+let export_cmd ~env =
185185+ let doc = "Export your forest to an archive that can be planted elsewhere" in
186186+ let man = [] in
187187+ let info = Cmd.info "export" ~version ~doc ~man in
188188+ Cmd.v info Term.(const (export ~env) $ arg_config)
189189+172190let new_tree_cmd ~env =
173191 let arg_prefix =
174192 let doc = "The namespace prefix for the created tree." in
···252270 ]
253271 in
254272 let info = Cmd.info "forester" ~version ~doc ~man in
255255- Cmd.group info [build_cmd ~env; new_tree_cmd ~env; complete_cmd ~env; init_cmd ~env; query_cmd ~env]
273273+ Cmd.group info [build_cmd ~env; new_tree_cmd ~env; complete_cmd ~env; init_cmd ~env; query_cmd ~env; export_cmd ~env]
256274257275let () =
258276 Random.self_init ();
···167167 let@ writer = Eio.Buf_write.with_flow flow in
168168 Client.pp_xml ~stylesheet (Eio.Buf_write.make_formatter writer) article
169169 end
170170+171171+let export ~env ~host ~asset_dirs : unit =
172172+ let@ () = Reporter.profile "Export forest" in
173173+ let cwd = Eio.Stdenv.cwd env in
174174+ let trees = FU.get_all_articles () in
175175+ let result = Json_client.render_trees ~host trees in
176176+ let dir = Eio.Path.(cwd / "export" / host) in
177177+ Eio.Path.mkdirs ~exists_ok: true ~perm: 0o755 dir;
178178+ Eio.Path.save ~create: (`Or_truncate 0o644) Eio.Path.(dir / "forest.json") result;
179179+ let@ dir_to_copy = List.iter @~ asset_dirs in
180180+ let source = EP.native_exn dir_to_copy in
181181+ let dest_dir = EP.native_exn dir in
182182+ Eio_util.copy_to_dir ~env ~cwd ~source ~dest_dir
+6
lib/frontend/Forester.mli
···1919 stylesheet: string ->
2020 unit
21212222+val export :
2323+ env: env ->
2424+ host: string ->
2525+ asset_dirs: dir list ->
2626+ unit
2727+2228val copy_contents_of_dir :
2329 env: env ->
2430 dir ->