2022-02-09 01:57:03 +00:00
|
|
|
use std::fs;
|
2022-02-17 12:10:29 +00:00
|
|
|
use std::path::{Path, PathBuf};
|
2022-02-09 01:57:03 +00:00
|
|
|
|
2022-06-15 11:40:18 +00:00
|
|
|
#[derive(serde::Deserialize, Clone, Debug)]
|
2022-02-09 01:57:03 +00:00
|
|
|
pub struct FlowyConfig {
|
2023-02-13 01:29:49 +00:00
|
|
|
#[serde(default)]
|
|
|
|
pub event_files: Vec<String>,
|
2022-06-17 03:27:00 +00:00
|
|
|
|
2023-02-13 01:29:49 +00:00
|
|
|
// Collect AST from the file or directory specified by proto_input to generate the proto files.
|
|
|
|
#[serde(default)]
|
|
|
|
pub proto_input: Vec<String>,
|
2022-06-17 03:19:49 +00:00
|
|
|
|
2023-02-13 01:29:49 +00:00
|
|
|
// Output path for the generated proto files. The default value is default_proto_output()
|
|
|
|
#[serde(default = "default_proto_output")]
|
|
|
|
pub proto_output: String,
|
2022-06-17 03:19:49 +00:00
|
|
|
|
2023-02-13 01:29:49 +00:00
|
|
|
// Create a crate that stores the generated protobuf Rust structures. The default value is default_protobuf_crate()
|
|
|
|
#[serde(default = "default_protobuf_crate")]
|
|
|
|
pub protobuf_crate_path: String,
|
2022-06-17 03:19:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn default_proto_output() -> String {
|
2023-03-17 22:45:12 +00:00
|
|
|
let mut path = PathBuf::from("resources");
|
|
|
|
path.push("proto");
|
|
|
|
path.to_str().unwrap().to_owned()
|
2022-06-17 03:19:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn default_protobuf_crate() -> String {
|
2023-03-17 22:45:12 +00:00
|
|
|
let mut path = PathBuf::from("src");
|
|
|
|
path.push("protobuf");
|
|
|
|
path.to_str().unwrap().to_owned()
|
2022-02-09 01:57:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl FlowyConfig {
|
2023-02-13 01:29:49 +00:00
|
|
|
pub fn from_toml_file(path: &Path) -> Self {
|
|
|
|
let content = fs::read_to_string(path).unwrap();
|
|
|
|
let config: FlowyConfig = toml::from_str(content.as_ref()).unwrap();
|
|
|
|
config
|
|
|
|
}
|
2022-02-09 01:57:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct CrateConfig {
|
2023-02-13 01:29:49 +00:00
|
|
|
pub crate_path: PathBuf,
|
|
|
|
pub crate_folder: String,
|
|
|
|
pub flowy_config: FlowyConfig,
|
2022-02-09 01:57:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn parse_crate_config_from(entry: &walkdir::DirEntry) -> Option<CrateConfig> {
|
2023-02-13 01:29:49 +00:00
|
|
|
let mut config_path = entry.path().parent().unwrap().to_path_buf();
|
|
|
|
config_path.push("Flowy.toml");
|
|
|
|
if !config_path.as_path().exists() {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
let crate_path = entry.path().parent().unwrap().to_path_buf();
|
|
|
|
let flowy_config = FlowyConfig::from_toml_file(config_path.as_path());
|
|
|
|
let crate_folder = crate_path
|
|
|
|
.file_stem()
|
|
|
|
.unwrap()
|
|
|
|
.to_str()
|
|
|
|
.unwrap()
|
|
|
|
.to_string();
|
|
|
|
|
|
|
|
Some(CrateConfig {
|
|
|
|
crate_path,
|
|
|
|
crate_folder,
|
|
|
|
flowy_config,
|
|
|
|
})
|
2022-02-09 01:57:03 +00:00
|
|
|
}
|