37 lines
1.2 KiB
Rust
37 lines
1.2 KiB
Rust
![]() |
use std::path::PathBuf;
|
||
|
|
||
|
use crate::error::CustomError;
|
||
|
|
||
|
use super::RenderContext;
|
||
|
|
||
|
#[derive(Debug)]
|
||
|
pub(crate) enum Dependency {
|
||
|
StaticFile { absolute_path: PathBuf },
|
||
|
}
|
||
|
|
||
|
impl Dependency {
|
||
|
pub(crate) async fn perform(
|
||
|
&self,
|
||
|
render_context: RenderContext<'_>,
|
||
|
) -> Result<(), CustomError> {
|
||
|
match self {
|
||
|
Dependency::StaticFile { absolute_path } => {
|
||
|
let input_root_directory = render_context.config.get_root_directory();
|
||
|
let relative_path_to_file = absolute_path.strip_prefix(input_root_directory)?;
|
||
|
let path_to_output = render_context
|
||
|
.output_root_directory
|
||
|
.join(relative_path_to_file);
|
||
|
tokio::fs::create_dir_all(
|
||
|
path_to_output
|
||
|
.parent()
|
||
|
.ok_or("Output file should have a containing directory.")?,
|
||
|
)
|
||
|
.await?;
|
||
|
// TODO: If file already exists, either error out or compare hash to avoid duplicate write.
|
||
|
tokio::fs::copy(absolute_path, path_to_output).await?;
|
||
|
Ok(())
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|