-
Notifications
You must be signed in to change notification settings - Fork 88
/
build.rs
72 lines (62 loc) · 1.85 KB
/
build.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
68
69
70
71
72
use std::sync::Arc;
use crate::ext::compress;
use crate::{
compile,
compile::ChangeSet,
config::{Config, Project},
ext::{
anyhow::{anyhow, Context, Result},
fs,
},
};
pub async fn build_all(conf: &Config) -> Result<()> {
let mut first_failed_project = None;
for proj in &conf.projects {
log::debug!("Building project: {}, {}", proj.name, proj.working_dir);
if !build_proj(proj).await? && first_failed_project.is_none() {
first_failed_project = Some(proj);
}
}
if let Some(proj) = first_failed_project {
Err(anyhow!("Failed to build {}", proj.name))
} else {
Ok(())
}
}
/// Build the project. Returns true if the build was successful
pub async fn build_proj(proj: &Arc<Project>) -> Result<bool> {
if proj.site.root_dir.exists() {
fs::rm_dir_content(&proj.site.root_dir).await.dot()?;
}
let changes = ChangeSet::all_changes();
if !compile::front(proj, &changes).await.await??.is_success() {
return Ok(false);
}
if !compile::assets(proj, &changes, true)
.await
.await??
.is_success()
{
return Ok(false);
}
if !compile::style(proj, &changes).await.await??.is_success() {
return Ok(false);
}
// it is important to do the precompression of the static files before building the
// server to make it possible to include them as assets into the binary itself
if proj.release
&& proj.precompress
&& compress::compress_static_files(proj.site.root_dir.clone().into())
.await
.is_err()
{
return Ok(false);
}
if !compile::server(proj, &changes).await.await??.is_success() {
return Ok(false);
}
if proj.frontend_files_content_hashes {
compile::add_hashes_to_site(proj)?;
}
Ok(true)
}