Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

chore: add description for FlowyConfig

appflowy16e1387a8e50
diff --git a/frontend/rust-lib/dart-ffi/Flowy.toml b/frontend/rust-lib/dart-ffi/Flowy.toml
index 979b0e48bf..47ee93d904 100644
--- a/frontend/rust-lib/dart-ffi/Flowy.toml
+++ b/frontend/rust-lib/dart-ffi/Flowy.toml
@@ -1,4 +1,4 @@
-proto_rust_file_input_dir = ["src/model"]
-proto_file_output_dir = "resources/proto"
-protobuf_crate_output_dir = "src/protobuf"
+proto_input = ["src/model"]
+#proto_output = "resources/proto"
+#protobuf_crate_path = "src/protobuf"
event_files = []
\ No newline at end of file
diff --git a/frontend/rust-lib/dart-notify/Flowy.toml b/frontend/rust-lib/dart-notify/Flowy.toml
index 2d16a3ac96..fd35d807ea 100644
--- a/frontend/rust-lib/dart-notify/Flowy.toml
+++ b/frontend/rust-lib/dart-notify/Flowy.toml
@@ -1,5 +1,5 @@
-proto_rust_file_input_dir = ["src/entities"]
-proto_file_output_dir = "resources/proto"
-protobuf_crate_output_dir = "src/protobuf"
+proto_input = ["src/entities"]
+proto_output = "resources/proto"
+protobuf_crate_path = "src/protobuf"
event_files = []
\ No newline at end of file
diff --git a/frontend/rust-lib/flowy-error/Flowy.toml b/frontend/rust-lib/flowy-error/Flowy.toml
index dbeabf92d6..8f8b6312e7 100644
--- a/frontend/rust-lib/flowy-error/Flowy.toml
+++ b/frontend/rust-lib/flowy-error/Flowy.toml
@@ -1,5 +1,5 @@
-proto_rust_file_input_dir = ["src/errors.rs",]
-proto_file_output_dir = "resources/proto"
-protobuf_crate_output_dir = "src/protobuf"
+proto_input = ["src/errors.rs",]
+proto_output = "resources/proto"
+protobuf_crate_path = "src/protobuf"
event_files = []
\ No newline at end of file
diff --git a/frontend/rust-lib/flowy-folder/Flowy.toml b/frontend/rust-lib/flowy-folder/Flowy.toml
index b14c511efe..373884561a 100644
--- a/frontend/rust-lib/flowy-folder/Flowy.toml
+++ b/frontend/rust-lib/flowy-folder/Flowy.toml
@@ -1,5 +1,5 @@
-proto_rust_file_input_dir = ["src/entities", "src/event_map.rs", "src/dart_notification.rs"]
-proto_file_output_dir = "resources/proto"
-protobuf_crate_output_dir = "src/protobuf"
+proto_input = ["src/entities", "src/event_map.rs", "src/dart_notification.rs"]
+proto_output = "resources/proto"
+protobuf_crate_path = "src/protobuf"
event_files = ["src/event_map.rs"]
\ No newline at end of file
diff --git a/frontend/rust-lib/flowy-grid/Flowy.toml b/frontend/rust-lib/flowy-grid/Flowy.toml
index ea075859bf..b4f2b865a5 100644
--- a/frontend/rust-lib/flowy-grid/Flowy.toml
+++ b/frontend/rust-lib/flowy-grid/Flowy.toml
@@ -1,9 +1,9 @@
-proto_rust_file_input_dir = [
+proto_input = [
"src/event_map.rs",
"src/services/field/type_options",
"src/entities",
"src/dart_notification.rs"
]
-proto_file_output_dir = "resources/proto"
-protobuf_crate_output_dir = "src/protobuf"
+proto_output = "resources/proto"
+protobuf_crate_path = "src/protobuf"
event_files = ["src/event_map.rs"]
\ No newline at end of file
diff --git a/frontend/rust-lib/flowy-net/Flowy.toml b/frontend/rust-lib/flowy-net/Flowy.toml
index 1f05f6069c..eae4b3bdf6 100644
--- a/frontend/rust-lib/flowy-net/Flowy.toml
+++ b/frontend/rust-lib/flowy-net/Flowy.toml
@@ -1,4 +1,4 @@
-proto_rust_file_input_dir = ["src/event_map.rs", "src/entities"]
-proto_file_output_dir = "resources/proto"
-protobuf_crate_output_dir = "src/protobuf"
+proto_input = ["src/event_map.rs", "src/entities"]
+proto_output = "resources/proto"
+protobuf_crate_path = "src/protobuf"
event_files = ["src/event_map.rs"]
\ No newline at end of file
diff --git a/frontend/rust-lib/flowy-text-block/Flowy.toml b/frontend/rust-lib/flowy-text-block/Flowy.toml
index 627bc5a069..a9ba87c567 100644
--- a/frontend/rust-lib/flowy-text-block/Flowy.toml
+++ b/frontend/rust-lib/flowy-text-block/Flowy.toml
@@ -1,5 +1,5 @@
-proto_rust_file_input_dir = ["src/event_map.rs", "src/entities.rs"]
-proto_file_output_dir = "resources/proto"
-protobuf_crate_output_dir = "src/protobuf"
+proto_input = ["src/event_map.rs", "src/entities.rs"]
+proto_output = "resources/proto"
+protobuf_crate_path = "src/protobuf"
event_files = ["src/event_map.rs"]
\ No newline at end of file
diff --git a/frontend/rust-lib/flowy-user/Flowy.toml b/frontend/rust-lib/flowy-user/Flowy.toml
index 1a6a7417c6..a66b5e214d 100644
--- a/frontend/rust-lib/flowy-user/Flowy.toml
+++ b/frontend/rust-lib/flowy-user/Flowy.toml
@@ -1,5 +1,5 @@
-proto_rust_file_input_dir = ["src/event_map.rs", "src/dart_notification.rs"]
-proto_file_output_dir = "resources/proto"
-protobuf_crate_output_dir = "src/protobuf"
+proto_input = ["src/event_map.rs", "src/dart_notification.rs"]
+proto_output = "resources/proto"
+protobuf_crate_path = "src/protobuf"
event_files = ["src/event_map.rs"]
\ No newline at end of file
diff --git a/shared-lib/flowy-error-code/Flowy.toml b/shared-lib/flowy-error-code/Flowy.toml
index e1780fda7c..30674e4364 100644
--- a/shared-lib/flowy-error-code/Flowy.toml
+++ b/shared-lib/flowy-error-code/Flowy.toml
@@ -1,5 +1,5 @@
-proto_rust_file_input_dir = ["src/code.rs"]
-proto_file_output_dir = "resources/proto"
-protobuf_crate_output_dir = "src/protobuf"
+proto_input = ["src/code.rs"]
+proto_output = "resources/proto"
+protobuf_crate_path = "src/protobuf"
event_files = []
\ No newline at end of file
diff --git a/shared-lib/flowy-folder-data-model/Flowy.toml b/shared-lib/flowy-folder-data-model/Flowy.toml
index 0a953766c4..8385068a56 100644
--- a/shared-lib/flowy-folder-data-model/Flowy.toml
+++ b/shared-lib/flowy-folder-data-model/Flowy.toml
@@ -1,5 +1,5 @@
-proto_rust_file_input_dir = ["src/entities",]
-proto_file_output_dir = "resources/proto"
-protobuf_crate_output_dir = "src/protobuf"
+proto_input = ["src/entities",]
+proto_output = "resources/proto"
+protobuf_crate_path = "src/protobuf"
event_files = []
\ No newline at end of file
diff --git a/shared-lib/flowy-grid-data-model/Flowy.toml b/shared-lib/flowy-grid-data-model/Flowy.toml
index 668c4bcd46..48e8084a60 100644
--- a/shared-lib/flowy-grid-data-model/Flowy.toml
+++ b/shared-lib/flowy-grid-data-model/Flowy.toml
@@ -1,5 +1,5 @@
-proto_rust_file_input_dir = ["src/entities/",]
-proto_file_output_dir = "resources/proto"
-protobuf_crate_output_dir = "src/protobuf"
+proto_input = ["src/entities/",]
+proto_output = "resources/proto"
+protobuf_crate_path = "src/protobuf"
event_files = []
\ No newline at end of file
diff --git a/shared-lib/flowy-sync/Flowy.toml b/shared-lib/flowy-sync/Flowy.toml
index 2d16a3ac96..fd35d807ea 100644
--- a/shared-lib/flowy-sync/Flowy.toml
+++ b/shared-lib/flowy-sync/Flowy.toml
@@ -1,5 +1,5 @@
-proto_rust_file_input_dir = ["src/entities"]
-proto_file_output_dir = "resources/proto"
-protobuf_crate_output_dir = "src/protobuf"
+proto_input = ["src/entities"]
+proto_output = "resources/proto"
+protobuf_crate_path = "src/protobuf"
event_files = []
\ No newline at end of file
diff --git a/shared-lib/flowy-user-data-model/Flowy.toml b/shared-lib/flowy-user-data-model/Flowy.toml
index d0cc72be93..0939516deb 100644
--- a/shared-lib/flowy-user-data-model/Flowy.toml
+++ b/shared-lib/flowy-user-data-model/Flowy.toml
@@ -1,5 +1,5 @@
-proto_rust_file_input_dir = ["src/entities", "src/errors.rs"]
-proto_file_output_dir = "resources/proto"
-protobuf_crate_output_dir = "src/protobuf"
+proto_input = ["src/entities", "src/errors.rs"]
+proto_output = "resources/proto"
+protobuf_crate_path = "src/protobuf"
event_files = []
\ No newline at end of file
diff --git a/shared-lib/lib-infra/src/code_gen/flowy_toml.rs b/shared-lib/lib-infra/src/code_gen/flowy_toml.rs
index 3bffa43d7c..af199d0f78 100644
--- a/shared-lib/lib-infra/src/code_gen/flowy_toml.rs
+++ b/shared-lib/lib-infra/src/code_gen/flowy_toml.rs
@@ -4,9 +4,24 @@ use std::path::{Path, PathBuf};
#[derive(serde::Deserialize, Clone, Debug)]
pub struct FlowyConfig {
pub event_files: Vec<String>,
- pub proto_rust_file_input_dir: Vec<String>,
- pub proto_file_output_dir: String,
- pub protobuf_crate_output_dir: String,
+ // Collect AST from the file or directory specified by proto_input to generate the proto files.
+ pub proto_input: Vec<String>,
+
+ // Output path for the generated proto files. The default value is default_proto_output()
+ #[serde(default = "default_proto_output")]
+ pub proto_output: String,
+
+ // 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,
+}
+
+fn default_proto_output() -> String {
+ "resources/proto".to_owned()
+}
+
+fn default_protobuf_crate() -> String {
+ "src/protobuf".to_owned()
}
impl FlowyConfig {
diff --git a/shared-lib/lib-infra/src/code_gen/protobuf_file/ast.rs b/shared-lib/lib-infra/src/code_gen/protobuf_file/ast.rs
index 9d52e17f63..de5538ea0a 100644
--- a/shared-lib/lib-infra/src/code_gen/protobuf_file/ast.rs
+++ b/shared-lib/lib-infra/src/code_gen/protobuf_file/ast.rs
@@ -18,11 +18,11 @@ pub fn parse_protobuf_context_from(crate_paths: Vec<String>) -> Vec<ProtobufCrat
let contexts = crate_infos
.into_iter()
.map(|crate_info| {
- let proto_output_dir = crate_info.proto_file_output_dir();
+ let proto_output_path = crate_info.proto_output_path();
let files = crate_info
- .proto_rust_file_paths()
+ .proto_input_paths()
.iter()
- .map(|proto_crate_path| parse_files_protobuf(proto_crate_path, &proto_output_dir))
+ .map(|proto_crate_path| parse_files_protobuf(proto_crate_path, &proto_output_path))
.flatten()
.collect::<Vec<ProtoFile>>();
@@ -33,7 +33,7 @@ pub fn parse_protobuf_context_from(crate_paths: Vec<String>) -> Vec<ProtobufCrat
contexts
}
-fn parse_files_protobuf(proto_crate_path: &Path, proto_output_dir: &Path) -> Vec<ProtoFile> {
+fn parse_files_protobuf(proto_crate_path: &Path, proto_output_path: &Path) -> Vec<ProtoFile> {
let mut gen_proto_vec: Vec<ProtoFile> = vec![];
// file_stem https://doc.rust-lang.org/std/path/struct.Path.html#method.file_stem
for (path, file_name) in WalkDir::new(proto_crate_path)
@@ -56,7 +56,7 @@ fn parse_files_protobuf(proto_crate_path: &Path, proto_output_dir: &Path) -> Vec
.unwrap_or_else(|_| panic!("Unable to parse file at {}", path));
let structs = get_ast_structs(&ast);
let proto_file = format!("{}.proto", &file_name);
- let proto_file_path = path_string_with_component(proto_output_dir, vec![&proto_file]);
+ let proto_file_path = path_string_with_component(proto_output_path, vec![&proto_file]);
let mut proto_file_content = find_proto_syntax(proto_file_path.as_ref());
structs.iter().for_each(|s| {
@@ -153,7 +153,7 @@ lazy_static! {
fn find_proto_syntax(path: &str) -> String {
if !Path::new(path).exists() {
- return String::from("syntax = \"proto3\";\\n");
+ return String::from("syntax = \"proto3\";\n\n");
}
let mut result = String::new();
diff --git a/shared-lib/lib-infra/src/code_gen/protobuf_file/mod.rs b/shared-lib/lib-infra/src/code_gen/protobuf_file/mod.rs
index 0280738899..3641b4729f 100644
--- a/shared-lib/lib-infra/src/code_gen/protobuf_file/mod.rs
+++ b/shared-lib/lib-infra/src/code_gen/protobuf_file/mod.rs
@@ -27,10 +27,10 @@ pub fn gen(crate_name: &str) {
for proto_crate in proto_crates {
let mut proto_file_paths = vec![];
let mut file_names = vec![];
- let proto_file_output_dir = proto_crate.proto_file_output_dir().to_str().unwrap().to_string();
- let protobuf_output_dir = proto_crate.protobuf_crate_path().to_str().unwrap().to_string();
+ let proto_file_output_path = proto_crate.proto_output_path().to_str().unwrap().to_string();
+ let protobuf_output_path = proto_crate.protobuf_crate_path().to_str().unwrap().to_string();
- for (path, file_name) in WalkDir::new(&proto_file_output_dir)
+ for (path, file_name) in WalkDir::new(&proto_file_output_path)
.into_iter()
.filter_map(|e| e.ok())
.map(|e| {
@@ -52,7 +52,7 @@ pub fn gen(crate_name: &str) {
#[cfg(feature = "dart")]
generate_dart_protobuf_files(
crate_name,
- &proto_file_output_dir,
+ &proto_file_output_path,
&proto_file_paths,
&file_names,
&protoc_bin_path,
@@ -62,8 +62,8 @@ pub fn gen(crate_name: &str) {
generate_rust_protobuf_files(
&protoc_bin_path,
&proto_file_paths,
- &proto_file_output_dir,
- &protobuf_output_dir,
+ &proto_file_output_path,
+ &protobuf_output_path,
);
}
}
@@ -71,14 +71,14 @@ pub fn gen(crate_name: &str) {
fn generate_rust_protobuf_files(
protoc_bin_path: &Path,
proto_file_paths: &[String],
- proto_file_output_dir: &str,
- protobuf_output_dir: &str,
+ proto_file_output_path: &str,
+ protobuf_output_path: &str,
) {
protoc_rust::Codegen::new()
- .out_dir(protobuf_output_dir)
+ .out_dir(protobuf_output_path)
.protoc_path(protoc_bin_path)
.inputs(proto_file_paths)
- .include(proto_file_output_dir)
+ .include(proto_file_output_path)
.run()
.expect("Running rust protoc failed.");
}
@@ -86,7 +86,7 @@ fn generate_rust_protobuf_files(
#[cfg(feature = "dart")]
fn generate_dart_protobuf_files(
name: &str,
- proto_file_output_dir: &str,
+ proto_file_output_path: &str,
paths: &Vec<String>,
file_names: &Vec<String>,
protoc_bin_path: &PathBuf,
@@ -115,7 +115,7 @@ fn generate_dart_protobuf_files(
let protoc_bin_path = protoc_bin_path.to_str().unwrap().to_owned();
paths.iter().for_each(|path| {
if cmd_lib::run_cmd! {
- ${protoc_bin_path} --dart_out=${output} --proto_path=${proto_file_output_dir} ${path}
+ ${protoc_bin_path} --dart_out=${output} --proto_path=${proto_file_output_path} ${path}
}
.is_err()
{
diff --git a/shared-lib/lib-infra/src/code_gen/protobuf_file/proto_gen.rs b/shared-lib/lib-infra/src/code_gen/protobuf_file/proto_gen.rs
index dda2b99b41..0c22ba7d1a 100644
--- a/shared-lib/lib-infra/src/code_gen/protobuf_file/proto_gen.rs
+++ b/shared-lib/lib-infra/src/code_gen/protobuf_file/proto_gen.rs
@@ -50,7 +50,7 @@ impl ProtoGenerator {
fn write_proto_files(crate_contexts: &[ProtobufCrateContext]) {
for context in crate_contexts {
- let dir = context.protobuf_crate.proto_file_output_dir();
+ let dir = context.protobuf_crate.proto_output_path();
context.files.iter().for_each(|info| {
let proto_file = format!("{}.proto", &info.file_name);
let proto_file_path = path_string_with_component(&dir, vec![&proto_file]);
@@ -75,7 +75,7 @@ fn write_rust_crate_mod_file(crate_contexts: &[ProtobufCrateContext]) {
mod_file_content.push_str("#![cfg_attr(rustfmt, rustfmt::skip)]\n");
mod_file_content.push_str("// Auto-generated, do not edit\n");
walk_dir(
- context.protobuf_crate.proto_file_output_dir(),
+ context.protobuf_crate.proto_output_path(),
|e| !e.file_type().is_dir(),
|_, name| {
let c = format!("\nmod {};\npub use {}::*;\n", &name, &name);
diff --git a/shared-lib/lib-infra/src/code_gen/protobuf_file/proto_info.rs b/shared-lib/lib-infra/src/code_gen/protobuf_file/proto_info.rs
index a3fa88142e..be2c8fdb38 100644
--- a/shared-lib/lib-infra/src/code_gen/protobuf_file/proto_info.rs
+++ b/shared-lib/lib-infra/src/code_gen/protobuf_file/proto_info.rs
@@ -73,22 +73,25 @@ impl ProtobufCrate {
}
}
- pub fn proto_rust_file_paths(&self) -> Vec<PathBuf> {
+ // Return the file paths for each rust file that used to generate the proto file.
+ pub fn proto_input_paths(&self) -> Vec<PathBuf> {
self.flowy_config
- .proto_rust_file_input_dir
+ .proto_input
.iter()
.map(|name| path_buf_with_component(&self.crate_path, vec![name]))
.collect::<Vec<PathBuf>>()
}
+ // The protobuf_crate_path is used to store the generated protobuf Rust structures.
pub fn protobuf_crate_path(&self) -> PathBuf {
- let crate_path = PathBuf::from(&self.flowy_config.protobuf_crate_output_dir);
+ let crate_path = PathBuf::from(&self.flowy_config.protobuf_crate_path);
create_dir_if_not_exist(&crate_path);
crate_path
}
- pub fn proto_file_output_dir(&self) -> PathBuf {
- let output_dir = PathBuf::from(&self.flowy_config.proto_file_output_dir);
+ // The proto_output_path is used to store the proto files
+ pub fn proto_output_path(&self) -> PathBuf {
+ let output_dir = PathBuf::from(&self.flowy_config.proto_output);
create_dir_if_not_exist(&output_dir);
output_dir
}
diff --git a/shared-lib/lib-ws/Flowy.toml b/shared-lib/lib-ws/Flowy.toml
index 377bd4f924..532d5fb239 100644
--- a/shared-lib/lib-ws/Flowy.toml
+++ b/shared-lib/lib-ws/Flowy.toml
@@ -1,4 +1,4 @@
-proto_rust_file_input_dir = ["src/errors.rs", "src/msg.rs"]
-proto_file_output_dir = "resources/proto"
-protobuf_crate_output_dir = "src/protobuf"
+proto_input = ["src/errors.rs", "src/msg.rs"]
+proto_output = "resources/proto"
+protobuf_crate_path = "src/protobuf"
event_files = []
\ No newline at end of file