Skip to content

Commit dba790d

Browse files
committed
builder: add flag to copy out static files.
1 parent 9f9eaad commit dba790d

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/bin/builder.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ struct Cli {
168168
#[clap(short)]
169169
output: PathBuf,
170170

171+
/// Output directory containing static files.
172+
#[clap(long)]
173+
output_static: Option<PathBuf>,
174+
171175
/// Compress output with zstd
172176
#[clap(short, env = "BUILDER_COMPRESS")]
173177
compress: bool,
@@ -218,6 +222,9 @@ fn main() -> io::Result<()> {
218222
}
219223
drop(tx);
220224

225+
let statics_copied: &Mutex<bool> = &Mutex::new(false);
226+
let static_path = &cli.output_static;
227+
221228
thread::scope(|s| {
222229
// Spawn workers
223230
for i in 0..num_threads {
@@ -302,6 +309,28 @@ fn main() -> io::Result<()> {
302309
//fs::remove_dir_all(doc_dir.join("implementors")).unwrap();
303310
//fs::remove_file(doc_dir.join("crates.js")).unwrap();
304311
//fs::remove_file(doc_dir.join("source-files.js")).unwrap();
312+
313+
if let Some(static_path) = static_path {
314+
let copy_done =
315+
std::mem::replace(&mut *statics_copied.lock().unwrap(), true);
316+
if !copy_done {
317+
fs::create_dir_all(static_path).unwrap();
318+
// recursive copy
319+
let mut stack = vec![doc_dir.join("static.files")];
320+
while let Some(path) = stack.pop() {
321+
if path.is_dir() {
322+
for entry in fs::read_dir(path).unwrap() {
323+
stack.push(entry.unwrap().path());
324+
}
325+
} else {
326+
let rel_path = path.strip_prefix(&doc_dir).unwrap();
327+
let target_path = static_path.join(rel_path);
328+
let _ = fs::create_dir_all(target_path.parent().unwrap());
329+
fs::copy(path, target_path).unwrap();
330+
}
331+
}
332+
}
333+
}
305334
}
306335
});
307336
}

0 commit comments

Comments
 (0)