3 Commits

Author SHA1 Message Date
edc01a5372 Add extends interface. 2024-06-05 15:49:59 +02:00
ed1cd4fffa Skip comments in loadPower function
A new condition has been added to the loadPower function in src/octopower to identify and skip lines that start with //, which are treated as comments. Previously, the function validated and processed all lines without filtering out comments.
2024-06-03 18:15:45 +02:00
223c972795 Add link to classes where dependencies are. Add composer setup instructions. 2024-05-23 10:48:48 +02:00

View File

@ -3,7 +3,7 @@
# Program name # Program name
PROGRAM_NAME="OctoPower" PROGRAM_NAME="OctoPower"
PROGRAM_CODE="octopower" PROGRAM_CODE="octopower"
PROGRAM_VERSION="1.0.0" PROGRAM_VERSION="1.0.1"
PROGRAM_V="1.0" PROGRAM_V="1.0"
PROGRAM_URL="https://git.vdm.dev/octoleo/${PROGRAM_CODE}" PROGRAM_URL="https://git.vdm.dev/octoleo/${PROGRAM_CODE}"
@ -228,7 +228,9 @@ function setPowers() {
# load the power # load the power
function loadPower() { function loadPower() {
local guid="$1" local guid="$1"
if [ ${#guid} -ge 30 ] && validateGuid "${guid}"; then if [[ $guid == "//"* ]]; then
return 0 # skip comments ;)
elif [ ${#guid} -ge 30 ] && validateGuid "${guid}"; then
setPower "$guid" || return 19 setPower "$guid" || return 19
loadChildrenPowers "$guid" || return 19 loadChildrenPowers "$guid" || return 19
return 0 return 0
@ -263,7 +265,9 @@ function loadChildrenPowers() {
local has_error local has_error
local children_loaded local children_loaded
# some local vars # some local vars
local guids
local extends local extends
local extends_interfaces
local implements local implements
local use_selection local use_selection
local load_selection local load_selection
@ -288,6 +292,7 @@ function loadChildrenPowers() {
addValueToPower "${guid}" 'children' "done" addValueToPower "${guid}" 'children' "done"
# get the global config values if not set # get the global config values if not set
setValueFromJson 'VDM_POWER_DATA' '.data' "${power}" || has_error=true setValueFromJson 'VDM_POWER_DATA' '.data' "${power}" || has_error=true
setValueFromJson 'VDM_POWER_USE_NAME' '.use_name' "${power}" || has_error=true
# could we get the data # could we get the data
if $has_error; then if $has_error; then
_echo "[error] We could not get power data for ${guid} so the dependencies could not be loaded." _echo "[error] We could not get power data for ${guid} so the dependencies could not be loaded."
@ -299,23 +304,32 @@ function loadChildrenPowers() {
power_data="${VDM_POWER_DATA}" power_data="${VDM_POWER_DATA}"
# get th values if set # get th values if set
setValueFromJson 'VDM_POWER_EXTENDS' '.extends' "${power_data}" setValueFromJson 'VDM_POWER_EXTENDS' '.extends' "${power_data}"
setValueFromJson 'VDM_POWER_EXTENDS_INTERFACES' '.extendsinterfaces' "${power_data}"
setValueFromJson 'VDM_POWER_IMPLEMENTS' '.implements' "${power_data}" setValueFromJson 'VDM_POWER_IMPLEMENTS' '.implements' "${power_data}"
setValueFromJson 'VDM_POWER_USE_SELECTION' '.use_selection' "${power_data}" setValueFromJson 'VDM_POWER_USE_SELECTION' '.use_selection' "${power_data}"
setValueFromJson 'VDM_POWER_LOAD_SELECTION' '.load_selection' "${power_data}" setValueFromJson 'VDM_POWER_LOAD_SELECTION' '.load_selection' "${power_data}"
setValueFromJson 'VDM_POWER_HEAD' '.head' "${power_data}" setValueFromJson 'VDM_POWER_HEAD' '.head' "${power_data}"
# extract any joomla dependencies we might find # extract any joomla dependencies we might find
extractJoomlaUseStatements "${VDM_POWER_HEAD:-none}" extractJoomlaUseStatements "${VDM_POWER_HEAD:-none}" "${VDM_POWER_USE_NAME}"
# TODO add more dynamic options # TODO add more dynamic options
# setValueFromJson 'VDM_POWER_COMPOSER' '.composer' "${power_data}" # setValueFromJson 'VDM_POWER_COMPOSER' '.composer' "${power_data}"
# check if we have VDM_POWER_EXTENDS # check if we have VDM_POWER_EXTENDS
# we must add these locally to avoid collusion # we must add these locally to avoid collusion
extends="${VDM_POWER_EXTENDS:-0}" extends="${VDM_POWER_EXTENDS:-0}"
extends_interfaces="${VDM_POWER_EXTENDS_INTERFACES:-null}"
implements="${VDM_POWER_IMPLEMENTS:-null}" implements="${VDM_POWER_IMPLEMENTS:-null}"
use_selection="${VDM_POWER_USE_SELECTION:-null}" use_selection="${VDM_POWER_USE_SELECTION:-null}"
load_selection="${VDM_POWER_LOAD_SELECTION:-null}" load_selection="${VDM_POWER_LOAD_SELECTION:-null}"
if [ "${extends}" != "0" ]; then if [ "${extends}" != "0" ]; then
loadPower "${extends}" loadPower "${extends}"
fi fi
# Process the JSON array in extends_interfaces if it's not empty or null
if [ "${extends_interfaces}" != "null" ]; then
guids=$(echo "${extends_interfaces}" | jq -r '.[]')
for guid in $guids; do
loadPower "$guid"
done
fi
# Process the JSON array in implements if it's not empty or null # Process the JSON array in implements if it's not empty or null
if [ "${implements}" != "null" ]; then if [ "${implements}" != "null" ]; then
guids=$(echo "${implements}" | jq -r '.[]') guids=$(echo "${implements}" | jq -r '.[]')
@ -479,6 +493,7 @@ function setPowerData() {
local settings local settings
local namespace local namespace
local name local name
local use_name
# get existing power # get existing power
power=$(getExistingPower "${guid}") power=$(getExistingPower "${guid}")
if [ -z "$power" ]; then if [ -z "$power" ]; then
@ -524,6 +539,7 @@ function setPowerData() {
settings="${VDM_POWER_SETTINGS_URL}" settings="${VDM_POWER_SETTINGS_URL}"
namespace="${VDM_POWER_NAMESPACE}" namespace="${VDM_POWER_NAMESPACE}"
name="${VDM_POWER_NAME}" name="${VDM_POWER_NAME}"
use_name="${VDM_POWER_NAMESPACE}\\${VDM_POWER_NAME}"
# little information of progress # little information of progress
_echo "[info] Getting (${namespace}\\${name}) power (${guid}) details." _echo "[info] Getting (${namespace}\\${name}) power (${guid}) details."
# we first load the settings data # we first load the settings data
@ -537,6 +553,7 @@ function setPowerData() {
# check that we got data # check that we got data
if [ -n "${VDM_API_BUCKET}" ]; then if [ -n "${VDM_API_BUCKET}" ]; then
addJsonValueToPower "${guid}" 'data' "${VDM_API_BUCKET}" addJsonValueToPower "${guid}" 'data' "${VDM_API_BUCKET}"
addValueToPower "${guid}" 'use_name' "${use_name}"
else else
# always clear memory # always clear memory
clearPowerDataEnv clearPowerDataEnv
@ -698,6 +715,7 @@ function addNamespace() {
# extract Joomla use statements # extract Joomla use statements
function extractJoomlaUseStatements() { function extractJoomlaUseStatements() {
local header_string="$1" local header_string="$1"
local use_name="$2"
# Check if the header string is empty # Check if the header string is empty
if [[ -z "$header_string" ]]; then if [[ -z "$header_string" ]]; then
return return
@ -715,14 +733,28 @@ function extractJoomlaUseStatements() {
# shellcheck disable=SC1003 # shellcheck disable=SC1003
extracted_namespace=$(echo "$namespace" | awk -F'\\' '{print $1 "\\" $2}') extracted_namespace=$(echo "$namespace" | awk -F'\\' '{print $1 "\\" $2}')
JOOMLA_FRAMEWORK["$extracted_namespace"]=1 JOOMLA_FRAMEWORK["$extracted_namespace"]=1
setLinkedDependencyClasses "${extracted_namespace}" "${use_name//\\//}" "${use_name}"
else else
# Add the namespace to the associative array # Add the namespace to the associative array
JOOMLA_NAMESPACES["$namespace"]=1 JOOMLA_NAMESPACES["$namespace"]=1
setLinkedDependencyClasses "${namespace}" "${use_name//\\//}" "${use_name}"
fi fi
fi fi
done <<< "$header_string" done <<< "$header_string"
} }
# set the linked classes to the dependencies
function setLinkedDependencyClasses() {
local main_key="$1"
local sub_key="$2"
local value="$3"
# Use jq to update the JSON structure
VDM_LINKED_CLASSES=$(echo "$VDM_LINKED_CLASSES" | jq --arg mk "$main_key" --arg sk "$sub_key" --arg val "$value" '
.[$mk][$sk] = $val
')
}
# just to clear all file ENVs # just to clear all file ENVs
function clearPowerEnv() { function clearPowerEnv() {
# SET IN: loadPowerRepositories # SET IN: loadPowerRepositories
@ -760,6 +792,7 @@ function clearPowerChildrenEnv() {
unset VDM_POWER_LOAD_SELECTION unset VDM_POWER_LOAD_SELECTION
unset VDM_POWER_USE_SELECTION unset VDM_POWER_USE_SELECTION
unset VDM_POWER_HEAD unset VDM_POWER_HEAD
unset VDM_POWER_USE_NAME
unset VDM_POWER_COMPOSER unset VDM_POWER_COMPOSER
} }
@ -1088,19 +1121,6 @@ function getJoomlaFrameworkRequired() {
echo -n "$json" echo -n "$json"
} }
# Convert JOOMLA_NAMESPACES to a Markdown list
function getJoomlaDependencies() {
if [ ${#JOOMLA_NAMESPACES[@]} -eq 0 ]; then
echo -n ""
else
local markdown_list="\n## Joomla CMS Dependencies\n\n"
markdown_list+=$(for key in "${!JOOMLA_NAMESPACES[@]}"; do
echo "- ${key}"
done | sort)
echo -e "$markdown_list\n"
fi
}
# Convert JOOMLA_FRAMEWORK to a Markdown list # Convert JOOMLA_FRAMEWORK to a Markdown list
function getJoomlaFramework() { function getJoomlaFramework() {
if [ ${#JOOMLA_FRAMEWORK[@]} -eq 0 ]; then if [ ${#JOOMLA_FRAMEWORK[@]} -eq 0 ]; then
@ -1108,17 +1128,49 @@ function getJoomlaFramework() {
else else
local markdown_list="\n## Joomla Framework Dependencies\n\n" local markdown_list="\n## Joomla Framework Dependencies\n\n"
if [ -z "${VDM_PACKAGE_JOOMLA_FRAMEWORK}" ]; then if [ -z "${VDM_PACKAGE_JOOMLA_FRAMEWORK}" ]; then
markdown_list+=">You can add the following to your project to insure the Joomla! framework classes are in your project.\n\n" markdown_list+=">You should add the following to your project to ensure the Joomla! framework classes are included.\n\n"
for key in $(printf "%s\n" "${!JOOMLA_FRAMEWORK[@]}" | sort); do
markdown_list+="- \`composer require ${key//\\//} \"${VDM_PACKAGE_JOOMLA_FRAMEWORK:-~3.0}\"\`\n";
markdown_list+=$(getLinkedClassesMarkdown "${key}");
markdown_list+="\n";
done
else else
markdown_list+=">We have added the following framework classes the required list of this composer package.\n\n" markdown_list+=">We have added the following framework classes to the required list of this Composer package.\n\n"
for key in $(printf "%s\n" "${!JOOMLA_FRAMEWORK[@]}" | sort); do
markdown_list+="- ${key//\\//} \"${VDM_PACKAGE_JOOMLA_FRAMEWORK:-~3.0}\"\n";
markdown_list+=$(getLinkedClassesMarkdown "${key}");
markdown_list+="\n";
done
fi fi
markdown_list+=$(for key in "${!JOOMLA_FRAMEWORK[@]}"; do echo -e "$markdown_list"
echo "- \`composer require ${key//\\//} \"${VDM_PACKAGE_JOOMLA_FRAMEWORK:-~3.0}\"\`"
done | sort)
echo -e "$markdown_list\n"
fi fi
} }
# Convert JOOMLA_NAMESPACES to a Markdown list
function getJoomlaDependencies() {
if [ ${#JOOMLA_NAMESPACES[@]} -eq 0 ]; then
echo -n ""
else
local markdown_list="\n## Joomla CMS Dependencies\n\n"
for key in $(printf "%s\n" "${!JOOMLA_NAMESPACES[@]}" | sort); do
markdown_list+="- ${key}\n";
markdown_list+=$(getLinkedClassesMarkdown "${key}");
markdown_list+="\n";
done
echo -e "$markdown_list"
fi
}
# get the classes linked to this dependency
function getLinkedClassesMarkdown() {
local dependency="$1"
local subset
# Extract the subset for the given main_key
subset=$(echo "$VDM_LINKED_CLASSES" | jq --arg mk "$dependency" '.[$mk] // {}')
# Generate the markdown format
echo "$subset" | jq -r 'to_entries[] | " - [\(.value)](src/\(.key).php)"'
}
# convert VDM_NAME to the desired header format # convert VDM_NAME to the desired header format
function convertToHeader() { function convertToHeader() {
local name="$1" local name="$1"
@ -1153,8 +1205,26 @@ function setReadMe() {
echo "- Packager: [${VDM_PACKAGER}](${VDM_PACKAGER_URL})" echo "- Packager: [${VDM_PACKAGER}](${VDM_PACKAGER_URL})"
echo "- Author: [${VDM_AUTHOR:-$PROGRAM_NAME}](${VDM_AUTHOR_URL:-$PROGRAM_URL})" echo "- Author: [${VDM_AUTHOR:-$PROGRAM_NAME}](${VDM_AUTHOR_URL:-$PROGRAM_URL})"
echo "- Creation Date: ${CREATION_DATE}" echo "- Creation Date: ${CREATION_DATE}"
getJoomlaDependencies echo ""
echo "### Installation via Composer"
echo ""
echo "Setup this registry in your \`~/.composer/config.json\` file:"
echo "\`\`\`"
echo "{"
echo " \"repositories\": [{"
echo " \"type\": \"composer\","
echo " \"url\": \"https://${VDM_REPOSITORY_URL}/api/packages/${VDM_REPOSITORY_OWNER}/composer\""
echo " }"
echo " ]"
echo "}"
echo "\`\`\`"
echo ""
echo "To install the package using Composer, run the following command:"
echo "\`\`\`"
echo "composer require ${VDM_NAME:-error}:${VDM_PACKAGE_VERSION:-1.0.0}"
echo "\`\`\`"
getJoomlaFramework getJoomlaFramework
getJoomlaDependencies
echo "" echo ""
echo "### License" echo "### License"
echo "> ${VDM_LICENSE:-none}" echo "> ${VDM_LICENSE:-none}"
@ -1217,8 +1287,6 @@ function setRepository() {
if $update_repo && [[ -z $(git status --porcelain) ]]; then if $update_repo && [[ -z $(git status --porcelain) ]]; then
_echo "[info] No changes found in (${VDM_REPOSITORY_OWNER}/${VDM_REPOSITORY_REPO}) repository" _echo "[info] No changes found in (${VDM_REPOSITORY_OWNER}/${VDM_REPOSITORY_REPO}) repository"
else else
# add user details
setUserDetails
# check if we must update or create repository # check if we must update or create repository
if $update_repo; then if $update_repo; then
# make API call # make API call
@ -1231,6 +1299,8 @@ function setRepository() {
else else
message="Update" message="Update"
fi fi
# add user details
setUserDetails
# get the repository last tag # get the repository last tag
makeGitCommit "${message}" "${VDM_PACKAGE_VERSION:-1.0.0}" "$VDM_TAG_EXIST" || return 28 makeGitCommit "${message}" "${VDM_PACKAGE_VERSION:-1.0.0}" "$VDM_TAG_EXIST" || return 28
# give little notice of progress # give little notice of progress
@ -1289,6 +1359,8 @@ function setGitRepository() {
_echo "[info] Initializing the (${VDM_REPOSITORY_OWNER}/${VDM_REPOSITORY_REPO}) repository" _echo "[info] Initializing the (${VDM_REPOSITORY_OWNER}/${VDM_REPOSITORY_REPO}) repository"
# initialize the repository # initialize the repository
git init >/dev/null 2>&1 || return 29 git init >/dev/null 2>&1 || return 29
# add user details
setUserDetails
# add the first commit # add the first commit
makeGitCommit "First Commit - ${VDM_PACKAGE_VERSION:-1.0.0}" "${VDM_PACKAGE_VERSION:-1.0.0}" >/dev/null 2>&1 || return 28 makeGitCommit "First Commit - ${VDM_PACKAGE_VERSION:-1.0.0}" "${VDM_PACKAGE_VERSION:-1.0.0}" >/dev/null 2>&1 || return 28
# little information of progress # little information of progress
@ -1740,6 +1812,7 @@ fi
# Global array to store Joomla namespaces # Global array to store Joomla namespaces
declare -A JOOMLA_NAMESPACES declare -A JOOMLA_NAMESPACES
declare -A JOOMLA_FRAMEWORK declare -A JOOMLA_FRAMEWORK
VDM_LINKED_CLASSES=$(jq -n '{}')
# if path not set try $PWD path (so you can open a folder that has .octopc file and it will be loaded) # if path not set try $PWD path (so you can open a folder that has .octopc file and it will be loaded)
tmp_path="$PWD/.${PROGRAM_CODE}" tmp_path="$PWD/.${PROGRAM_CODE}"