Skip to content

Commit

Permalink
feat: add html_output config
Browse files Browse the repository at this point in the history
tguichaoua authored and ctron committed Jan 13, 2025
1 parent 42f1d3b commit a0183c6
Showing 3 changed files with 26 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/config/models/build.rs
Original file line number Diff line number Diff line change
@@ -19,6 +19,11 @@ pub struct Build {
#[serde(default = "default::target")]
pub target: PathBuf,

/// The name of the output HTML file.
///
/// If not set, use the same file name as the target HTML file.
pub html_output: Option<String>,

/// Build in release mode [default: false]
#[serde(default)]
pub release: bool,
@@ -189,6 +194,7 @@ impl Default for Build {
fn default() -> Self {
Self {
target: default::target(),
html_output: None,
release: false,
cargo_profile: None,
dist: default::dist(),
14 changes: 14 additions & 0 deletions src/config/rt/build.rs
Original file line number Diff line number Diff line change
@@ -31,6 +31,8 @@ pub struct RtcBuild {
pub core: RtcCore,
/// The index HTML file to drive the bundling process.
pub target: PathBuf,
/// The file name of the output HTML file.
pub html_output_filename: String,
/// The parent directory of the target index HTML file.
pub target_parent: PathBuf,
/// Build in release mode.
@@ -132,6 +134,15 @@ impl RtcBuild {
)
})?;

let html_output_filename = match build.html_output {
Some(html_output) => html_output,
None => target
.file_name()
.context("target path isn't a file path")?
.to_string_lossy()
.into_owned(),
};

// Get the target HTML's parent dir, falling back to OS specific root, as that is the only
// time when no parent could be determined.
let target_parent = target
@@ -178,6 +189,7 @@ impl RtcBuild {
Ok(Self {
core,
target,
html_output_filename,
target_parent,
release: build.release,
cargo_profile: build.cargo_profile,
@@ -210,6 +222,7 @@ impl RtcBuild {
#[cfg(test)]
pub async fn new_test(tmpdir: &std::path::Path) -> anyhow::Result<Self> {
let target = tmpdir.join("index.html");
let html_output_filename = String::from("index.html");
let target_parent = tmpdir.to_path_buf();
let final_dist = tmpdir.join("dist");
let staging_dist = final_dist.join(".stage");
@@ -219,6 +232,7 @@ impl RtcBuild {
Ok(Self {
core: RtcCore::new_test(tmpdir),
target,
html_output_filename,
target_parent,
release: false,
cargo_profile: None,
9 changes: 6 additions & 3 deletions src/pipelines/html.rs
Original file line number Diff line number Diff line change
@@ -183,9 +183,12 @@ impl HtmlPipeline {
false => target_html.into_inner(),
};

fs::write(self.cfg.staging_dist.join("index.html"), &output_html)
.await
.context("error writing finalized HTML output")?;
fs::write(
self.cfg.staging_dist.join(&self.cfg.html_output_filename),
&output_html,
)
.await
.context("error writing finalized HTML output")?;

// Spawn and wait on post-build hooks.
wait_hooks(spawn_hooks(self.cfg.clone(), PipelineStage::PostBuild)).await?;

0 comments on commit a0183c6

Please sign in to comment.