-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ec407ff
commit 2111d62
Showing
5 changed files
with
92 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use crate::ProjectInfo; | ||
use std::fs; | ||
use std::io; | ||
use std::path::PathBuf; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct Config { | ||
pub dist_path: PathBuf, | ||
pub web_project_path: PathBuf, | ||
} | ||
|
||
impl Config { | ||
pub fn from_project_info(project_info: &ProjectInfo) -> Self { | ||
Self { | ||
dist_path: project_info.dist_path.clone(), | ||
web_project_path: project_info.web_project_path.clone(), | ||
} | ||
} | ||
|
||
fn web_project_wasm_path(&self) -> PathBuf { | ||
self.web_project_path.join("wasm") | ||
} | ||
} | ||
|
||
#[derive(Debug)] | ||
pub enum Error { | ||
CreateDistDir(io::Error), | ||
CreateWebWasmDir(io::Error), | ||
} | ||
|
||
pub struct Cleaner { | ||
config: Config, | ||
} | ||
|
||
impl Cleaner { | ||
pub fn new(config: Config) -> Self { | ||
Self { config } | ||
} | ||
|
||
pub fn run(&self) -> Result<(), Error> { | ||
let _ = fs::remove_dir_all(&self.config.dist_path); | ||
fs::create_dir_all(&self.config.dist_path).map_err(Error::CreateDistDir)?; | ||
|
||
let web_project_wasm_path = self.config.web_project_wasm_path(); | ||
let _ = fs::remove_dir_all(&web_project_wasm_path); | ||
fs::create_dir_all(&web_project_wasm_path).map_err(Error::CreateWebWasmDir)?; | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters