1use std::path::PathBuf;
2use tokio::fs;
3
4pub struct Changesets {
5 pub directory: PathBuf,
6}
7
8impl Changesets {
9 fn readme_path(&self) -> PathBuf {
10 let mut readme_path = self.directory.clone();
11 readme_path.push("README.md");
12 readme_path
13 }
14
15 pub fn validate(&self) -> bool {
16 self.directory.exists() && self.readme_path().exists()
17 }
18
19 pub async fn initialize(&self) -> Result<(), std::io::Error> {
20 if !self.directory.exists() {
21 fs::create_dir(&self.directory).await?;
22 }
23
24 fs::write(self.readme_path(), b"# Changesets directory\n\nThis directory is for changeset files, can be createted with `mol add`\n\n").await?;
25
26 Ok(())
27 }
28}
29
30impl Default for Changesets {
31 fn default() -> Self {
32 Changesets {
33 directory: [".changeset"].iter().collect(),
34 }
35 }
36}