-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
85e98fb
commit 2e07a73
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/bin/bash | ||
|
||
# Directory to store logs | ||
LOG_DIR="$HOME/.logs" | ||
mkdir -p "$LOG_DIR" | ||
|
||
# Log file for plugin loader | ||
LOG_FILE="$LOG_DIR/plugins-loader.log" | ||
|
||
# Start logging | ||
echo "Initializing plugins at $(date)" > "$LOG_FILE" | ||
|
||
# Iterate through all plugins | ||
for config in plugins/*/config.json; do | ||
plugin_dir=$(dirname "$config") | ||
plugin_name=$(basename "$plugin_dir") | ||
|
||
# Parse configuration | ||
script=$(jq -r '.script' "$config") | ||
dependencies=$(jq -r '.dependencies | .[]?' "$config" 2>/dev/null) | ||
|
||
echo "Loading plugin: $plugin_name" | tee -a "$LOG_FILE" | ||
|
||
# Ensure the script is executable | ||
if [ -f "$plugin_dir/$script" ]; then | ||
chmod +x "$plugin_dir/$script" | ||
echo " Script set as executable: $plugin_dir/$script" | tee -a "$LOG_FILE" | ||
else | ||
echo " ERROR: Script $plugin_dir/$script not found!" | tee -a "$LOG_FILE" | ||
continue | ||
fi | ||
|
||
# Handle dependencies | ||
if [ -n "$dependencies" ]; then | ||
echo " Installing dependencies..." | tee -a "$LOG_FILE" | ||
for dep in $dependencies; do | ||
echo " Installing $dep" | tee -a "$LOG_FILE" | ||
# Example for npm packages: | ||
npm install -g "$dep" || { | ||
echo " ERROR: Failed to install $dep!" | tee -a "$LOG_FILE" | ||
} | ||
done | ||
fi | ||
|
||
# Execute an optional initialization step (if defined in the script) | ||
if [ -f "$plugin_dir/$script" ]; then | ||
"$plugin_dir/$script" init || echo " Optional init step failed for $plugin_name" | tee -a "$LOG_FILE" | ||
fi | ||
done | ||
|
||
echo "All plugins loaded successfully!" | tee -a "$LOG_FILE" |