This repository has been archived on 2024-08-08. You can view files and clone it, but cannot push or open issues or pull requests.
joomla/bin/create_component.sh

73 lines
2.4 KiB
Bash
Raw Normal View History

2023-05-26 14:19:20 -07:00
#!/bin/bash
# Determine the directory where the script is located
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
#################################################################################
# ENV File
#################################################################################
# Import variables from .env file
if [ -f "$script_dir/../.env" ]; then
2023-05-26 14:19:20 -07:00
read -p "Found .env file at '$script_dir/.env'. Press Enter to use it, or enter a different file path: " env_file
if [ -z "$env_file" ]; then
env_file="$script_dir/.env"
fi
else
read -p "Enter the path to the .env file: " env_file
fi
# Validate the .env file path
if [ ! -f "$env_file" ]; then
echo "Invalid .env file path. Please make sure the file exists."
exit 1
fi
# Source the variables from the .env file
source "$env_file"
echo "Variables from .env file imported successfully!"
#################################################################################
# Component Name
#################################################################################
# Check if the component name is provided as the first parameter
if [ -n "$1" ]; then
name="$1"
else
# Prompt for the name of the component
read -p "Enter the name of the component (one word in lowercase): " name
fi
# Validate the component name
if [[ ! "$name" =~ ^[a-z0-9_]+$ ]]; then
echo "Invalid component name. The name should be one word in lowercase with no spaces or special characters."
exit 1
fi
#################################################################################
# Do the work
#################################################################################
# Create the component directory
component_dir="com_${name}"
mkdir -p "$component_dir"
# Create the main component files
cd "$component_dir" || exit
mkdir -p site
mkdir -p admin/language/en-GB
2023-05-26 14:19:20 -07:00
# Source the files for generating component files
source "$script_dir/component_parts/manifest.sh"
source "$script_dir/component_parts/language.sh"
2023-05-26 14:19:20 -07:00
# source "$script_dir/component_parts/admin_controller.sh"
# source "$script_dir/component_parts/site_controller.sh"
# source "$script_dir/component_parts/site_controller_base.sh"
# source "$script_dir/component_parts/admin_controller_base.sh"
2023-05-26 14:19:20 -07:00
echo "Component framework generated successfully!"
echo "You should manually edit the manifest file before checkin"