|
@@ -1,45 +1,15 @@
|
|
|
-use crate::config::FlowyConfig;
|
|
|
-use crate::proto::helper::*;
|
|
|
+use crate::util::*;
|
|
|
use std::fs::OpenOptions;
|
|
|
use std::io::Write;
|
|
|
use walkdir::WalkDir;
|
|
|
|
|
|
-#[derive(Clone)]
|
|
|
-pub struct CrateInfo {
|
|
|
- pub crate_folder_name: String,
|
|
|
- pub proto_crate_paths: Vec<String>,
|
|
|
- pub crate_path: String,
|
|
|
-}
|
|
|
-
|
|
|
pub struct CrateProtoInfo {
|
|
|
- pub files: Vec<FileProtoInfo>,
|
|
|
- pub inner: CrateInfo,
|
|
|
-}
|
|
|
-
|
|
|
-impl CrateInfo {
|
|
|
- fn protobuf_crate_name(&self) -> String {
|
|
|
- format!("{}/src/protobuf", self.crate_path)
|
|
|
- }
|
|
|
-
|
|
|
- pub fn proto_file_output_dir(&self) -> String {
|
|
|
- let dir = format!("{}/proto", self.protobuf_crate_name());
|
|
|
- create_dir_if_not_exist(dir.as_ref());
|
|
|
- dir
|
|
|
- }
|
|
|
-
|
|
|
- pub fn proto_struct_output_dir(&self) -> String {
|
|
|
- let dir = format!("{}/model", self.protobuf_crate_name());
|
|
|
- create_dir_if_not_exist(dir.as_ref());
|
|
|
- dir
|
|
|
- }
|
|
|
-
|
|
|
- pub fn proto_model_mod_file(&self) -> String {
|
|
|
- format!("{}/mod.rs", self.proto_struct_output_dir())
|
|
|
- }
|
|
|
+ pub files: Vec<ProtoFile>,
|
|
|
+ pub inner: ProtobufCrate,
|
|
|
}
|
|
|
|
|
|
impl CrateProtoInfo {
|
|
|
- pub fn from_crate_info(inner: CrateInfo, files: Vec<FileProtoInfo>) -> Self {
|
|
|
+ pub fn from_crate_info(inner: ProtobufCrate, files: Vec<ProtoFile>) -> Self {
|
|
|
Self { files, inner }
|
|
|
}
|
|
|
|
|
@@ -68,45 +38,61 @@ pub use model::*;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+#[derive(Clone, Debug)]
|
|
|
+pub struct ProtobufCrate {
|
|
|
+ pub folder_name: String,
|
|
|
+ pub proto_paths: Vec<String>,
|
|
|
+ pub crate_path: String,
|
|
|
+}
|
|
|
+
|
|
|
+impl ProtobufCrate {
|
|
|
+ pub fn from_config(config: CrateConfig) -> Self {
|
|
|
+ let proto_paths = config.proto_paths();
|
|
|
+ ProtobufCrate {
|
|
|
+ folder_name: config.folder_name,
|
|
|
+ proto_paths,
|
|
|
+ crate_path: config.crate_path,
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ fn protobuf_crate_name(&self) -> String {
|
|
|
+ format!("{}/src/protobuf", self.crate_path)
|
|
|
+ }
|
|
|
+
|
|
|
+ pub fn proto_file_output_dir(&self) -> String {
|
|
|
+ let dir = format!("{}/proto", self.protobuf_crate_name());
|
|
|
+ create_dir_if_not_exist(dir.as_ref());
|
|
|
+ dir
|
|
|
+ }
|
|
|
+
|
|
|
+ pub fn proto_struct_output_dir(&self) -> String {
|
|
|
+ let dir = format!("{}/model", self.protobuf_crate_name());
|
|
|
+ create_dir_if_not_exist(dir.as_ref());
|
|
|
+ dir
|
|
|
+ }
|
|
|
+
|
|
|
+ pub fn proto_model_mod_file(&self) -> String {
|
|
|
+ format!("{}/mod.rs", self.proto_struct_output_dir())
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
#[derive(Debug)]
|
|
|
-pub struct FileProtoInfo {
|
|
|
+pub struct ProtoFile {
|
|
|
pub file_name: String,
|
|
|
pub structs: Vec<String>,
|
|
|
pub enums: Vec<String>,
|
|
|
pub generated_content: String,
|
|
|
}
|
|
|
|
|
|
-pub fn parse_crate_info_from_path(root: &str) -> Vec<CrateInfo> {
|
|
|
+pub fn parse_crate_info_from_path(root: &str) -> Vec<ProtobufCrate> {
|
|
|
WalkDir::new(root)
|
|
|
.into_iter()
|
|
|
.filter_entry(|e| !is_hidden(e))
|
|
|
.filter_map(|e| e.ok())
|
|
|
.filter(|e| is_crate_dir(e))
|
|
|
- .flat_map(|e| {
|
|
|
- // Assert e.path().parent() will be the crate dir
|
|
|
- let path = e.path().parent().unwrap();
|
|
|
- let crate_path = path.to_str().unwrap().to_string();
|
|
|
- let crate_folder_name = path.file_stem().unwrap().to_str().unwrap().to_string();
|
|
|
- let flowy_config_file = format!("{}/Flowy.toml", crate_path);
|
|
|
-
|
|
|
- if std::path::Path::new(&flowy_config_file).exists() {
|
|
|
- let config = FlowyConfig::from_toml_file(flowy_config_file.as_ref());
|
|
|
- let crate_path = path.to_str().unwrap().to_string();
|
|
|
- let proto_crate_paths = config
|
|
|
- .proto_crates
|
|
|
- .iter()
|
|
|
- .map(|name| format!("{}/{}", crate_path, name))
|
|
|
- .collect::<Vec<String>>();
|
|
|
- Some(CrateInfo {
|
|
|
- crate_folder_name,
|
|
|
- proto_crate_paths,
|
|
|
- crate_path,
|
|
|
- })
|
|
|
- } else {
|
|
|
- None
|
|
|
- }
|
|
|
- })
|
|
|
- .collect::<Vec<CrateInfo>>()
|
|
|
+ .flat_map(|e| parse_crate_config_from(&e))
|
|
|
+ .map(|crate_config| ProtobufCrate::from_config(crate_config))
|
|
|
+ .collect::<Vec<ProtobufCrate>>()
|
|
|
}
|
|
|
|
|
|
pub struct FlutterProtobufInfo {
|