Skip to main content

dxm_init/
lib.rs

1//! A crate for initializing FXServer data directories.
2
3use std::{error::Error, path::Path};
4
5use dxm_manifest::Manifest;
6use vcs::VcsOption;
7
8pub mod vcs;
9
10pub const SERVER_CFG_NAME: &str = "server.cfg";
11
12/// Initialize server data files in the given directory path with the given vcs.
13pub fn server<P>(path: P, vcs: &VcsOption) -> Result<(), Box<dyn Error>>
14where
15    P: AsRef<Path>,
16{
17    let path = path.as_ref();
18
19    fs_err::create_dir_all(path)?;
20
21    let manifest = Manifest::default();
22    let data_path = manifest.server.data(path);
23
24    manifest.write(path)?;
25
26    fs_err::create_dir_all(manifest.server.resources(path))?;
27    fs_err::write(data_path.join(SERVER_CFG_NAME), "")?;
28
29    vcs.init(path, &manifest)?;
30
31    Ok(())
32}