From da73b0a29b9111b3dc99e28b49bc60b290e7ffcb Mon Sep 17 00:00:00 2001 From: Kate Goldenring Date: Fri, 12 May 2023 13:44:13 -0700 Subject: [PATCH] check for brew installation of templates Signed-off-by: Kate Goldenring --- crates/plugins/src/store.rs | 9 +++++++++ crates/templates/src/store.rs | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/crates/plugins/src/store.rs b/crates/plugins/src/store.rs index ad052b92b..01106c8f8 100644 --- a/crates/plugins/src/store.rs +++ b/crates/plugins/src/store.rs @@ -24,6 +24,15 @@ impl PluginStore { } pub fn try_default() -> Result { + if let Ok(brew_prefix) = std::env::var("HOMEBREW_PREFIX") { + let plugins_dir = Path::new(&brew_prefix).join("var/spin/plugins"); + + if plugins_dir.exists() && plugins_dir.is_dir() { + println!("Path to brew plugins exists"); + return Ok(Self::new(plugins_dir)); + // TODO: check if they also have plugins in non-brew default dir and warn + } + } let data_dir = match std::env::var("TEST_PLUGINS_DIRECTORY") { Ok(test_dir) => PathBuf::from(test_dir), Err(_) => dirs::data_local_dir() diff --git a/crates/templates/src/store.rs b/crates/templates/src/store.rs index b5f0722fd..783055b2c 100644 --- a/crates/templates/src/store.rs +++ b/crates/templates/src/store.rs @@ -20,6 +20,16 @@ impl TemplateStore { } pub(crate) fn try_default() -> anyhow::Result { + if let Ok(brew_prefix) = std::env::var("HOMEBREW_PREFIX") { + let templates_dir = Path::new(&brew_prefix).join("var/spin/templates"); + + if templates_dir.exists() && templates_dir.is_dir() { + println!("Path to brew templates exists"); + return Ok(Self::new(templates_dir)); + // TODO: check if they also have templates in non-brew default dir and warn + } + } + let data_dir = dirs::data_local_dir() .or_else(|| dirs::home_dir().map(|p| p.join(".spin"))) .ok_or_else(|| anyhow!("Unable to get local data directory or home directory"))?;