Skip to content

Commit

Permalink
Merge pull request #18 from Rynaro/chore/plugins/enhance-plugin-scaff…
Browse files Browse the repository at this point in the history
…olding

Enhance Plugin Creation
  • Loading branch information
Rynaro authored Jul 1, 2024
2 parents b31032a + ea938a3 commit b5a242e
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 60 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
!plugins.sh
!plugins/
!plugins/*.sh
!plugins/templates/
!plugins/templates/*.sh

# Allow the .potions directory and its contents
!.potions
Expand Down
60 changes: 2 additions & 58 deletions plugins/scaffold_plugin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,74 +16,18 @@ create_plugin() {
mkdir -p "$plugin_dir/packages"

# Create the blank install.sh script
cat <<EOL > "$plugin_dir/install.sh"
#!/bin/bash
PLUGIN_NAME="$plugin_name"
PLUGIN_VERSION="0.0.1"
PLUGIN_RELATIVE_FOLDER="$(dirname "$0")/$1"
# Function to prepare to install packages
prepare() {
# sudo apt update
}
# Function to install packages
install_packages() {
echo "Installing Plugin: $plugin_name..."
safe_source "packages/package1.sh"
bash "packages/package2.sh"
}
# Function to consolidate post-installation scripts
post_install() {
# Add your post install scripts
}
# Run pipeline
configure
install_packages
post_install
EOL
cat plugins/templates/install.sh > "$plugin_dir/install.sh"

# Create utilities.sh
cat plugins/utilities.sh > "$plugin_dir/utilities.sh"


# Create a blank package1.sh script
cat <<EOL > "$plugin_dir/packages/package1.sh"
#!/bin/bash
# Function to install package 1
install_package() {
echo "Installing package 1..."
# Installation commands for package 1
}
# Run installation
install_package
EOL

# Create a blank package2.sh script
cat <<EOL > "$plugin_dir/packages/package2.sh"
#!/bin/bash
# Function to install package 2
install_package() {
echo "Installing package 2..."
# Installation commands for package 2
}
# Run installation
install_package
EOL
cat plugins/templates/package1.sh > "$plugin_dir/packages/package1.sh"

# Make the scripts executable
chmod +x "$plugin_dir/install.sh"
chmod +x "$plugin_dir/utilities.sh"
chmod +x "$plugin_dir/packages/package1.sh"
chmod +x "$plugin_dir/packages/package2.sh"

echo "Plugin $plugin_name has been created at $plugin_dir"
}
29 changes: 29 additions & 0 deletions plugins/templates/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

PLUGIN_NAME="$plugin_name"
PLUGIN_VERSION="0.0.1"
PLUGIN_RELATIVE_FOLDER='$(dirname "$0")/"$1"'

# Source utilities script
source "$PLUGIN_RELATIVE_FOLDER/utilities.sh"

# Function to prepare to install packages
prepare() {
# update_repositories
}

# Function to install packages
install_packages() {
echo "Installing Plugin: $plugin_name..."
safe_source "packages/package1.sh"
}

# Function to consolidate post-installation scripts
post_install() {
# Add your post install scripts
}

# Run pipeline
configure
install_packages
post_install
25 changes: 25 additions & 0 deletions plugins/templates/package1.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

safe_source "utilities.sh"

MY_PREFERRED_PACKAGE_VERSION=1.0.0

prepare_package() {
# sudo apt install -y build-essentials
}

# Function to install package 1
install_package() {
echo "Installing package 1..."
# Installation commands for package 1
echo "Installing super cool package $MY_PREFERRED_PACKAGE_VERSION"
}

configure_package() {
# docker build ~/projects/super-duper-app
}

# Run installation
prepare_package
install_package
configure_package
16 changes: 14 additions & 2 deletions plugins/utilities.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

UTILITIES_VERSION=1.0.0
UTILITIES_VERSION=1.1.0

OS_TYPE="$(uname -s)"

Expand All @@ -17,7 +17,19 @@ update_repositories() {

# Function to check if a command exists
command_exists() {
command -v "$1" &> /dev/null
local cmd="$1"

# Check in bash
if command -v "$cmd" &> /dev/null; then
return 0
fi

# Check in zsh
if ZDOTDIR="$HOME/.potions" zsh -c "command -v $cmd" &> /dev/null; then
return 0
fi

return 1
}

# Function to safely source a script if it exists
Expand Down

0 comments on commit b5a242e

Please sign in to comment.