Skip to content

Commit

Permalink
add content directory
Browse files Browse the repository at this point in the history
  • Loading branch information
HectorCastelli committed Jan 9, 2024
1 parent ec5a4fa commit 8f16828
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
6 changes: 6 additions & 0 deletions fixtures/commands/initialize/content.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"schema": "sample",
"renderOrder": 1,
"name": "Sample",
"number": 10
}
4 changes: 4 additions & 0 deletions fixtures/commands/initialize/content.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
schema: sample
renderOrder: 1
name: Sample
number: 10
34 changes: 31 additions & 3 deletions src/commands/initialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ impl<F: FileSystem> Command<F> for Initialize {
self.initialize_module_file(&root, fs);
self.initialize_authors(&root, fs);
self.initialize_schema(&root, fs);
debug!("Create contents directory");
self.initialize_content(&root, fs);
trace!("Finished initializing")
}
}

Expand Down Expand Up @@ -111,16 +112,43 @@ impl Initialize {
trace!("Creating sample schema");
let (file_name, contents) = match self.file_type {
FileType::Json => (
"schema.json",
"sample.json",
include_str!("../../fixtures/commands/initialize/schema.json"),
),
FileType::Yaml => (
"schema.yaml",
"sample.yaml",
include_str!("../../fixtures/commands/initialize/schema.yaml"),
),
};
fs.create_file(&dir.join(file_name), contents)
.expect("Sample schema file could not be created");
}
}

fn initialize_content(&self, root: &PathBuf, fs: &impl FileSystem) {
trace!("Initializing content directory");
let dir = fs.create_dir_if_not_exists(&root.join("content")).unwrap();

let dir_children = fs.get_dir_children(dir.as_ref());
debug!(
"Content directory has {} files",
dir_children.clone().map_or(0, |v| v.len())
);

if dir_children.is_none() {
trace!("Creating sample content");
let (file_name, contents) = match self.file_type {
FileType::Json => (
"content.json",
include_str!("../../fixtures/commands/initialize/content.json"),
),
FileType::Yaml => (
"content.yaml",
include_str!("../../fixtures/commands/initialize/content.yaml"),
),
};
fs.create_file(&dir.join(file_name), contents)
.expect("Sample content file could not be created");
}
}
}

0 comments on commit 8f16828

Please sign in to comment.