Working on component creator

This commit is contained in:
Nick Yeoman 2023-05-26 14:19:20 -07:00
parent 75689ca463
commit 2e56d220d3
9 changed files with 210 additions and 2 deletions

3
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,3 @@
{
"ansible.python.interpreterPath": "/bin/python3"
}

View File

@ -0,0 +1,16 @@
#!/bin/bash
cat <<EOM
<?php
defined('_JEXEC') or die;
use Joomla\CMS\MVC\Controller\AdminController;
class ${name^}Controller extends AdminController
{
public function __construct(\$config = array())
{
parent::__construct(\$config);
}
}
EOM

View File

@ -0,0 +1,16 @@
#!/bin/bash
cat <<EOM > admin_controller_base.php
<?php
defined('_JEXEC') or die;
use Joomla\CMS\MVC\Controller\Controller;
class ${name^}Controller extends Controller
{
public function __construct(\$config = array())
{
parent::__construct(\$config);
}
}
EOM

View File

@ -0,0 +1,71 @@
#!/bin/bash
current_date=$(date +'%B %Y')
# Check if JOOMLA_USER is set, otherwise prompt for it
if [ -z "$JOOMLA_USER" ]; then
read -p "Enter the Joomla user: " JOOMLA_USER
fi
# Check if EMAIL is set, otherwise prompt for it
if [ -z "$EMAIL" ]; then
read -p "Enter the email address: " EMAIL
fi
cat <<EOM > ${name}.xml
<?xml version="1.0" encoding="UTF-8"?>
<extension type="component" method="upgrade">
<name>com_${name}</name>
<!-- The following elements are optional and free of formatting conttraints -->
<creationDate>${current_date}</creationDate>
<author>${JOOMLA_USER}</author>
<authorEmail>${EMAIL}</authorEmail>
<authorUrl>https://www.example.com/</authorUrl>
<copyright>Copyright (C) 2023 ${JOOMLA_USER}, All rights reserved.</copyright>
<license>GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html</license>
<!-- The version string is recorded in the components table -->
<version>0.0.1</version>
<!-- The description is optional and defaults to the name -->
<description>COM_${name}_XML_DESCRIPTION</description>
<namespace path="src">J4xdemos\Component\${name#com_}</namespace>
<install> <!-- Runs on install -->
<sql>
<file driver="mysql" charset="utf8">sql/install.mysql.sql</file>
</sql>
</install>
<uninstall> <!-- Runs on uninstall -->
<sql>
<file driver="mysql" charset="utf8">sql/uninstall.mysql.sql</file>
</sql>
</uninstall>
<!-- Site Main File Copy Section -->
<!-- Note the folder attribute: This attribute describes the folder
to copy FROM in the package to install therefore files copied
in this section are copied from /site/ in the package -->
<files folder="site">
<folder>forms</folder>
<folder>language</folder>
<folder>src</folder>
<folder>tmpl</folder>
</files>
<administration>
<files folder="admin">
<file>access.xml</file>
<file>config.xml</file>
<folder>forms</folder>
<folder>language</folder>
<folder>services</folder>
<folder>sql</folder>
<folder>src</folder>
<folder>tmpl</folder>
</files>
<menu img="class:default" link="option=com_mywalks">com_mywalks</menu>
</administration>
</extension>
EOM

View File

@ -0,0 +1,16 @@
#!/bin/bash
cat <<EOM
<?php
defined('_JEXEC') or die;
use Joomla\CMS\MVC\Controller\BaseController;
class ${name^}Controller extends BaseController
{
public function __construct(\$config = array())
{
parent::__construct(\$config);
}
}
EOM

View File

@ -0,0 +1,16 @@
#!/bin/bash
cat <<EOM
<?php
defined('_JEXEC') or die;
use Joomla\CMS\MVC\Controller\Controller;
class ${name^}Controller extends Controller
{
public function __construct(\$config = array())
{
parent::__construct(\$config);
}
}
EOM

69
bin/create_component.sh Normal file
View File

@ -0,0 +1,69 @@
#!/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
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"

View File

@ -34,7 +34,7 @@ docker-compose exec -u www-data joomla php installation/joomla.php install \
--site-name=$PROJECTNAME \ --site-name=$PROJECTNAME \
--admin-email=$EMAIL \ --admin-email=$EMAIL \
--admin-user=$JOOMLA_USER \ --admin-user=$JOOMLA_USER \
--admin-username=$JOOMLA_USER \ --admin-username=$JOOMLA_USERNAME \
--admin-password=$JOOMLA_PASSWORD \ --admin-password=$JOOMLA_PASSWORD \
--db-type=mysqli \ --db-type=mysqli \
--db-host=mariadb \ --db-host=mariadb \

View File

@ -13,6 +13,7 @@ ACCESS_TOKEN=REPLACEME
# Joomla # Joomla
EMAIL=noreply@example.com EMAIL=noreply@example.com
JOOMLA_USER=admin JOOMLA_USER="John Doe"
JOOMLA_USERNAME=admin
# Passwords must be 12 characters long # Passwords must be 12 characters long
JOOMLA_PASSWORD=REPLACEME123 JOOMLA_PASSWORD=REPLACEME123