mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2025-04-24 22:57:12 -04:00
feat: add flowy_clean command to remove the build.rs cache
This commit is contained in:
parent
0933935071
commit
bf3a0b6e5b
11 changed files with 93 additions and 24 deletions
|
@ -1,4 +1,4 @@
|
||||||
.PHONY: flowy_dev_install
|
.PHONY: flowy_dev_install flowy_clean
|
||||||
|
|
||||||
flowy_dev_install:
|
flowy_dev_install:
|
||||||
brew bundle
|
brew bundle
|
||||||
|
@ -8,3 +8,7 @@ flowy_dev_install:
|
||||||
cargo make flowy_dev
|
cargo make flowy_dev
|
||||||
|
|
||||||
|
|
||||||
|
flowy_clean:
|
||||||
|
sh ./scripts/clean.sh
|
||||||
|
|
||||||
|
|
||||||
|
|
7
frontend/app_flowy/.vscode/launch.json
vendored
7
frontend/app_flowy/.vscode/launch.json
vendored
|
@ -40,5 +40,12 @@
|
||||||
"preLaunchTask": "Generate Language Files",
|
"preLaunchTask": "Generate Language Files",
|
||||||
"cwd": "${workspaceRoot}"
|
"cwd": "${workspaceRoot}"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "Clean",
|
||||||
|
"request": "launch",
|
||||||
|
"type": "dart",
|
||||||
|
"preLaunchTask": "Clean",
|
||||||
|
"cwd": "${workspaceRoot}"
|
||||||
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
21
frontend/app_flowy/.vscode/tasks.json
vendored
21
frontend/app_flowy/.vscode/tasks.json
vendored
|
@ -70,6 +70,27 @@
|
||||||
"options": {
|
"options": {
|
||||||
"cwd": "${workspaceFolder}/../"
|
"cwd": "${workspaceFolder}/../"
|
||||||
},
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "Clean FlowySDK",
|
||||||
|
"type": "shell",
|
||||||
|
"command": "sh ./scripts/clean.sh",
|
||||||
|
"windows": {
|
||||||
|
"options": {
|
||||||
|
"shell": {
|
||||||
|
"executable": "cmd.exe",
|
||||||
|
"args": [
|
||||||
|
"/d",
|
||||||
|
"/c",
|
||||||
|
".\\scripts\\clean.cmd"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"group": "build",
|
||||||
|
"options": {
|
||||||
|
"cwd": "${workspaceFolder}/../"
|
||||||
|
},
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
|
@ -1,5 +1,7 @@
|
||||||
use lib_infra::code_gen;
|
use lib_infra::code_gen;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
code_gen::protobuf_file::gen(env!("CARGO_PKG_NAME"), "./src/protobuf/proto");
|
let crate_name = env!("CARGO_PKG_NAME");
|
||||||
|
code_gen::protobuf_file::gen(crate_name, "./src/protobuf/proto");
|
||||||
|
// dart_event::gen(crate_name);
|
||||||
}
|
}
|
||||||
|
|
7
frontend/scripts/clean.cmd
Normal file
7
frontend/scripts/clean.cmd
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
cd rust-lib
|
||||||
|
cargo clean
|
||||||
|
|
||||||
|
cd ../../shared-lib
|
||||||
|
cargo clean
|
||||||
|
|
||||||
|
rmdir /s/q lib-infra/.cache
|
10
frontend/scripts/clean.sh
Normal file
10
frontend/scripts/clean.sh
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
#!/bin/sh
|
||||||
|
#!/usr/bin/env fish
|
||||||
|
|
||||||
|
cd rust-lib
|
||||||
|
cargo clean
|
||||||
|
|
||||||
|
cd ../../shared-lib
|
||||||
|
cargo clean
|
||||||
|
|
||||||
|
rm -rf lib-infra/.cache
|
|
@ -8,6 +8,7 @@ use crate::proto_buf::{
|
||||||
};
|
};
|
||||||
use flowy_ast::*;
|
use flowy_ast::*;
|
||||||
use proc_macro2::TokenStream;
|
use proc_macro2::TokenStream;
|
||||||
|
use std::default::Default;
|
||||||
|
|
||||||
pub fn expand_derive(input: &syn::DeriveInput) -> Result<TokenStream, Vec<syn::Error>> {
|
pub fn expand_derive(input: &syn::DeriveInput) -> Result<TokenStream, Vec<syn::Error>> {
|
||||||
let ctxt = Ctxt::new();
|
let ctxt = Ctxt::new();
|
||||||
|
|
|
@ -1,15 +1,14 @@
|
||||||
use super::event_template::*;
|
use super::event_template::*;
|
||||||
use crate::code_gen::flowy_toml::{parse_crate_config_from, CrateConfig};
|
use crate::code_gen::flowy_toml::{parse_crate_config_from, CrateConfig};
|
||||||
use crate::code_gen::util::{is_crate_dir, is_hidden, read_file, save_content_to_file_with_diff_prompt};
|
use crate::code_gen::util::{cache_dir, is_crate_dir, is_hidden, read_file, save_content_to_file_with_diff_prompt};
|
||||||
use flowy_ast::{event_ast::*, *};
|
use flowy_ast::{event_ast::*, *};
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::Write;
|
||||||
use syn::Item;
|
use syn::Item;
|
||||||
use walkdir::WalkDir;
|
use walkdir::WalkDir;
|
||||||
|
|
||||||
pub struct DartEventCodeGen();
|
pub fn gen(crate_name: &str) {
|
||||||
|
let event_crates = parse_dart_event_files(vec![".".to_owned()]);
|
||||||
impl DartEventCodeGen {
|
|
||||||
pub fn gen(crate_name: &str, crate_path: &str) {
|
|
||||||
let event_crates = parse_dart_event_files(vec![crate_path.to_owned()]);
|
|
||||||
let event_ast = event_crates.iter().map(parse_event_crate).flatten().collect::<Vec<_>>();
|
let event_ast = event_crates.iter().map(parse_event_crate).flatten().collect::<Vec<_>>();
|
||||||
|
|
||||||
let event_render_ctx = ast_to_event_render_ctx(event_ast.as_ref());
|
let event_render_ctx = ast_to_event_render_ctx(event_ast.as_ref());
|
||||||
|
@ -22,7 +21,22 @@ impl DartEventCodeGen {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
save_content_to_file_with_diff_prompt(render_result.as_ref(), ".");
|
let cache_dir = format!("{}/{}", cache_dir(), crate_name);
|
||||||
|
let dart_event_file_path = format!("{}/dart_event.dart", cache_dir);
|
||||||
|
match std::fs::OpenOptions::new()
|
||||||
|
.create(true)
|
||||||
|
.write(true)
|
||||||
|
.append(false)
|
||||||
|
.truncate(true)
|
||||||
|
.open(&dart_event_file_path)
|
||||||
|
{
|
||||||
|
Ok(ref mut file) => {
|
||||||
|
file.write_all(render_result.as_bytes()).unwrap();
|
||||||
|
File::flush(file).unwrap();
|
||||||
|
}
|
||||||
|
Err(_err) => {
|
||||||
|
panic!("Failed to open file: {}", dart_event_file_path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,8 +59,8 @@ impl DartEventCrate {
|
||||||
|
|
||||||
pub fn parse_dart_event_files(crate_paths: Vec<String>) -> Vec<DartEventCrate> {
|
pub fn parse_dart_event_files(crate_paths: Vec<String>) -> Vec<DartEventCrate> {
|
||||||
let mut dart_event_crates: Vec<DartEventCrate> = vec![];
|
let mut dart_event_crates: Vec<DartEventCrate> = vec![];
|
||||||
crate_paths.iter().for_each(|root| {
|
crate_paths.iter().for_each(|path| {
|
||||||
let crates = WalkDir::new(root)
|
let crates = WalkDir::new(path)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_entry(|e| !is_hidden(e))
|
.filter_entry(|e| !is_hidden(e))
|
||||||
.filter_map(|e| e.ok())
|
.filter_map(|e| e.ok())
|
||||||
|
|
|
@ -153,9 +153,8 @@ fn run_command(cmd: &str) -> bool {
|
||||||
|
|
||||||
#[cfg(feature = "proto_gen")]
|
#[cfg(feature = "proto_gen")]
|
||||||
fn gen_protos(crate_name: &str) -> Vec<ProtobufCrate> {
|
fn gen_protos(crate_name: &str) -> Vec<ProtobufCrate> {
|
||||||
let cache_path = env!("CARGO_MANIFEST_DIR");
|
let crate_path = std::fs::canonicalize(".").unwrap().as_path().display().to_string();
|
||||||
let root = std::fs::canonicalize(".").unwrap().as_path().display().to_string();
|
let crate_context = ProtoGenerator::gen(crate_name, &crate_path);
|
||||||
let crate_context = ProtoGenerator::gen(crate_name, &root, cache_path);
|
|
||||||
let proto_crates = crate_context
|
let proto_crates = crate_context
|
||||||
.iter()
|
.iter()
|
||||||
.map(|info| info.protobuf_crate.clone())
|
.map(|info| info.protobuf_crate.clone())
|
||||||
|
|
|
@ -12,7 +12,7 @@ use std::{fs::OpenOptions, io::Write};
|
||||||
|
|
||||||
pub struct ProtoGenerator();
|
pub struct ProtoGenerator();
|
||||||
impl ProtoGenerator {
|
impl ProtoGenerator {
|
||||||
pub fn gen(crate_name: &str, crate_path: &str, cache_path: &str) -> Vec<ProtobufCrateContext> {
|
pub fn gen(crate_name: &str, crate_path: &str) -> Vec<ProtobufCrateContext> {
|
||||||
let crate_contexts = parse_crate_protobuf(vec![crate_path.to_owned()]);
|
let crate_contexts = parse_crate_protobuf(vec![crate_path.to_owned()]);
|
||||||
write_proto_files(&crate_contexts);
|
write_proto_files(&crate_contexts);
|
||||||
write_rust_crate_mod_file(&crate_contexts);
|
write_rust_crate_mod_file(&crate_contexts);
|
||||||
|
@ -24,7 +24,7 @@ impl ProtoGenerator {
|
||||||
|
|
||||||
let cache = ProtoCache::from_crate_contexts(&crate_contexts);
|
let cache = ProtoCache::from_crate_contexts(&crate_contexts);
|
||||||
let cache_str = serde_json::to_string(&cache).unwrap();
|
let cache_str = serde_json::to_string(&cache).unwrap();
|
||||||
let cache_dir = format!("{}/.cache/{}", cache_path, crate_name);
|
let cache_dir = format!("{}/{}", cache_dir(), crate_name);
|
||||||
if !Path::new(&cache_dir).exists() {
|
if !Path::new(&cache_dir).exists() {
|
||||||
std::fs::create_dir_all(&cache_dir).unwrap();
|
std::fs::create_dir_all(&cache_dir).unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
@ -152,3 +152,7 @@ pub fn get_tera(directory: &str) -> Tera {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn cache_dir() -> String {
|
||||||
|
format!("{}/.cache", env!("CARGO_MANIFEST_DIR"))
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue