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
2023-06-06 01:58:54 -07:00

74 lines
2.4 KiB
Bash

#!/bin/bash
# create_component.sh componentName
# 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
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 admin/services
mkdir -p admin/src/Controller admin/src/View/${name^} admin/tmpl/${name}
# Source the files for generating component files
source "$script_dir/component_parts/manifest.sh"
source "$script_dir/component_parts/language.sh"
source "$script_dir/component_parts/provider.sh"
source "$script_dir/component_parts/displaycontroller.sh"
source "$script_dir/component_parts/view.sh"
source "$script_dir/component_parts/defaultview.sh"
echo "Component framework generated successfully!"
echo "You should manually edit the manifest file before checkin"