use std::fmt;
use comemo::{Track, Tracked};
use typst::ecow::EcoString;
use typst_kit::datetime::Time;
use typst_kit::fonts::FontStore;
use crate::foundation::{FilesystemDependency, FontConfig, Project};
mod content;
mod downloader;
mod files;
mod output;
mod pipeline;
mod postprocess;
mod transform;
mod world;
use self::files::ProjectFiles;
pub use pipeline::BuildOutcome;
pub struct BuildSession {
project: Project,
font_config: Option<FontConfig>,
fonts: FontStore,
files: ProjectFiles,
now: Time,
dev: bool,
}
impl BuildSession {
pub fn new(project: Project, dev: bool) -> Self {
let files = ProjectFiles::new(&project);
Self {
project,
font_config: None,
fonts: FontStore::new(),
files,
now: Time::system(),
dev,
}
}
pub fn project(&self) -> &Project {
&self.project
}
pub fn dependencies(&mut self) -> Vec<FilesystemDependency> {
self.files.dependencies()
}
fn reset(&mut self) {
self.files.reset();
self.now.reset();
}
fn project_files(&self) -> Tracked<'_, ProjectFiles> {
self.files.track()
}
}
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct BuildWarning(EcoString);
impl BuildWarning {
fn new(message: impl Into<EcoString>) -> Self {
Self(message.into())
}
pub fn as_str(&self) -> &str {
self.0.as_str()
}
}
impl fmt::Display for BuildWarning {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str(&self.0)
}
}
impl AsRef<str> for BuildWarning {
fn as_ref(&self) -> &str {
self.as_str()
}
}