1use crate::traits::{LoadYaml, SaveMessagePack, SaveYaml};
2use crate::{
3 structs::{Bookmark, Story},
4 Error,
5};
6
7use std::path::Path;
8
9fn dump<S: SaveYaml + SaveMessagePack>(obj: &S, outpath: &Path) -> Result<(), Error> {
11 if cfg!(debug_assertions) {
13 obj.save_yml(outpath.with_extension("yml"))?;
14 }
15
16 obj.save_mp(outpath)
18}
19
20pub fn pack(dir: &str, outdir: &str) -> Result<(), Error> {
22 let path = Path::new(dir);
23 let outpath = Path::new(outdir);
24
25 let story = Story::load_yml(path.join("story"))?;
26 dump(&story, &outpath.join("story"))?;
27
28 let mut bookmark = Bookmark::load_yml(path.join("bookmark.yml"))?;
30 bookmark.init_state(&story);
31 dump(&bookmark, &outpath.join("bookmark"))?;
32 Ok(())
33}