Skip to content

Commit

Permalink
internal: Add events. (#188)
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Sep 10, 2023
1 parent 02af08d commit d3a4677
Show file tree
Hide file tree
Showing 9 changed files with 194 additions and 42 deletions.
47 changes: 24 additions & 23 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ serde = { workspace = true }
serde_json = { workspace = true }
sha2 = { workspace = true }
starbase_archive = { workspace = true }
starbase_events = "0.2.1"
starbase_styles = { workspace = true }
starbase_utils = { workspace = true, features = ["fs-lock"] }
thiserror = { workspace = true }
Expand Down
50 changes: 50 additions & 0 deletions crates/core/src/events.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
use crate::version::*;
use starbase_events::Event;

macro_rules! impl_event {
($name:ident, $impl:tt) => {
impl_event!($name, (), $impl);
};

($name:ident, $data:ty, $impl:tt) => {
pub struct $name $impl

impl Event for $name {
type Data = $data;
}
};
}

impl_event!(InstallingEvent, {
pub version: AliasOrVersion,
});

impl_event!(InstalledEvent, {
pub version: AliasOrVersion,
});

impl_event!(InstalledGlobalEvent, {
pub dependency: String,
});

impl_event!(UninstallingEvent, {
pub version: AliasOrVersion,
});

impl_event!(UninstalledEvent, {
pub version: AliasOrVersion,
});

impl_event!(UninstalledGlobalEvent, {
pub dependency: String,
});

impl_event!(CreatedShimsEvent, {
pub global: Vec<String>,
pub local: Vec<String>,
});

impl_event!(ResolvedVersionEvent, {
pub candidate: VersionType,
pub version: AliasOrVersion,
});
2 changes: 2 additions & 0 deletions crates/core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod error;
mod events;
mod helpers;
mod proto;
mod shimmer;
Expand All @@ -12,6 +13,7 @@ mod version_detector;
mod version_resolver;

pub use error::*;
pub use events::*;
pub use extism::{manifest::Wasm, Manifest as PluginManifest};
pub use helpers::*;
pub use proto::*;
Expand Down
13 changes: 13 additions & 0 deletions crates/core/src/proto.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::helpers::{get_home_dir, get_proto_home};
use once_cell::sync::OnceCell;
use std::env;
use std::path::{Path, PathBuf};
use warpgate::PluginLoader;

#[derive(Clone, Debug)]
pub struct ProtoEnvironment {
Expand All @@ -11,6 +13,8 @@ pub struct ProtoEnvironment {
pub tools_dir: PathBuf,
pub home: PathBuf, // ~
pub root: PathBuf, // ~/.proto

loader: OnceCell<PluginLoader>,
}

impl ProtoEnvironment {
Expand All @@ -36,6 +40,15 @@ impl ProtoEnvironment {
tools_dir: root.join("tools"),
home: get_home_dir()?,
root: root.to_owned(),
loader: OnceCell::new(),
})
}

pub fn get_plugin_loader(&self) -> &PluginLoader {
self.loader.get_or_init(|| {
let mut loader = PluginLoader::new(&self.plugins_dir, &self.temp_dir);
loader.set_seed(env!("CARGO_PKG_VERSION"));
loader
})
}
}
Expand Down
Loading

0 comments on commit d3a4677

Please sign in to comment.