refactor: separate proto file from src folder

This commit is contained in:
appflowy 2022-06-15 19:40:18 +08:00
parent b4a5d007be
commit 4b71c474e4
86 changed files with 258 additions and 224 deletions

View File

@ -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';

View File

@ -1,2 +1,4 @@
proto_crates = ["src/model"]
proto_output_dir = "resources/proto"
protobuf_crate_path = "src/protobuf"
event_files = []

View File

@ -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"));
}

View File

@ -1,3 +1,5 @@
proto_crates = ["src/entities"]
proto_output_dir = "resources/proto"
protobuf_crate_path = "src/protobuf"
event_files = []

View File

@ -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"));
}

View File

@ -1,3 +1,5 @@
proto_crates = ["src/errors.rs",]
proto_output_dir = "resources/proto"
protobuf_crate_path = "src/protobuf"
event_files = []

View File

@ -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");
}

View File

@ -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"]

View File

@ -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);

View File

@ -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"]

View File

@ -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);

View File

@ -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"]

View File

@ -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);

View File

@ -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"]

View File

@ -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);

View File

@ -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"]

View File

@ -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);

View File

@ -0,0 +1,5 @@
#![cfg_attr(rustfmt, rustfmt::skip)]
// Auto-generated, do not edit
mod code;
pub use code::*;

View File

@ -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;
}

View File

@ -1,3 +1,5 @@
proto_crates = ["src/code.rs"]
proto_output_dir = "resources/proto"
protobuf_crate_path = "src/protobuf"
event_files = []

View File

@ -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"));
}

View File

@ -0,0 +1,5 @@
#![cfg_attr(rustfmt, rustfmt::skip)]
// Auto-generated, do not edit
mod code;
pub use code::*;

View File

@ -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;
}

View File

@ -0,0 +1,4 @@
#![cfg_attr(rustfmt, rustfmt::skip)]
// Auto-generated, do not edit
mod model;
pub use model::*;

View File

@ -0,0 +1,5 @@
#![cfg_attr(rustfmt, rustfmt::skip)]
// Auto-generated, do not edit
mod code;
pub use code::*;

View File

@ -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;
}

View File

@ -1,3 +1,5 @@
proto_crates = ["src/entities",]
proto_output_dir = "resources/proto"
protobuf_crate_path = "src/protobuf"
event_files = []

View File

@ -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"));
}

View File

@ -1,3 +1,5 @@
proto_crates = ["src/entities/",]
proto_output_dir = "resources/proto"
protobuf_crate_path = "src/protobuf"
event_files = []

View File

@ -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"));
}

View File

@ -1,3 +1,5 @@
proto_crates = ["src/entities"]
proto_output_dir = "resources/proto"
protobuf_crate_path = "src/protobuf"
event_files = []

View File

@ -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"));
}

View File

@ -1,3 +1,5 @@
proto_crates = ["src/entities", "src/errors.rs"]
proto_output_dir = "resources/proto"
protobuf_crate_path = "src/protobuf"
event_files = []

View File

@ -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"));
}

View File

@ -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<ErrorCode> {
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>("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()
})
}

View File

@ -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::*;

View File

@ -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;
}

View File

@ -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<String>,
pub event_files: Vec<String>,
pub proto_output_dir: String,
pub protobuf_crate_path: String,
}
impl FlowyConfig {

View File

@ -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<String>,
file_names: &Vec<String>,
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<ProtobufCrate> {
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<ProtobufCrate> {
let crate_context = ProtoGenerator::gen(crate_name, crate_path);
let proto_crates = crate_context
.iter()
.map(|info| info.protobuf_crate.clone())

View File

@ -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<PathBuf>,
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 {

View File

@ -1,2 +1,4 @@
proto_crates = ["src/errors.rs", "src/msg.rs"]
proto_output_dir = "resources/proto"
protobuf_crate_path = "src/protobuf"
event_files = []

View File

@ -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"));
}