crate_config.rs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. use crate::config::FlowyConfig;
  2. pub struct CrateConfig {
  3. pub(crate) crate_path: String,
  4. pub(crate) folder_name: String,
  5. pub(crate) flowy_config: FlowyConfig,
  6. }
  7. impl CrateConfig {
  8. pub fn proto_paths(&self) -> Vec<String> {
  9. let proto_paths = self
  10. .flowy_config
  11. .proto_crates
  12. .iter()
  13. .map(|name| format!("{}/{}", self.crate_path, name))
  14. .collect::<Vec<String>>();
  15. proto_paths
  16. }
  17. }
  18. pub fn parse_crate_config_from(entry: &walkdir::DirEntry) -> Option<CrateConfig> {
  19. let path = entry.path().parent().unwrap();
  20. let crate_path = path.to_str().unwrap().to_string();
  21. let folder_name = path.file_stem().unwrap().to_str().unwrap().to_string();
  22. let config_path = format!("{}/Flowy.toml", crate_path);
  23. if !std::path::Path::new(&config_path).exists() {
  24. return None;
  25. }
  26. let flowy_config = FlowyConfig::from_toml_file(config_path.as_ref());
  27. Some(CrateConfig {
  28. crate_path,
  29. folder_name,
  30. flowy_config,
  31. })
  32. }