From 2e56d220d362be494c6beee08e558f6e0fa89e81 Mon Sep 17 00:00:00 2001 From: Nick Yeoman Date: Fri, 26 May 2023 14:19:20 -0700 Subject: [PATCH] Working on component creator --- .vscode/settings.json | 3 + bin/component_parts/admin_controller.sh | 16 +++++ bin/component_parts/admin_controller_base.sh | 16 +++++ bin/component_parts/manifest.sh | 71 ++++++++++++++++++++ bin/component_parts/site_controller.sh | 16 +++++ bin/component_parts/site_controller_base.sh | 16 +++++ bin/create_component.sh | 69 +++++++++++++++++++ bin/setup_joomla_installer.sh | 2 +- env.sample | 3 +- 9 files changed, 210 insertions(+), 2 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 bin/component_parts/admin_controller.sh create mode 100644 bin/component_parts/admin_controller_base.sh create mode 100644 bin/component_parts/manifest.sh create mode 100644 bin/component_parts/site_controller.sh create mode 100644 bin/component_parts/site_controller_base.sh create mode 100644 bin/create_component.sh diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..5d71af8 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "ansible.python.interpreterPath": "/bin/python3" +} \ No newline at end of file diff --git a/bin/component_parts/admin_controller.sh b/bin/component_parts/admin_controller.sh new file mode 100644 index 0000000..44ccdbd --- /dev/null +++ b/bin/component_parts/admin_controller.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +cat < admin_controller_base.php + ${name}.xml + + + com_${name} + + ${current_date} + ${JOOMLA_USER} + ${EMAIL} + https://www.example.com/ + Copyright (C) 2023 ${JOOMLA_USER}, All rights reserved. + GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html + + 0.0.1 + + COM_${name}_XML_DESCRIPTION + J4xdemos\Component\${name#com_} + + + + sql/install.mysql.sql + + + + + sql/uninstall.mysql.sql + + + + + + + + forms + language + src + tmpl + + + + + access.xml + config.xml + forms + language + services + sql + src + tmpl + + com_mywalks + + +EOM + + \ No newline at end of file diff --git a/bin/component_parts/site_controller.sh b/bin/component_parts/site_controller.sh new file mode 100644 index 0000000..9bfbc5b --- /dev/null +++ b/bin/component_parts/site_controller.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +cat </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 admin + +# Source the files for generating component files +# 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" +source "$script_dir/component_parts/manifest.sh" + +echo "Component framework generated successfully!" +echo "You should manually edit the manifest file before checkin" + diff --git a/bin/setup_joomla_installer.sh b/bin/setup_joomla_installer.sh index 03bbda4..c55645b 100644 --- a/bin/setup_joomla_installer.sh +++ b/bin/setup_joomla_installer.sh @@ -34,7 +34,7 @@ docker-compose exec -u www-data joomla php installation/joomla.php install \ --site-name=$PROJECTNAME \ --admin-email=$EMAIL \ --admin-user=$JOOMLA_USER \ - --admin-username=$JOOMLA_USER \ + --admin-username=$JOOMLA_USERNAME \ --admin-password=$JOOMLA_PASSWORD \ --db-type=mysqli \ --db-host=mariadb \ diff --git a/env.sample b/env.sample index f145290..6fcc4d9 100644 --- a/env.sample +++ b/env.sample @@ -13,6 +13,7 @@ ACCESS_TOKEN=REPLACEME # Joomla EMAIL=noreply@example.com -JOOMLA_USER=admin +JOOMLA_USER="John Doe" +JOOMLA_USERNAME=admin # Passwords must be 12 characters long JOOMLA_PASSWORD=REPLACEME123 \ No newline at end of file