diff --git a/frontend/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user-data-model/protobuf.dart b/frontend/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user-data-model/protobuf.dart index 61ea505de9..3c6a1c28fa 100644 --- a/frontend/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user-data-model/protobuf.dart +++ b/frontend/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user-data-model/protobuf.dart @@ -1,5 +1,4 @@ // Auto-generated, do not edit -export './errors.pb.dart'; export './user_profile.pb.dart'; export './auth.pb.dart'; export './user_setting.pb.dart'; diff --git a/frontend/rust-lib/dart-ffi/Flowy.toml b/frontend/rust-lib/dart-ffi/Flowy.toml index 41fea48238..07d2554915 100644 --- a/frontend/rust-lib/dart-ffi/Flowy.toml +++ b/frontend/rust-lib/dart-ffi/Flowy.toml @@ -1,2 +1,4 @@ proto_crates = ["src/model"] +proto_output_dir = "resources/proto" +protobuf_crate_path = "src/protobuf" event_files = [] \ No newline at end of file diff --git a/frontend/rust-lib/dart-ffi/build.rs b/frontend/rust-lib/dart-ffi/build.rs index 7f06ab48c8..e897c3690d 100644 --- a/frontend/rust-lib/dart-ffi/build.rs +++ b/frontend/rust-lib/dart-ffi/build.rs @@ -1,5 +1,5 @@ use lib_infra::code_gen; fn main() { - code_gen::protobuf_file::gen(env!("CARGO_PKG_NAME"), "./src/protobuf/proto"); + code_gen::protobuf_file::gen(env!("CARGO_PKG_NAME")); } diff --git a/frontend/rust-lib/dart-ffi/src/protobuf/proto/ffi_request.proto b/frontend/rust-lib/dart-ffi/resources/proto/ffi_request.proto similarity index 100% rename from frontend/rust-lib/dart-ffi/src/protobuf/proto/ffi_request.proto rename to frontend/rust-lib/dart-ffi/resources/proto/ffi_request.proto diff --git a/frontend/rust-lib/dart-ffi/src/protobuf/proto/ffi_response.proto b/frontend/rust-lib/dart-ffi/resources/proto/ffi_response.proto similarity index 100% rename from frontend/rust-lib/dart-ffi/src/protobuf/proto/ffi_response.proto rename to frontend/rust-lib/dart-ffi/resources/proto/ffi_response.proto diff --git a/frontend/rust-lib/dart-notify/Flowy.toml b/frontend/rust-lib/dart-notify/Flowy.toml index 33b1c193f2..963226777d 100644 --- a/frontend/rust-lib/dart-notify/Flowy.toml +++ b/frontend/rust-lib/dart-notify/Flowy.toml @@ -1,3 +1,5 @@ proto_crates = ["src/entities"] +proto_output_dir = "resources/proto" +protobuf_crate_path = "src/protobuf" event_files = [] \ No newline at end of file diff --git a/frontend/rust-lib/dart-notify/build.rs b/frontend/rust-lib/dart-notify/build.rs index 7f06ab48c8..e897c3690d 100644 --- a/frontend/rust-lib/dart-notify/build.rs +++ b/frontend/rust-lib/dart-notify/build.rs @@ -1,5 +1,5 @@ use lib_infra::code_gen; fn main() { - code_gen::protobuf_file::gen(env!("CARGO_PKG_NAME"), "./src/protobuf/proto"); + code_gen::protobuf_file::gen(env!("CARGO_PKG_NAME")); } diff --git a/frontend/rust-lib/dart-notify/src/protobuf/proto/subject.proto b/frontend/rust-lib/dart-notify/resources/proto/subject.proto similarity index 100% rename from frontend/rust-lib/dart-notify/src/protobuf/proto/subject.proto rename to frontend/rust-lib/dart-notify/resources/proto/subject.proto diff --git a/frontend/rust-lib/flowy-error/Flowy.toml b/frontend/rust-lib/flowy-error/Flowy.toml index 1c5d489f5b..d8028ce8cd 100644 --- a/frontend/rust-lib/flowy-error/Flowy.toml +++ b/frontend/rust-lib/flowy-error/Flowy.toml @@ -1,3 +1,5 @@ proto_crates = ["src/errors.rs",] +proto_output_dir = "resources/proto" +protobuf_crate_path = "src/protobuf" event_files = [] \ No newline at end of file diff --git a/frontend/rust-lib/flowy-error/build.rs b/frontend/rust-lib/flowy-error/build.rs index 1556b7749f..c674f76a4f 100644 --- a/frontend/rust-lib/flowy-error/build.rs +++ b/frontend/rust-lib/flowy-error/build.rs @@ -1,5 +1,5 @@ use lib_infra::code_gen; fn main() { - code_gen::protobuf_file::gen("flowy-error", "./src/protobuf/proto"); + code_gen::protobuf_file::gen("flowy-error"); } diff --git a/frontend/rust-lib/flowy-error/src/protobuf/proto/errors.proto b/frontend/rust-lib/flowy-error/resources/proto/errors.proto similarity index 100% rename from frontend/rust-lib/flowy-error/src/protobuf/proto/errors.proto rename to frontend/rust-lib/flowy-error/resources/proto/errors.proto diff --git a/frontend/rust-lib/flowy-folder/Flowy.toml b/frontend/rust-lib/flowy-folder/Flowy.toml index e589605a15..709d3dad0b 100644 --- a/frontend/rust-lib/flowy-folder/Flowy.toml +++ b/frontend/rust-lib/flowy-folder/Flowy.toml @@ -1,3 +1,5 @@ proto_crates = ["src/entities", "src/event_map.rs", "src/dart_notification.rs"] +proto_output_dir = "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-folder/build.rs b/frontend/rust-lib/flowy-folder/build.rs index 4d4d3b13da..b5514a7944 100644 --- a/frontend/rust-lib/flowy-folder/build.rs +++ b/frontend/rust-lib/flowy-folder/build.rs @@ -2,7 +2,7 @@ use lib_infra::code_gen; fn main() { let crate_name = env!("CARGO_PKG_NAME"); - code_gen::protobuf_file::gen(crate_name, "./src/protobuf/proto"); + code_gen::protobuf_file::gen(crate_name); #[cfg(feature = "dart")] code_gen::dart_event::gen(crate_name); diff --git a/frontend/rust-lib/flowy-folder/src/protobuf/proto/dart_notification.proto b/frontend/rust-lib/flowy-folder/resources/proto/dart_notification.proto similarity index 100% rename from frontend/rust-lib/flowy-folder/src/protobuf/proto/dart_notification.proto rename to frontend/rust-lib/flowy-folder/resources/proto/dart_notification.proto diff --git a/frontend/rust-lib/flowy-folder/src/protobuf/proto/event_map.proto b/frontend/rust-lib/flowy-folder/resources/proto/event_map.proto similarity index 100% rename from frontend/rust-lib/flowy-folder/src/protobuf/proto/event_map.proto rename to frontend/rust-lib/flowy-folder/resources/proto/event_map.proto diff --git a/frontend/rust-lib/flowy-grid/Flowy.toml b/frontend/rust-lib/flowy-grid/Flowy.toml index 835988d41e..f23613073f 100644 --- a/frontend/rust-lib/flowy-grid/Flowy.toml +++ b/frontend/rust-lib/flowy-grid/Flowy.toml @@ -1,8 +1,9 @@ - proto_crates = [ "src/event_map.rs", "src/services/field/type_options", "src/entities", "src/dart_notification.rs" ] +proto_output_dir = "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/build.rs b/frontend/rust-lib/flowy-grid/build.rs index 4d4d3b13da..b5514a7944 100644 --- a/frontend/rust-lib/flowy-grid/build.rs +++ b/frontend/rust-lib/flowy-grid/build.rs @@ -2,7 +2,7 @@ use lib_infra::code_gen; fn main() { let crate_name = env!("CARGO_PKG_NAME"); - code_gen::protobuf_file::gen(crate_name, "./src/protobuf/proto"); + code_gen::protobuf_file::gen(crate_name); #[cfg(feature = "dart")] code_gen::dart_event::gen(crate_name); diff --git a/frontend/rust-lib/flowy-grid/src/protobuf/proto/cell_entities.proto b/frontend/rust-lib/flowy-grid/resources/proto/cell_entities.proto similarity index 100% rename from frontend/rust-lib/flowy-grid/src/protobuf/proto/cell_entities.proto rename to frontend/rust-lib/flowy-grid/resources/proto/cell_entities.proto diff --git a/frontend/rust-lib/flowy-grid/src/protobuf/proto/checkbox_type_option.proto b/frontend/rust-lib/flowy-grid/resources/proto/checkbox_type_option.proto similarity index 100% rename from frontend/rust-lib/flowy-grid/src/protobuf/proto/checkbox_type_option.proto rename to frontend/rust-lib/flowy-grid/resources/proto/checkbox_type_option.proto diff --git a/frontend/rust-lib/flowy-grid/src/protobuf/proto/dart_notification.proto b/frontend/rust-lib/flowy-grid/resources/proto/dart_notification.proto similarity index 100% rename from frontend/rust-lib/flowy-grid/src/protobuf/proto/dart_notification.proto rename to frontend/rust-lib/flowy-grid/resources/proto/dart_notification.proto diff --git a/frontend/rust-lib/flowy-grid/src/protobuf/proto/date_type_option.proto b/frontend/rust-lib/flowy-grid/resources/proto/date_type_option.proto similarity index 100% rename from frontend/rust-lib/flowy-grid/src/protobuf/proto/date_type_option.proto rename to frontend/rust-lib/flowy-grid/resources/proto/date_type_option.proto diff --git a/frontend/rust-lib/flowy-grid/src/protobuf/proto/event_map.proto b/frontend/rust-lib/flowy-grid/resources/proto/event_map.proto similarity index 100% rename from frontend/rust-lib/flowy-grid/src/protobuf/proto/event_map.proto rename to frontend/rust-lib/flowy-grid/resources/proto/event_map.proto diff --git a/frontend/rust-lib/flowy-grid/src/protobuf/proto/field_entities.proto b/frontend/rust-lib/flowy-grid/resources/proto/field_entities.proto similarity index 100% rename from frontend/rust-lib/flowy-grid/src/protobuf/proto/field_entities.proto rename to frontend/rust-lib/flowy-grid/resources/proto/field_entities.proto diff --git a/frontend/rust-lib/flowy-grid/src/protobuf/proto/format.proto b/frontend/rust-lib/flowy-grid/resources/proto/format.proto similarity index 100% rename from frontend/rust-lib/flowy-grid/src/protobuf/proto/format.proto rename to frontend/rust-lib/flowy-grid/resources/proto/format.proto diff --git a/frontend/rust-lib/flowy-grid/src/protobuf/proto/number_type_option.proto b/frontend/rust-lib/flowy-grid/resources/proto/number_type_option.proto similarity index 100% rename from frontend/rust-lib/flowy-grid/src/protobuf/proto/number_type_option.proto rename to frontend/rust-lib/flowy-grid/resources/proto/number_type_option.proto diff --git a/frontend/rust-lib/flowy-grid/src/protobuf/proto/row_entities.proto b/frontend/rust-lib/flowy-grid/resources/proto/row_entities.proto similarity index 100% rename from frontend/rust-lib/flowy-grid/src/protobuf/proto/row_entities.proto rename to frontend/rust-lib/flowy-grid/resources/proto/row_entities.proto diff --git a/frontend/rust-lib/flowy-grid/src/protobuf/proto/selection_type_option.proto b/frontend/rust-lib/flowy-grid/resources/proto/selection_type_option.proto similarity index 100% rename from frontend/rust-lib/flowy-grid/src/protobuf/proto/selection_type_option.proto rename to frontend/rust-lib/flowy-grid/resources/proto/selection_type_option.proto diff --git a/frontend/rust-lib/flowy-grid/src/protobuf/proto/text_type_option.proto b/frontend/rust-lib/flowy-grid/resources/proto/text_type_option.proto similarity index 100% rename from frontend/rust-lib/flowy-grid/src/protobuf/proto/text_type_option.proto rename to frontend/rust-lib/flowy-grid/resources/proto/text_type_option.proto diff --git a/frontend/rust-lib/flowy-grid/src/protobuf/proto/url_type_option.proto b/frontend/rust-lib/flowy-grid/resources/proto/url_type_option.proto similarity index 100% rename from frontend/rust-lib/flowy-grid/src/protobuf/proto/url_type_option.proto rename to frontend/rust-lib/flowy-grid/resources/proto/url_type_option.proto diff --git a/frontend/rust-lib/flowy-net/Flowy.toml b/frontend/rust-lib/flowy-net/Flowy.toml index 055287f500..4689103236 100644 --- a/frontend/rust-lib/flowy-net/Flowy.toml +++ b/frontend/rust-lib/flowy-net/Flowy.toml @@ -1,2 +1,4 @@ proto_crates = ["src/event_map.rs", "src/entities"] +proto_output_dir = "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/build.rs b/frontend/rust-lib/flowy-net/build.rs index 4d4d3b13da..b5514a7944 100644 --- a/frontend/rust-lib/flowy-net/build.rs +++ b/frontend/rust-lib/flowy-net/build.rs @@ -2,7 +2,7 @@ use lib_infra::code_gen; fn main() { let crate_name = env!("CARGO_PKG_NAME"); - code_gen::protobuf_file::gen(crate_name, "./src/protobuf/proto"); + code_gen::protobuf_file::gen(crate_name); #[cfg(feature = "dart")] code_gen::dart_event::gen(crate_name); diff --git a/frontend/rust-lib/flowy-net/src/protobuf/proto/event_map.proto b/frontend/rust-lib/flowy-net/resources/proto/event_map.proto similarity index 100% rename from frontend/rust-lib/flowy-net/src/protobuf/proto/event_map.proto rename to frontend/rust-lib/flowy-net/resources/proto/event_map.proto diff --git a/frontend/rust-lib/flowy-net/src/protobuf/proto/network_state.proto b/frontend/rust-lib/flowy-net/resources/proto/network_state.proto similarity index 100% rename from frontend/rust-lib/flowy-net/src/protobuf/proto/network_state.proto rename to frontend/rust-lib/flowy-net/resources/proto/network_state.proto diff --git a/frontend/rust-lib/flowy-text-block/Flowy.toml b/frontend/rust-lib/flowy-text-block/Flowy.toml index e6a5c4bd8f..45ca0081c5 100644 --- a/frontend/rust-lib/flowy-text-block/Flowy.toml +++ b/frontend/rust-lib/flowy-text-block/Flowy.toml @@ -1,3 +1,5 @@ proto_crates = ["src/event_map.rs", "src/entities.rs"] +proto_output_dir = "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/build.rs b/frontend/rust-lib/flowy-text-block/build.rs index 4d4d3b13da..b5514a7944 100644 --- a/frontend/rust-lib/flowy-text-block/build.rs +++ b/frontend/rust-lib/flowy-text-block/build.rs @@ -2,7 +2,7 @@ use lib_infra::code_gen; fn main() { let crate_name = env!("CARGO_PKG_NAME"); - code_gen::protobuf_file::gen(crate_name, "./src/protobuf/proto"); + code_gen::protobuf_file::gen(crate_name); #[cfg(feature = "dart")] code_gen::dart_event::gen(crate_name); diff --git a/frontend/rust-lib/flowy-text-block/src/protobuf/proto/entities.proto b/frontend/rust-lib/flowy-text-block/resources/proto/entities.proto similarity index 100% rename from frontend/rust-lib/flowy-text-block/src/protobuf/proto/entities.proto rename to frontend/rust-lib/flowy-text-block/resources/proto/entities.proto diff --git a/frontend/rust-lib/flowy-text-block/src/protobuf/proto/event_map.proto b/frontend/rust-lib/flowy-text-block/resources/proto/event_map.proto similarity index 100% rename from frontend/rust-lib/flowy-text-block/src/protobuf/proto/event_map.proto rename to frontend/rust-lib/flowy-text-block/resources/proto/event_map.proto diff --git a/frontend/rust-lib/flowy-user/Flowy.toml b/frontend/rust-lib/flowy-user/Flowy.toml index d080fa526c..9704193feb 100644 --- a/frontend/rust-lib/flowy-user/Flowy.toml +++ b/frontend/rust-lib/flowy-user/Flowy.toml @@ -1,3 +1,5 @@ proto_crates = ["src/event_map.rs", "src/dart_notification.rs"] +proto_output_dir = "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/build.rs b/frontend/rust-lib/flowy-user/build.rs index 4d4d3b13da..b5514a7944 100644 --- a/frontend/rust-lib/flowy-user/build.rs +++ b/frontend/rust-lib/flowy-user/build.rs @@ -2,7 +2,7 @@ use lib_infra::code_gen; fn main() { let crate_name = env!("CARGO_PKG_NAME"); - code_gen::protobuf_file::gen(crate_name, "./src/protobuf/proto"); + code_gen::protobuf_file::gen(crate_name); #[cfg(feature = "dart")] code_gen::dart_event::gen(crate_name); diff --git a/frontend/rust-lib/flowy-user/src/protobuf/proto/dart_notification.proto b/frontend/rust-lib/flowy-user/resources/proto/dart_notification.proto similarity index 100% rename from frontend/rust-lib/flowy-user/src/protobuf/proto/dart_notification.proto rename to frontend/rust-lib/flowy-user/resources/proto/dart_notification.proto diff --git a/frontend/rust-lib/flowy-user/src/protobuf/proto/event_map.proto b/frontend/rust-lib/flowy-user/resources/proto/event_map.proto similarity index 100% rename from frontend/rust-lib/flowy-user/src/protobuf/proto/event_map.proto rename to frontend/rust-lib/flowy-user/resources/proto/event_map.proto diff --git a/shared-lib/flowy-user-data-model/src/protobuf/document b/shared-lib/flowy-error-code/.proto/mod.rs similarity index 100% rename from shared-lib/flowy-user-data-model/src/protobuf/document rename to shared-lib/flowy-error-code/.proto/mod.rs diff --git a/shared-lib/flowy-error-code/.proto/model/mod.rs b/shared-lib/flowy-error-code/.proto/model/mod.rs new file mode 100644 index 0000000000..191b80e077 --- /dev/null +++ b/shared-lib/flowy-error-code/.proto/model/mod.rs @@ -0,0 +1,5 @@ +#![cfg_attr(rustfmt, rustfmt::skip)] +// Auto-generated, do not edit + +mod code; +pub use code::*; diff --git a/shared-lib/flowy-error-code/.proto/proto/code.proto b/shared-lib/flowy-error-code/.proto/proto/code.proto new file mode 100644 index 0000000000..ede9b65657 --- /dev/null +++ b/shared-lib/flowy-error-code/.proto/proto/code.proto @@ -0,0 +1,48 @@ +syntax = "proto3"; +enum ErrorCode { + Internal = 0; + UserUnauthorized = 2; + RecordNotFound = 3; + UserIdIsEmpty = 4; + WorkspaceNameInvalid = 100; + WorkspaceIdInvalid = 101; + AppColorStyleInvalid = 102; + WorkspaceDescTooLong = 103; + WorkspaceNameTooLong = 104; + AppIdInvalid = 110; + AppNameInvalid = 111; + ViewNameInvalid = 120; + ViewThumbnailInvalid = 121; + ViewIdInvalid = 122; + ViewDescTooLong = 123; + ViewDataInvalid = 124; + ViewNameTooLong = 125; + ConnectError = 200; + EmailIsEmpty = 300; + EmailFormatInvalid = 301; + EmailAlreadyExists = 302; + PasswordIsEmpty = 303; + PasswordTooLong = 304; + PasswordContainsForbidCharacters = 305; + PasswordFormatInvalid = 306; + PasswordNotMatch = 307; + UserNameTooLong = 308; + UserNameContainForbiddenCharacters = 309; + UserNameIsEmpty = 310; + UserIdInvalid = 311; + UserNotExist = 312; + TextTooLong = 400; + GridIdIsEmpty = 410; + BlockIdIsEmpty = 420; + RowIdIsEmpty = 430; + OptionIdIsEmpty = 431; + FieldIdIsEmpty = 440; + FieldDoesNotExist = 441; + SelectOptionNameIsEmpty = 442; + FieldNotExists = 443; + FieldInvalidOperation = 444; + TypeOptionDataIsEmpty = 450; + InvalidDateTimeFormat = 500; + UnexpectedEmptyString = 999; + InvalidData = 1000; +} diff --git a/shared-lib/flowy-error-code/Flowy.toml b/shared-lib/flowy-error-code/Flowy.toml index 7d6706b430..6e11937930 100644 --- a/shared-lib/flowy-error-code/Flowy.toml +++ b/shared-lib/flowy-error-code/Flowy.toml @@ -1,3 +1,5 @@ proto_crates = ["src/code.rs"] +proto_output_dir = "resources/proto" +protobuf_crate_path = "src/protobuf" event_files = [] \ No newline at end of file diff --git a/shared-lib/flowy-error-code/build.rs b/shared-lib/flowy-error-code/build.rs index 7f06ab48c8..e897c3690d 100644 --- a/shared-lib/flowy-error-code/build.rs +++ b/shared-lib/flowy-error-code/build.rs @@ -1,5 +1,5 @@ use lib_infra::code_gen; fn main() { - code_gen::protobuf_file::gen(env!("CARGO_PKG_NAME"), "./src/protobuf/proto"); + code_gen::protobuf_file::gen(env!("CARGO_PKG_NAME")); } diff --git a/shared-lib/flowy-error-code/src/protobuf/proto/code.proto b/shared-lib/flowy-error-code/resources/proto/code.proto similarity index 100% rename from shared-lib/flowy-error-code/src/protobuf/proto/code.proto rename to shared-lib/flowy-error-code/resources/proto/code.proto diff --git a/shared-lib/lib-ws/src/protobuf/document b/shared-lib/flowy-error-code/src/assets/mod.rs similarity index 100% rename from shared-lib/lib-ws/src/protobuf/document rename to shared-lib/flowy-error-code/src/assets/mod.rs diff --git a/shared-lib/flowy-error-code/src/assets/model/mod.rs b/shared-lib/flowy-error-code/src/assets/model/mod.rs new file mode 100644 index 0000000000..191b80e077 --- /dev/null +++ b/shared-lib/flowy-error-code/src/assets/model/mod.rs @@ -0,0 +1,5 @@ +#![cfg_attr(rustfmt, rustfmt::skip)] +// Auto-generated, do not edit + +mod code; +pub use code::*; diff --git a/shared-lib/flowy-error-code/src/assets/proto/code.proto b/shared-lib/flowy-error-code/src/assets/proto/code.proto new file mode 100644 index 0000000000..ede9b65657 --- /dev/null +++ b/shared-lib/flowy-error-code/src/assets/proto/code.proto @@ -0,0 +1,48 @@ +syntax = "proto3"; +enum ErrorCode { + Internal = 0; + UserUnauthorized = 2; + RecordNotFound = 3; + UserIdIsEmpty = 4; + WorkspaceNameInvalid = 100; + WorkspaceIdInvalid = 101; + AppColorStyleInvalid = 102; + WorkspaceDescTooLong = 103; + WorkspaceNameTooLong = 104; + AppIdInvalid = 110; + AppNameInvalid = 111; + ViewNameInvalid = 120; + ViewThumbnailInvalid = 121; + ViewIdInvalid = 122; + ViewDescTooLong = 123; + ViewDataInvalid = 124; + ViewNameTooLong = 125; + ConnectError = 200; + EmailIsEmpty = 300; + EmailFormatInvalid = 301; + EmailAlreadyExists = 302; + PasswordIsEmpty = 303; + PasswordTooLong = 304; + PasswordContainsForbidCharacters = 305; + PasswordFormatInvalid = 306; + PasswordNotMatch = 307; + UserNameTooLong = 308; + UserNameContainForbiddenCharacters = 309; + UserNameIsEmpty = 310; + UserIdInvalid = 311; + UserNotExist = 312; + TextTooLong = 400; + GridIdIsEmpty = 410; + BlockIdIsEmpty = 420; + RowIdIsEmpty = 430; + OptionIdIsEmpty = 431; + FieldIdIsEmpty = 440; + FieldDoesNotExist = 441; + SelectOptionNameIsEmpty = 442; + FieldNotExists = 443; + FieldInvalidOperation = 444; + TypeOptionDataIsEmpty = 450; + InvalidDateTimeFormat = 500; + UnexpectedEmptyString = 999; + InvalidData = 1000; +} diff --git a/shared-lib/flowy-error-code/src/resource/mod.rs b/shared-lib/flowy-error-code/src/resource/mod.rs new file mode 100644 index 0000000000..da97aad28a --- /dev/null +++ b/shared-lib/flowy-error-code/src/resource/mod.rs @@ -0,0 +1,4 @@ +#![cfg_attr(rustfmt, rustfmt::skip)] +// Auto-generated, do not edit +mod model; +pub use model::*; \ No newline at end of file diff --git a/shared-lib/flowy-error-code/src/resource/model/mod.rs b/shared-lib/flowy-error-code/src/resource/model/mod.rs new file mode 100644 index 0000000000..191b80e077 --- /dev/null +++ b/shared-lib/flowy-error-code/src/resource/model/mod.rs @@ -0,0 +1,5 @@ +#![cfg_attr(rustfmt, rustfmt::skip)] +// Auto-generated, do not edit + +mod code; +pub use code::*; diff --git a/shared-lib/flowy-error-code/src/resource/proto/code.proto b/shared-lib/flowy-error-code/src/resource/proto/code.proto new file mode 100644 index 0000000000..ede9b65657 --- /dev/null +++ b/shared-lib/flowy-error-code/src/resource/proto/code.proto @@ -0,0 +1,48 @@ +syntax = "proto3"; +enum ErrorCode { + Internal = 0; + UserUnauthorized = 2; + RecordNotFound = 3; + UserIdIsEmpty = 4; + WorkspaceNameInvalid = 100; + WorkspaceIdInvalid = 101; + AppColorStyleInvalid = 102; + WorkspaceDescTooLong = 103; + WorkspaceNameTooLong = 104; + AppIdInvalid = 110; + AppNameInvalid = 111; + ViewNameInvalid = 120; + ViewThumbnailInvalid = 121; + ViewIdInvalid = 122; + ViewDescTooLong = 123; + ViewDataInvalid = 124; + ViewNameTooLong = 125; + ConnectError = 200; + EmailIsEmpty = 300; + EmailFormatInvalid = 301; + EmailAlreadyExists = 302; + PasswordIsEmpty = 303; + PasswordTooLong = 304; + PasswordContainsForbidCharacters = 305; + PasswordFormatInvalid = 306; + PasswordNotMatch = 307; + UserNameTooLong = 308; + UserNameContainForbiddenCharacters = 309; + UserNameIsEmpty = 310; + UserIdInvalid = 311; + UserNotExist = 312; + TextTooLong = 400; + GridIdIsEmpty = 410; + BlockIdIsEmpty = 420; + RowIdIsEmpty = 430; + OptionIdIsEmpty = 431; + FieldIdIsEmpty = 440; + FieldDoesNotExist = 441; + SelectOptionNameIsEmpty = 442; + FieldNotExists = 443; + FieldInvalidOperation = 444; + TypeOptionDataIsEmpty = 450; + InvalidDateTimeFormat = 500; + UnexpectedEmptyString = 999; + InvalidData = 1000; +} diff --git a/shared-lib/flowy-folder-data-model/Flowy.toml b/shared-lib/flowy-folder-data-model/Flowy.toml index 5e88aadda5..264666f791 100644 --- a/shared-lib/flowy-folder-data-model/Flowy.toml +++ b/shared-lib/flowy-folder-data-model/Flowy.toml @@ -1,3 +1,5 @@ proto_crates = ["src/entities",] +proto_output_dir = "resources/proto" +protobuf_crate_path = "src/protobuf" event_files = [] \ No newline at end of file diff --git a/shared-lib/flowy-folder-data-model/build.rs b/shared-lib/flowy-folder-data-model/build.rs index 7f06ab48c8..e897c3690d 100644 --- a/shared-lib/flowy-folder-data-model/build.rs +++ b/shared-lib/flowy-folder-data-model/build.rs @@ -1,5 +1,5 @@ use lib_infra::code_gen; fn main() { - code_gen::protobuf_file::gen(env!("CARGO_PKG_NAME"), "./src/protobuf/proto"); + code_gen::protobuf_file::gen(env!("CARGO_PKG_NAME")); } diff --git a/shared-lib/flowy-folder-data-model/src/protobuf/proto/app.proto b/shared-lib/flowy-folder-data-model/resources/proto/app.proto similarity index 100% rename from shared-lib/flowy-folder-data-model/src/protobuf/proto/app.proto rename to shared-lib/flowy-folder-data-model/resources/proto/app.proto diff --git a/shared-lib/flowy-folder-data-model/src/protobuf/proto/trash.proto b/shared-lib/flowy-folder-data-model/resources/proto/trash.proto similarity index 100% rename from shared-lib/flowy-folder-data-model/src/protobuf/proto/trash.proto rename to shared-lib/flowy-folder-data-model/resources/proto/trash.proto diff --git a/shared-lib/flowy-folder-data-model/src/protobuf/proto/view.proto b/shared-lib/flowy-folder-data-model/resources/proto/view.proto similarity index 100% rename from shared-lib/flowy-folder-data-model/src/protobuf/proto/view.proto rename to shared-lib/flowy-folder-data-model/resources/proto/view.proto diff --git a/shared-lib/flowy-folder-data-model/src/protobuf/proto/view_info.proto b/shared-lib/flowy-folder-data-model/resources/proto/view_info.proto similarity index 100% rename from shared-lib/flowy-folder-data-model/src/protobuf/proto/view_info.proto rename to shared-lib/flowy-folder-data-model/resources/proto/view_info.proto diff --git a/shared-lib/flowy-folder-data-model/src/protobuf/proto/workspace.proto b/shared-lib/flowy-folder-data-model/resources/proto/workspace.proto similarity index 100% rename from shared-lib/flowy-folder-data-model/src/protobuf/proto/workspace.proto rename to shared-lib/flowy-folder-data-model/resources/proto/workspace.proto diff --git a/shared-lib/flowy-grid-data-model/Flowy.toml b/shared-lib/flowy-grid-data-model/Flowy.toml index 56b4353888..55d11fd2ee 100644 --- a/shared-lib/flowy-grid-data-model/Flowy.toml +++ b/shared-lib/flowy-grid-data-model/Flowy.toml @@ -1,3 +1,5 @@ proto_crates = ["src/entities/",] +proto_output_dir = "resources/proto" +protobuf_crate_path = "src/protobuf" event_files = [] \ No newline at end of file diff --git a/shared-lib/flowy-grid-data-model/build.rs b/shared-lib/flowy-grid-data-model/build.rs index 7f06ab48c8..e897c3690d 100644 --- a/shared-lib/flowy-grid-data-model/build.rs +++ b/shared-lib/flowy-grid-data-model/build.rs @@ -1,5 +1,5 @@ use lib_infra::code_gen; fn main() { - code_gen::protobuf_file::gen(env!("CARGO_PKG_NAME"), "./src/protobuf/proto"); + code_gen::protobuf_file::gen(env!("CARGO_PKG_NAME")); } diff --git a/shared-lib/flowy-grid-data-model/src/protobuf/proto/field.proto b/shared-lib/flowy-grid-data-model/resources/proto/field.proto similarity index 100% rename from shared-lib/flowy-grid-data-model/src/protobuf/proto/field.proto rename to shared-lib/flowy-grid-data-model/resources/proto/field.proto diff --git a/shared-lib/flowy-grid-data-model/src/protobuf/proto/grid.proto b/shared-lib/flowy-grid-data-model/resources/proto/grid.proto similarity index 100% rename from shared-lib/flowy-grid-data-model/src/protobuf/proto/grid.proto rename to shared-lib/flowy-grid-data-model/resources/proto/grid.proto diff --git a/shared-lib/flowy-grid-data-model/src/protobuf/proto/grid_info.proto b/shared-lib/flowy-grid-data-model/resources/proto/grid_info.proto similarity index 100% rename from shared-lib/flowy-grid-data-model/src/protobuf/proto/grid_info.proto rename to shared-lib/flowy-grid-data-model/resources/proto/grid_info.proto diff --git a/shared-lib/flowy-sync/Flowy.toml b/shared-lib/flowy-sync/Flowy.toml index 33b1c193f2..963226777d 100644 --- a/shared-lib/flowy-sync/Flowy.toml +++ b/shared-lib/flowy-sync/Flowy.toml @@ -1,3 +1,5 @@ proto_crates = ["src/entities"] +proto_output_dir = "resources/proto" +protobuf_crate_path = "src/protobuf" event_files = [] \ No newline at end of file diff --git a/shared-lib/flowy-sync/build.rs b/shared-lib/flowy-sync/build.rs index 7f06ab48c8..e897c3690d 100644 --- a/shared-lib/flowy-sync/build.rs +++ b/shared-lib/flowy-sync/build.rs @@ -1,5 +1,5 @@ use lib_infra::code_gen; fn main() { - code_gen::protobuf_file::gen(env!("CARGO_PKG_NAME"), "./src/protobuf/proto"); + code_gen::protobuf_file::gen(env!("CARGO_PKG_NAME")); } diff --git a/shared-lib/flowy-sync/src/protobuf/proto/folder_info.proto b/shared-lib/flowy-sync/resources/proto/folder_info.proto similarity index 100% rename from shared-lib/flowy-sync/src/protobuf/proto/folder_info.proto rename to shared-lib/flowy-sync/resources/proto/folder_info.proto diff --git a/shared-lib/flowy-sync/src/protobuf/proto/revision.proto b/shared-lib/flowy-sync/resources/proto/revision.proto similarity index 100% rename from shared-lib/flowy-sync/src/protobuf/proto/revision.proto rename to shared-lib/flowy-sync/resources/proto/revision.proto diff --git a/shared-lib/flowy-sync/src/protobuf/proto/text_block_info.proto b/shared-lib/flowy-sync/resources/proto/text_block_info.proto similarity index 100% rename from shared-lib/flowy-sync/src/protobuf/proto/text_block_info.proto rename to shared-lib/flowy-sync/resources/proto/text_block_info.proto diff --git a/shared-lib/flowy-sync/src/protobuf/proto/ws_data.proto b/shared-lib/flowy-sync/resources/proto/ws_data.proto similarity index 100% rename from shared-lib/flowy-sync/src/protobuf/proto/ws_data.proto rename to shared-lib/flowy-sync/resources/proto/ws_data.proto diff --git a/shared-lib/flowy-user-data-model/Flowy.toml b/shared-lib/flowy-user-data-model/Flowy.toml index d1411c4d2b..83c4a9debb 100644 --- a/shared-lib/flowy-user-data-model/Flowy.toml +++ b/shared-lib/flowy-user-data-model/Flowy.toml @@ -1,3 +1,5 @@ proto_crates = ["src/entities", "src/errors.rs"] +proto_output_dir = "resources/proto" +protobuf_crate_path = "src/protobuf" event_files = [] \ No newline at end of file diff --git a/shared-lib/flowy-user-data-model/build.rs b/shared-lib/flowy-user-data-model/build.rs index 7f06ab48c8..e897c3690d 100644 --- a/shared-lib/flowy-user-data-model/build.rs +++ b/shared-lib/flowy-user-data-model/build.rs @@ -1,5 +1,5 @@ use lib_infra::code_gen; fn main() { - code_gen::protobuf_file::gen(env!("CARGO_PKG_NAME"), "./src/protobuf/proto"); + code_gen::protobuf_file::gen(env!("CARGO_PKG_NAME")); } diff --git a/shared-lib/flowy-user-data-model/src/protobuf/proto/auth.proto b/shared-lib/flowy-user-data-model/resources/proto/auth.proto similarity index 100% rename from shared-lib/flowy-user-data-model/src/protobuf/proto/auth.proto rename to shared-lib/flowy-user-data-model/resources/proto/auth.proto diff --git a/shared-lib/flowy-user-data-model/src/protobuf/proto/user_profile.proto b/shared-lib/flowy-user-data-model/resources/proto/user_profile.proto similarity index 100% rename from shared-lib/flowy-user-data-model/src/protobuf/proto/user_profile.proto rename to shared-lib/flowy-user-data-model/resources/proto/user_profile.proto diff --git a/shared-lib/flowy-user-data-model/src/protobuf/proto/user_setting.proto b/shared-lib/flowy-user-data-model/resources/proto/user_setting.proto similarity index 100% rename from shared-lib/flowy-user-data-model/src/protobuf/proto/user_setting.proto rename to shared-lib/flowy-user-data-model/resources/proto/user_setting.proto diff --git a/shared-lib/flowy-user-data-model/src/protobuf/model/errors.rs b/shared-lib/flowy-user-data-model/src/protobuf/model/errors.rs deleted file mode 100644 index 97c089f44c..0000000000 --- a/shared-lib/flowy-user-data-model/src/protobuf/model/errors.rs +++ /dev/null @@ -1,141 +0,0 @@ -// This file is generated by rust-protobuf 2.25.2. Do not edit -// @generated - -// https://github.com/rust-lang/rust-clippy/issues/702 -#![allow(unknown_lints)] -#![allow(clippy::all)] - -#![allow(unused_attributes)] -#![cfg_attr(rustfmt, rustfmt::skip)] - -#![allow(box_pointers)] -#![allow(dead_code)] -#![allow(missing_docs)] -#![allow(non_camel_case_types)] -#![allow(non_snake_case)] -#![allow(non_upper_case_globals)] -#![allow(trivial_casts)] -#![allow(unused_imports)] -#![allow(unused_results)] -//! Generated file from `errors.proto` - -/// Generated files are compatible only with the same version -/// of protobuf runtime. -// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_25_2; - -#[derive(Clone,PartialEq,Eq,Debug,Hash)] -pub enum ErrorCode { - EmailIsEmpty = 0, - EmailFormatInvalid = 1, - EmailAlreadyExists = 2, - PasswordIsEmpty = 10, - PasswordTooLong = 11, - PasswordContainsForbidCharacters = 12, - PasswordFormatInvalid = 13, - PasswordNotMatch = 14, - UserNameTooLong = 20, - UserNameContainForbiddenCharacters = 21, - UserNameIsEmpty = 22, - UserIdInvalid = 23, - UserUnauthorized = 24, - UserNotExist = 25, - ServerError = 99, - InternalError = 100, -} - -impl ::protobuf::ProtobufEnum for ErrorCode { - fn value(&self) -> i32 { - *self as i32 - } - - fn from_i32(value: i32) -> ::std::option::Option { - match value { - 0 => ::std::option::Option::Some(ErrorCode::EmailIsEmpty), - 1 => ::std::option::Option::Some(ErrorCode::EmailFormatInvalid), - 2 => ::std::option::Option::Some(ErrorCode::EmailAlreadyExists), - 10 => ::std::option::Option::Some(ErrorCode::PasswordIsEmpty), - 11 => ::std::option::Option::Some(ErrorCode::PasswordTooLong), - 12 => ::std::option::Option::Some(ErrorCode::PasswordContainsForbidCharacters), - 13 => ::std::option::Option::Some(ErrorCode::PasswordFormatInvalid), - 14 => ::std::option::Option::Some(ErrorCode::PasswordNotMatch), - 20 => ::std::option::Option::Some(ErrorCode::UserNameTooLong), - 21 => ::std::option::Option::Some(ErrorCode::UserNameContainForbiddenCharacters), - 22 => ::std::option::Option::Some(ErrorCode::UserNameIsEmpty), - 23 => ::std::option::Option::Some(ErrorCode::UserIdInvalid), - 24 => ::std::option::Option::Some(ErrorCode::UserUnauthorized), - 25 => ::std::option::Option::Some(ErrorCode::UserNotExist), - 99 => ::std::option::Option::Some(ErrorCode::ServerError), - 100 => ::std::option::Option::Some(ErrorCode::InternalError), - _ => ::std::option::Option::None - } - } - - fn values() -> &'static [Self] { - static values: &'static [ErrorCode] = &[ - ErrorCode::EmailIsEmpty, - ErrorCode::EmailFormatInvalid, - ErrorCode::EmailAlreadyExists, - ErrorCode::PasswordIsEmpty, - ErrorCode::PasswordTooLong, - ErrorCode::PasswordContainsForbidCharacters, - ErrorCode::PasswordFormatInvalid, - ErrorCode::PasswordNotMatch, - ErrorCode::UserNameTooLong, - ErrorCode::UserNameContainForbiddenCharacters, - ErrorCode::UserNameIsEmpty, - ErrorCode::UserIdInvalid, - ErrorCode::UserUnauthorized, - ErrorCode::UserNotExist, - ErrorCode::ServerError, - ErrorCode::InternalError, - ]; - values - } - - fn enum_descriptor_static() -> &'static ::protobuf::reflect::EnumDescriptor { - static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::EnumDescriptor> = ::protobuf::rt::LazyV2::INIT; - descriptor.get(|| { - ::protobuf::reflect::EnumDescriptor::new_pb_name::("ErrorCode", file_descriptor_proto()) - }) - } -} - -impl ::std::marker::Copy for ErrorCode { -} - -impl ::std::default::Default for ErrorCode { - fn default() -> Self { - ErrorCode::EmailIsEmpty - } -} - -impl ::protobuf::reflect::ProtobufValue for ErrorCode { - fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { - ::protobuf::reflect::ReflectValueRef::Enum(::protobuf::ProtobufEnum::descriptor(self)) - } -} - -static file_descriptor_proto_data: &'static [u8] = b"\ - \n\x0cerrors.proto*\xff\x02\n\tErrorCode\x12\x10\n\x0cEmailIsEmpty\x10\0\ - \x12\x16\n\x12EmailFormatInvalid\x10\x01\x12\x16\n\x12EmailAlreadyExists\ - \x10\x02\x12\x13\n\x0fPasswordIsEmpty\x10\n\x12\x13\n\x0fPasswordTooLong\ - \x10\x0b\x12$\n\x20PasswordContainsForbidCharacters\x10\x0c\x12\x19\n\ - \x15PasswordFormatInvalid\x10\r\x12\x14\n\x10PasswordNotMatch\x10\x0e\ - \x12\x13\n\x0fUserNameTooLong\x10\x14\x12&\n\"UserNameContainForbiddenCh\ - aracters\x10\x15\x12\x13\n\x0fUserNameIsEmpty\x10\x16\x12\x11\n\rUserIdI\ - nvalid\x10\x17\x12\x14\n\x10UserUnauthorized\x10\x18\x12\x10\n\x0cUserNo\ - tExist\x10\x19\x12\x0f\n\x0bServerError\x10c\x12\x11\n\rInternalError\ - \x10db\x06proto3\ -"; - -static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT; - -fn parse_descriptor_proto() -> ::protobuf::descriptor::FileDescriptorProto { - ::protobuf::Message::parse_from_bytes(file_descriptor_proto_data).unwrap() -} - -pub fn file_descriptor_proto() -> &'static ::protobuf::descriptor::FileDescriptorProto { - file_descriptor_proto_lazy.get(|| { - parse_descriptor_proto() - }) -} diff --git a/shared-lib/flowy-user-data-model/src/protobuf/model/mod.rs b/shared-lib/flowy-user-data-model/src/protobuf/model/mod.rs index e691c7e166..1290420028 100644 --- a/shared-lib/flowy-user-data-model/src/protobuf/model/mod.rs +++ b/shared-lib/flowy-user-data-model/src/protobuf/model/mod.rs @@ -1,9 +1,6 @@ #![cfg_attr(rustfmt, rustfmt::skip)] // Auto-generated, do not edit -mod errors; -pub use errors::*; - mod user_profile; pub use user_profile::*; diff --git a/shared-lib/flowy-user-data-model/src/protobuf/proto/errors.proto b/shared-lib/flowy-user-data-model/src/protobuf/proto/errors.proto deleted file mode 100644 index 6acad10651..0000000000 --- a/shared-lib/flowy-user-data-model/src/protobuf/proto/errors.proto +++ /dev/null @@ -1,20 +0,0 @@ -syntax = "proto3"; - -enum ErrorCode { - EmailIsEmpty = 0; - EmailFormatInvalid = 1; - EmailAlreadyExists = 2; - PasswordIsEmpty = 10; - PasswordTooLong = 11; - PasswordContainsForbidCharacters = 12; - PasswordFormatInvalid = 13; - PasswordNotMatch = 14; - UserNameTooLong = 20; - UserNameContainForbiddenCharacters = 21; - UserNameIsEmpty = 22; - UserIdInvalid = 23; - UserUnauthorized = 24; - UserNotExist = 25; - ServerError = 99; - InternalError = 100; -} 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 1357f25a74..3f72133518 100644 --- a/shared-lib/lib-infra/src/code_gen/flowy_toml.rs +++ b/shared-lib/lib-infra/src/code_gen/flowy_toml.rs @@ -2,10 +2,12 @@ use crate::code_gen::util::path_buf_with_component; use std::fs; use std::path::{Path, PathBuf}; -#[derive(serde::Deserialize)] +#[derive(serde::Deserialize, Clone, Debug)] pub struct FlowyConfig { pub proto_crates: Vec, pub event_files: Vec, + pub proto_output_dir: String, + pub protobuf_crate_path: String, } impl FlowyConfig { 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 a44f0cb267..17e1cf273e 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 @@ -17,44 +17,49 @@ use std::path::{Path, PathBuf}; use std::process::Command; use walkdir::WalkDir; -pub fn gen(crate_name: &str, proto_file_dir: &str) { +pub fn gen(crate_name: &str) { + let crate_path = std::fs::canonicalize(".").unwrap().as_path().display().to_string(); + // 1. generate the proto files to proto_file_dir #[cfg(feature = "proto_gen")] - let _ = gen_protos(crate_name); + let proto_crates = gen_proto_files(crate_name, &crate_path); - let mut proto_file_paths = vec![]; - let mut file_names = vec![]; + for proto_crate in proto_crates { + let mut proto_file_paths = vec![]; + let mut file_names = vec![]; + let proto_file_dir = &proto_crate.flowy_config.proto_output_dir; - for (path, file_name) in WalkDir::new(proto_file_dir) - .into_iter() - .filter_map(|e| e.ok()) - .map(|e| { - let path = e.path().to_str().unwrap().to_string(); - let file_name = e.path().file_stem().unwrap().to_str().unwrap().to_string(); - (path, file_name) - }) - { - if path.ends_with(".proto") { - // https://stackoverflow.com/questions/49077147/how-can-i-force-build-rs-to-run-again-without-cleaning-my-whole-project - println!("cargo:rerun-if-changed={}", path); - proto_file_paths.push(path); - file_names.push(file_name); + for (path, file_name) in WalkDir::new(proto_file_dir) + .into_iter() + .filter_map(|e| e.ok()) + .map(|e| { + let path = e.path().to_str().unwrap().to_string(); + let file_name = e.path().file_stem().unwrap().to_str().unwrap().to_string(); + (path, file_name) + }) + { + if path.ends_with(".proto") { + // https://stackoverflow.com/questions/49077147/how-can-i-force-build-rs-to-run-again-without-cleaning-my-whole-project + println!("cargo:rerun-if-changed={}", path); + proto_file_paths.push(path); + file_names.push(file_name); + } } + let protoc_bin_path = protoc_bin_vendored::protoc_bin_path().unwrap(); + + // 2. generate the protobuf files(Dart) + #[cfg(feature = "dart")] + generate_dart_protobuf_files( + crate_name, + proto_file_dir, + &proto_file_paths, + &file_names, + &protoc_bin_path, + ); + + // 3. generate the protobuf files(Rust) + generate_rust_protobuf_files(&protoc_bin_path, &proto_file_paths, proto_file_dir); } - let protoc_bin_path = protoc_bin_vendored::protoc_bin_path().unwrap(); - - // 2. generate the protobuf files(Dart) - #[cfg(feature = "dart")] - generate_dart_protobuf_files( - crate_name, - proto_file_dir, - &proto_file_paths, - &file_names, - &protoc_bin_path, - ); - - // 3. generate the protobuf files(Rust) - generate_rust_protobuf_files(&protoc_bin_path, &proto_file_paths, proto_file_dir); } fn generate_rust_protobuf_files(protoc_bin_path: &Path, proto_file_paths: &[String], proto_file_dir: &str) { @@ -70,7 +75,7 @@ fn generate_rust_protobuf_files(protoc_bin_path: &Path, proto_file_paths: &[Stri #[cfg(feature = "dart")] fn generate_dart_protobuf_files( name: &str, - root: &str, + proto_path: &str, paths: &Vec, file_names: &Vec, protoc_bin_path: &PathBuf, @@ -99,7 +104,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=${root} ${path} + ${protoc_bin_path} --dart_out=${output} --proto_path=${proto_path} ${path} } .is_err() { @@ -175,9 +180,8 @@ pub fn check_pb_dart_plugin() { } #[cfg(feature = "proto_gen")] -fn gen_protos(crate_name: &str) -> Vec { - let crate_path = std::fs::canonicalize(".").unwrap().as_path().display().to_string(); - let crate_context = ProtoGenerator::gen(crate_name, &crate_path); +fn gen_proto_files(crate_name: &str, crate_path: &str) -> Vec { + let crate_context = ProtoGenerator::gen(crate_name, crate_path); let proto_crates = crate_context .iter() .map(|info| info.protobuf_crate.clone()) 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 6c51c5b055..3a6e2e330d 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 @@ -1,5 +1,5 @@ #![allow(dead_code)] -use crate::code_gen::flowy_toml::{parse_crate_config_from, CrateConfig}; +use crate::code_gen::flowy_toml::{parse_crate_config_from, CrateConfig, FlowyConfig}; use crate::code_gen::util::*; use std::fs::OpenOptions; use std::io::Write; @@ -62,27 +62,30 @@ pub struct ProtobufCrate { pub folder_name: String, pub proto_paths: Vec, pub crate_path: PathBuf, + pub flowy_config: FlowyConfig, } 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, + flowy_config: config.flowy_config.clone(), } } fn protobuf_crate_name(&self) -> PathBuf { - path_buf_with_component(&self.crate_path, vec!["src", "protobuf"]) + let crate_path = PathBuf::from(&self.flowy_config.protobuf_crate_path); + crate_path } pub fn proto_output_dir(&self) -> PathBuf { - let path = self.protobuf_crate_name(); - let dir = path_buf_with_component(&path, vec!["proto"]); - create_dir_if_not_exist(&dir); - dir + let output_dir = PathBuf::from(&self.flowy_config.proto_output_dir); + create_dir_if_not_exist(&output_dir); + output_dir } pub fn create_output_dir(&self) -> PathBuf { diff --git a/shared-lib/lib-ws/Flowy.toml b/shared-lib/lib-ws/Flowy.toml index fec0b43d8b..8be549bb05 100644 --- a/shared-lib/lib-ws/Flowy.toml +++ b/shared-lib/lib-ws/Flowy.toml @@ -1,2 +1,4 @@ proto_crates = ["src/errors.rs", "src/msg.rs"] +proto_output_dir = "resources/proto" +protobuf_crate_path = "src/protobuf" event_files = [] \ No newline at end of file diff --git a/shared-lib/lib-ws/build.rs b/shared-lib/lib-ws/build.rs index 7f06ab48c8..e897c3690d 100644 --- a/shared-lib/lib-ws/build.rs +++ b/shared-lib/lib-ws/build.rs @@ -1,5 +1,5 @@ use lib_infra::code_gen; fn main() { - code_gen::protobuf_file::gen(env!("CARGO_PKG_NAME"), "./src/protobuf/proto"); + code_gen::protobuf_file::gen(env!("CARGO_PKG_NAME")); } diff --git a/shared-lib/lib-ws/src/protobuf/proto/errors.proto b/shared-lib/lib-ws/resources/proto/errors.proto similarity index 100% rename from shared-lib/lib-ws/src/protobuf/proto/errors.proto rename to shared-lib/lib-ws/resources/proto/errors.proto diff --git a/shared-lib/lib-ws/src/protobuf/proto/msg.proto b/shared-lib/lib-ws/resources/proto/msg.proto similarity index 100% rename from shared-lib/lib-ws/src/protobuf/proto/msg.proto rename to shared-lib/lib-ws/resources/proto/msg.proto