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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#![doc = include_str!("../README.proj.md")]
#![deny(missing_docs)]
mod build;
mod cmd;
mod deploy;
pub mod errors;
mod export;
mod export_error_page;
mod init;
mod install;
pub mod parse;
mod prepare;
mod reload_server;
mod serve;
mod serve_exported;
mod snoop;
mod thread;
mod tinker;
use errors::*;
use std::path::PathBuf;
use std::{fs, path::Path};
pub const PERSEUS_VERSION: &str = env!("CARGO_PKG_VERSION");
pub use build::build;
pub use deploy::deploy;
pub use export::export;
pub use export_error_page::export_error_page;
pub use init::{init, new};
pub use install::{get_tools_dir, Tools};
pub use prepare::check_env;
pub use reload_server::{order_reload, run_reload_server};
pub use serve::serve;
pub use serve_exported::serve_exported;
pub use snoop::{snoop_build, snoop_server, snoop_wasm_build};
pub use tinker::tinker;
pub fn create_dist(dir: &Path) -> Result<(), ExecutionError> {
let target = dir.join("dist");
if !target.exists() {
fs::create_dir(target).map_err(|err| ExecutionError::CreateDistFailed { source: err })?;
}
Ok(())
}
pub fn delete_dist(dir: PathBuf) -> Result<(), ExecutionError> {
let target = dir.join("dist");
if target.exists() {
if let Err(err) = fs::remove_dir_all(&target) {
return Err(ExecutionError::RemoveArtifactsFailed {
target: target.to_str().map(|s| s.to_string()),
source: err,
});
}
}
Ok(())
}
pub fn delete_artifacts(dir: PathBuf, dir_to_remove: &str) -> Result<(), ExecutionError> {
let mut target = dir;
target.extend(["dist", dir_to_remove]);
if target.exists() {
if let Err(err) = fs::remove_dir_all(&target) {
return Err(ExecutionError::RemoveArtifactsFailed {
target: target.to_str().map(|s| s.to_string()),
source: err,
});
}
}
if let Err(err) = fs::create_dir_all(&target) {
return Err(ExecutionError::RemoveArtifactsFailed {
target: target.to_str().map(|s| s.to_string()),
source: err,
});
}
Ok(())
}
pub fn get_user_crate_name(dir: &Path) -> Result<String, ExecutionError> {
let manifest = cargo_toml::Manifest::from_path(dir.join("Cargo.toml"))
.map_err(|err| ExecutionError::GetManifestFailed { source: err })?;
let name = manifest
.package
.ok_or(ExecutionError::CrateNameNotPresentInManifest)?
.name;
Ok(name)
}