forked from tauri-apps/cargo-mobile2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproject.rs
67 lines (64 loc) · 1.89 KB
/
project.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
use crate::{
bicycle, bossy,
config::Config,
templating::{self, FancyPackResolveError},
util::{
cli::{Report, Reportable},
Git,
},
};
use std::path::PathBuf;
#[derive(Debug)]
pub enum Error {
GitInitFailed(bossy::Error),
TemplatePackResolveFailed(FancyPackResolveError),
ProcessingFailed {
src: PathBuf,
dest: PathBuf,
cause: bicycle::ProcessingError,
},
}
impl Reportable for Error {
fn report(&self) -> Report {
match self {
Self::GitInitFailed(err) => Report::error("Failed to initialize git", err),
Self::TemplatePackResolveFailed(err) => {
Report::error("Failed to resolve template pack", err)
}
Self::ProcessingFailed { src, dest, cause } => Report::error(
format!(
"Base project template processing from src {:?} to dest {:?} failed",
src, dest,
),
cause,
),
}
}
}
pub fn gen(
config: &Config,
bike: &bicycle::Bicycle,
filter: &templating::Filter,
submodule_commit: Option<String>,
) -> Result<(), Error> {
println!("Generating base project...");
let root = config.app().root_dir();
let git = Git::new(&root);
git.init().map_err(Error::GitInitFailed)?;
let pack_chain = config
.app()
.template_pack()
.resolve(git, submodule_commit.as_deref())
.map_err(Error::TemplatePackResolveFailed)?;
log::info!("template pack chain: {:#?}", pack_chain);
for pack in pack_chain {
log::info!("traversing template pack {:#?}", pack);
bike.filter_and_process(&pack, &root, |_| (), filter.fun())
.map_err(|cause| Error::ProcessingFailed {
src: pack.to_owned(),
dest: root.to_owned(),
cause,
})?;
}
Ok(())
}