chore: build tauri from vscode launch (#1720)

* chore: build tauri from vscode launch

* fix: unit test

Co-authored-by: nathan <nathan@appflowy.io>
This commit is contained in:
Nathan.fooo
2023-01-18 11:22:13 +08:00
committed by GitHub
parent e6b186cc43
commit d77c41013f
14 changed files with 71 additions and 64 deletions

View File

@ -38,7 +38,4 @@ http_sync = ["flowy-core/http_sync", "flowy-core/use_bunyan"]
openssl_vendored = ["flowy-core/openssl_vendored"]
[build-dependencies]
flowy-codegen = { path = "../flowy-codegen", features = [
"dart",
]}
flowy-codegen = { path = "../flowy-codegen", features = ["dart"] }

View File

@ -6,17 +6,17 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
lazy_static = {version = "1.4.0"}
protobuf = {version = "2.20.0"}
allo-isolate = {version = "^0.1", features = ["catch-unwind",]}
lazy_static = { version = "1.4.0" }
protobuf = { version = "2.20.0" }
allo-isolate = { version = "^0.1", features = ["catch-unwind"] }
log = "0.4.14"
bytes = { version = "1.0" }
flowy-derive = {path = "../flowy-derive" }
lib-dispatch = {path = "../lib-dispatch" }
flowy-derive = { path = "../flowy-derive" }
lib-dispatch = { path = "../lib-dispatch" }
[build-dependencies]
flowy-codegen = { path = "../flowy-codegen", features = ["dart"]}
flowy-codegen = { path = "../flowy-codegen" }
[features]
dart = []
dart = ["flowy-codegen/dart"]

View File

@ -16,7 +16,7 @@ cmd_lib = { version = "1", optional = true }
protoc-rust = { version = "2", optional = true }
walkdir = { version = "2", optional = true }
similar = { version = "1.2.2", optional = true }
syn = { version = "1.0.60", features = ["extra-traits", "parsing", "derive", "full"], optional = true }
syn = { version = "1.0.60", features = ["extra-traits", "parsing", "derive", "full"] }
fancy-regex = { version = "0.10.0", optional = true }
lazy_static = { version = "1.4.0", optional = true }
tera = { version = "1.5.0", optional = true}
@ -31,7 +31,6 @@ toml = {version = "0.5.8", optional = true}
[features]
proto_gen = [
"similar",
"syn",
"fancy-regex",
"lazy_static",
"tera",
@ -45,7 +44,7 @@ proto_gen = [
"walkdir",
"protoc-bin-vendored",
]
dart_event = ["walkdir", "tera", "syn"]
dart_event = ["walkdir", "tera", ]
dart = ["proto_gen", "dart_event"]
ts_event = ["walkdir", "tera", "syn"]
ts_event = ["walkdir", "tera", ]
ts = ["proto_gen", "ts_event"]

View File

@ -1,5 +1,5 @@
use super::event_template::*;
use crate::dart_event::ast::EventASTContext;
use crate::ast::EventASTContext;
use crate::flowy_toml::{parse_crate_config_from, CrateConfig};
use crate::util::{is_crate_dir, is_hidden, path_string_with_component, read_file};
use flowy_ast::ASTResult;

View File

@ -1,5 +1,5 @@
#![allow(clippy::module_inception)]
pub(crate) mod ast;
mod dart_event;
mod event_template;

View File

@ -10,6 +10,7 @@ pub mod ts_event;
#[cfg(any(feature = "proto_gen", feature = "dart_event", feature = "ts_event"))]
mod flowy_toml;
pub(crate) mod ast;
#[cfg(any(feature = "proto_gen", feature = "dart_event", feature = "ts_event"))]
pub mod util;

View File

@ -100,14 +100,13 @@ fn generate_ts_protobuf_files(
file_names: &Vec<String>,
protoc_bin_path: &Path,
) {
if std::env::var("TAURI_PROTOBUF_PATH").is_err() {
eprintln!("TAURI_PROTOBUF_PATH was not set, skip generate ts pb");
return;
}
let root = std::env::var("CARGO_MAKE_WORKING_DIRECTORY").unwrap_or("../../".to_string());
let tauri_protobuf_path =
std::env::var("CARGO_MAKE_WORKING_DIRECTORY").unwrap_or("appflowy_tauri/src/protobuf".to_string());
let mut output = PathBuf::new();
output.push(std::env::var("CARGO_MAKE_WORKING_DIRECTORY").unwrap());
output.push(std::env::var("TAURI_PROTOBUF_PATH").unwrap());
output.push(root);
output.push(tauri_protobuf_path);
output.push("classes");
output.push(name);
@ -159,12 +158,12 @@ fn generate_dart_protobuf_files(
protoc_bin_path: &Path,
) {
if std::env::var("CARGO_MAKE_WORKING_DIRECTORY").is_err() {
log::warn!("CARGO_MAKE_WORKING_DIRECTORY was not set, skip generate dart pb");
log::error!("CARGO_MAKE_WORKING_DIRECTORY was not set, skip generate dart pb");
return;
}
if std::env::var("FLUTTER_FLOWY_SDK_PATH").is_err() {
log::warn!("FLUTTER_FLOWY_SDK_PATH was not set, skip generate dart pb");
log::error!("FLUTTER_FLOWY_SDK_PATH was not set, skip generate dart pb");
return;
}

View File

@ -1,6 +1,6 @@
mod event_template;
use crate::dart_event::ast::EventASTContext;
use crate::ast::EventASTContext;
use crate::flowy_toml::{parse_crate_config_from, CrateConfig};
use crate::ts_event::event_template::{EventRenderContext, EventTemplate};
use crate::util::{is_crate_dir, is_hidden, path_string_with_component, read_file};
@ -13,10 +13,9 @@ use syn::Item;
use walkdir::WalkDir;
pub fn gen(crate_name: &str) {
if std::env::var("TAURI_PROTOBUF_PATH").is_err() {
log::warn!("TAURI_PROTOBUF_PATH was not set, skip generate ts event");
return;
}
let root = std::env::var("CARGO_MAKE_WORKING_DIRECTORY").unwrap_or("../../".to_string());
let tauri_protobuf_path =
std::env::var("CARGO_MAKE_WORKING_DIRECTORY").unwrap_or("appflowy_tauri/src/protobuf".to_string());
let crate_path = std::fs::canonicalize(".").unwrap().as_path().display().to_string();
let event_crates = parse_ts_event_files(vec![crate_path]);
@ -33,15 +32,7 @@ pub fn gen(crate_name: &str) {
}
render_result.push_str(TS_FOOTER);
let ts_event_folder: PathBuf = [
&std::env::var("CARGO_MAKE_WORKING_DIRECTORY").unwrap(),
&std::env::var("TAURI_PROTOBUF_PATH").unwrap(),
"events",
crate_name,
]
.iter()
.collect();
let ts_event_folder: PathBuf = [&root, &tauri_protobuf_path, "events", crate_name].iter().collect();
if !ts_event_folder.as_path().exists() {
std::fs::create_dir_all(ts_event_folder.as_path()).unwrap();
}

View File

@ -149,7 +149,7 @@ where
pub async fn pong(&self, user: Arc<dyn RevisionUser>, client_rev_id: i64) -> Result<(), CollaborateError> {
let object_id = self.object_id.clone();
let server_rev_id = self.rev_id();
tracing::Span::current().record("server_rev_id", &server_rev_id);
tracing::Span::current().record("server_rev_id", server_rev_id);
match server_rev_id.cmp(&client_rev_id) {
Ordering::Less => {
tracing::trace!("Client should not send ping and the server should pull the revisions from the client")
@ -171,7 +171,7 @@ where
#[tracing::instrument(level = "debug", skip(self, revisions), fields(object_id), err)]
pub async fn reset(&self, revisions: Vec<Revision>) -> Result<(), CollaborateError> {
let object_id = self.object_id.clone();
tracing::Span::current().record("object_id", &object_id.as_str());
tracing::Span::current().record("object_id", object_id.as_str());
let (_, rev_id) = pair_rev_id_from_revision_pbs(&revisions);
let operations = make_operations_from_revisions(revisions.clone())?;
self.persistence.reset_object(&object_id, revisions).await?;