fixed dir bug, reasonable defaults
This commit is contained in:
parent
8c8fbc91aa
commit
f0f3a74dcb
21
src/main.rs
21
src/main.rs
|
@ -6,7 +6,7 @@ use std::{
|
|||
};
|
||||
|
||||
fn main() {
|
||||
let mut src_path = String::from("./");
|
||||
let mut src_path = String::from("./src");
|
||||
let mut dist_path = String::from("./dist");
|
||||
for arg in std::env::args() {
|
||||
if let Some(s) = arg.strip_prefix("--path=") {
|
||||
|
@ -55,12 +55,29 @@ fn convert_all(src_path: &Path, dist_path: &Path) {
|
|||
"css" => convert_css(file, src_path, dist_path),
|
||||
"js" => convert_js(file, src_path, dist_path),
|
||||
"json" => convert_json(file, src_path, dist_path),
|
||||
_ => Ok(()),
|
||||
_ => copy(file, src_path, dist_path),
|
||||
}
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
fn copy(
|
||||
file: &Path,
|
||||
src_path: &Path,
|
||||
dist_path: &Path,
|
||||
) -> Result<(), std::io::Error> {
|
||||
if file.is_dir() {
|
||||
return Ok(());
|
||||
}
|
||||
let file_contents = std::fs::read(file)?;
|
||||
let dist_path = dist_path.join(file.strip_prefix(src_path).unwrap_or(file));
|
||||
if let Some(path) = dist_path.parent() {
|
||||
let _ = std::fs::create_dir_all(path);
|
||||
}
|
||||
std::fs::File::create(dist_path)?.write(&file_contents)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn convert_md(
|
||||
file: &Path,
|
||||
src_path: &Path,
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
# hello world
|
Loading…
Reference in a new issue