refactor: tauri folder (#1738)

This commit is contained in:
Nathan.fooo 2023-01-24 14:01:30 +08:00 committed by GitHub
parent d2db49efab
commit 67f07463f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 52 additions and 43 deletions

View File

@ -92,9 +92,10 @@
"cwd": "${workspaceRoot}/app_flowy"
},
{
// https://tauri.app/v1/guides/debugging/vs-code
"type": "lldb",
"request": "launch",
"name": "AF-tauri: Dev",
"name": "AF-tauri: Debug backend",
"cargo": {
"args": [
"build",
@ -102,7 +103,7 @@
"--no-default-features"
]
},
"preLaunchTask": "AF: Tauri Dev",
"preLaunchTask": "AF: Tauri UI Dev",
"cwd": "${workspaceRoot}/appflowy_tauri/"
},
{

View File

@ -20,7 +20,7 @@
"AF: Flutter Pub Get",
"AF: Flutter Package Get",
"AF: Generate Language Files",
"AF: Generate Freezed Files",
"AF: Generate Freezed Files"
],
"presentation": {
"reveal": "always",
@ -38,12 +38,12 @@
"AF: Flutter Pub Get",
"AF: Flutter Package Get",
"AF: Generate Language Files",
"AF: Generate Freezed Files",
"AF: Generate Freezed Files"
],
"presentation": {
"reveal": "always",
"panel": "new",
},
"panel": "new"
}
},
{
"label": "AF: build_flowy_sdk_for_android",
@ -187,11 +187,20 @@
"detail": "app_flowy"
},
{
"label": "AF: Tauri Dev",
"label": "AF: Tauri UI Dev",
"type": "shell",
"isBackground": true,
"command": "npm run dev",
"problemMatcher": [],
"command": "yarn dev",
"problemMatcher": ["$tsc"],
"options": {
"cwd": "${workspaceFolder}/appflowy_tauri"
}
},
{
"label": "AF: Tauri Dev",
"type": "shell",
"command": "npm run tauri dev",
"problemMatcher": ["$tsc"],
"options": {
"cwd": "${workspaceFolder}/appflowy_tauri"
}
@ -202,7 +211,20 @@
"command": "cargo make tauri_clean",
"options": {
"cwd": "${workspaceFolder}"
}
},
"problemMatcher": ["$tsc"],
},
{
"label": "AF: Tauri Clean + Dev",
"type": "shell",
"dependsOrder": "sequence",
"dependsOn": [
"AF: Tauri Clean",
"AF: Tauri UI Dev"
],
"options": {
"cwd": "${workspaceFolder}"
}
}
]
}

View File

@ -44,7 +44,7 @@ CRATE_TYPE = "staticlib"
LIB_EXT = "a"
APP_ENVIRONMENT = "local"
FLUTTER_FLOWY_SDK_PATH = "app_flowy/packages/appflowy_backend"
TAURI_PROTOBUF_PATH = "appflowy_tauri/src/protobuf"
TAURI_BACKEND_SERVICE_PATH = "appflowy_tauri/src/services/backend"
# Test default config
TEST_CRATE_TYPE = "cdylib"
TEST_LIB_EXT = "dylib"

View File

@ -23,5 +23,5 @@ dist-ssr
*.sln
*.sw?
**/src/protobuf/classes/
**/src/protobuf/events/
**/src/services/backend/classes/
**/src/services/backend/events/

View File

@ -1,7 +1,3 @@
use std::env;
fn main() {
env::set_var("TAURI_PROTOBUF_PATH", "appflowy_tauri/src/protobuf");
env::set_var("CARGO_MAKE_WORKING_DIRECTORY", "../../../");
tauri_build::build()
}

View File

@ -2,7 +2,7 @@ import "./App.css";
import {
UserEventSignIn,
SignInPayloadPB,
} from "./protobuf/events/flowy-user";
} from "../services/backend/events/flowy-user";
import { nanoid } from "nanoid";

View File

@ -1,7 +1,7 @@
import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App";
import "./style.css";
import App from "./appflowy_app/App";
import "./appflowy_app/style.css";
ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
<React.StrictMode>

View File

@ -101,11 +101,12 @@ fn generate_ts_protobuf_files(
protoc_bin_path: &Path,
) {
let root = std::env::var("CARGO_MAKE_WORKING_DIRECTORY").unwrap_or("../../".to_string());
let tauri_protobuf_path = std::env::var("TAURI_PROTOBUF_PATH").unwrap_or("appflowy_tauri/src/protobuf".to_string());
let tauri_backend_service_path =
std::env::var("TAURI_BACKEND_SERVICE_PATH").unwrap_or("appflowy_tauri/src/services/backend".to_string());
let mut output = PathBuf::new();
output.push(root);
output.push(tauri_protobuf_path);
output.push(tauri_backend_service_path);
output.push("classes");
output.push(name);

View File

@ -14,7 +14,8 @@ use walkdir::WalkDir;
pub fn gen(crate_name: &str) {
let root = std::env::var("CARGO_MAKE_WORKING_DIRECTORY").unwrap_or("../../".to_string());
let tauri_protobuf_path = std::env::var("TAURI_PROTOBUF_PATH").unwrap_or("appflowy_tauri/src/protobuf".to_string());
let tauri_backend_service_path =
std::env::var("TAURI_BACKEND_SERVICE_PATH").unwrap_or("appflowy_tauri/src/services/backend".to_string());
let crate_path = std::fs::canonicalize(".").unwrap().as_path().display().to_string();
let event_crates = parse_ts_event_files(vec![crate_path]);
@ -31,7 +32,9 @@ pub fn gen(crate_name: &str) {
}
render_result.push_str(TS_FOOTER);
let ts_event_folder: PathBuf = [&root, &tauri_protobuf_path, "events", crate_name].iter().collect();
let ts_event_folder: PathBuf = [&root, &tauri_backend_service_path, "events", crate_name]
.iter()
.collect();
if !ts_event_folder.as_path().exists() {
std::fs::create_dir_all(ts_event_folder.as_path()).unwrap();
}
@ -185,7 +188,7 @@ const TS_HEADER: &str = r#"
/// Auto generate. Do not edit
import { Ok, Err, Result } from "ts-results";
import { invoke } from "@tauri-apps/api/tauri";
import * as pb from "../../classes";
import * as pb from "../..";
"#;
const TS_FOOTER: &str = r#"

View File

@ -1,17 +1,3 @@
[tasks.tauri_env]
script_runner = "@rust"
script = '''
//! ```cargo
use std::env;
fn main() {
env.set_var("TAURI_PROTOBUF_PATH", "appflowy_tauri/src/protobuf");
}
'''
[tasks.tauri_build]
script = ["""
cd appflowy_tauri/src-tauri
@ -45,7 +31,7 @@ run_task = { name = [
[tasks.rm_tauri_generated_protobuf_files]
private = true
script = ["""
protobuf_file_paths = glob_array ${TAURI_PROTOBUF_PATH}/classes
protobuf_file_paths = glob_array ${TAURI_BACKEND_SERVICE_PATH}/classes
if not array_is_empty ${protobuf_file_paths}
echo Remove generated protobuf files:
for path in ${protobuf_file_paths}
@ -59,10 +45,10 @@ script_runner = "@duckscript"
[tasks.rm_tauri_generated_event_files]
private = true
script = ["""
protobuf_file_paths = glob_array ${TAURI_PROTOBUF_PATH}/events
if not array_is_empty ${protobuf_file_paths}
event_file_paths = glob_array ${TAURI_BACKEND_SERVICE_PATH}/events
if not array_is_empty ${event_file_paths}
echo Remove generated protobuf files:
for path in ${protobuf_file_paths}
for path in ${event_file_paths}
echo remove ${path}
rm -rf ${path}
end