Skip to content

Commit

Permalink
feat (symfony): #15 migration symfony setup environment
Browse files Browse the repository at this point in the history
- Efde.Tasks
  - Generic element to manage the installation of any environment
- Symfony.Tasks
  - New projects
  - Cloning of existing project
  - PHP, Symfony, Webapp version selection
- Docker.Tasks: basic service management
  - General common task settings
  - Add common.tasks.command_line
  - Add common.tasks.env_variable
  - Fix core
  - Fix common.tasks.menu
  - Fix common.tasks.messages
  - Fix generals
  • Loading branch information
mmaximo33 committed Jan 7, 2024
1 parent db6aa05 commit bec6901
Show file tree
Hide file tree
Showing 33 changed files with 698 additions and 160 deletions.
60 changes: 26 additions & 34 deletions bin/efde.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
#!/usr/bin/env bash
set -euo pipefail
# Debug mode
EFDE_MOD_DEBUG=true # Messages debug
EFDE_MOD_DEBUG=false # Messages debug
EFDE_MOD_DEV=true # MMTodo: Prepared for create tmps
EFDE_CFG_SHOW_CLI=true #show COMMANDLINE
declare -gA GLOBAL_EFDE_CONFIG=(
[CLI_SHOW_DEFAULT]=true # Omite configuraciones personalizadas
[CLI_SHOW_CLI]=true #
[CLI_SHOW_OUTPUT]=false
)


GLOBAL_RUN_EFDE=$([ "$EFDE_MOD_DEBUG" = "true" ] && echo "e2" || echo "efde")

[[ $(echo "$@" | grep -oP '(?<=--debug=)[^ ]+') = "true" && "$EFDE_MOD_DEBUG" = "false" ]] && EFDE_MOD_DEBUG=true

Expand All @@ -15,17 +24,15 @@ resolve_absolute_dir()
SOURCE="$(readlink ${SOURCE})"
[[ ${SOURCE} != /* ]] && SOURCE="${DIR}/${SOURCE}" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done

ABSOLUTE_BIN_PATH="$( cd -P "$( dirname ${SOURCE} )" && pwd )"
ABSOLUTE_PATH="${ABSOLUTE_BIN_PATH}/.."
EFDE_PATH_INSTALL="$(dirname $ABSOLUTE_BIN_PATH)"
}


init_dirs()
{
resolve_absolute_dir
export DOCKERGENTO_DIR="${ABSOLUTE_PATH}"

export PATH_CONSOLE="${EFDE_PATH_INSTALL}/console"
export PATH_BIN="${EFDE_PATH_INSTALL}/bin"

Expand All @@ -37,41 +44,26 @@ init_dirs()
init_dirs
source "$PATH_CONSOLE/init"



main(){
if efde.tasks.implemention.has_folder_implementation ; then
#ES SYMFONY CARGA MENU
echo "symfony"
else
menu_init
fi
menu_main(){
common.tasks.menu.print_menu "Select an option:" "${efde_props_menu_MAIN[@]}"
}

menu_init(){

#IFS=',' read -ra elements <<< "${ALL_MENUS["MENU_INIT"]}"
#
#for element in "${elements[@]}"; do
# echo "$element"
#done
#common.tasks.menu.print_menu "Select an option:" "${ALL_MENUS["MENU_INIT"][@]}"
common.tasks.menu.print_menu "Select an option:" "${MENU_INIT[@]}"
RESPONSE_CODE=${MENU_RESPONSE_ARRAY_ASOCITIVE['code']}
RESPONSE_TITLE=${MENU_RESPONSE_ARRAY_ASOCITIVE['title']}
menu_implementation(){
local PATH_ENV=$(efde.tasks.implemention.get_current_path_env_file)
variables_string="$(efde.tasks.config.load_variables_from_file ${PATH_ENV})"
# Evaluar la cadena de variables
eval "$variables_string"
RUN_FUNCTION_IMPLEMENTATION_MAIN= "$IMPLEMENTION.tasks.menu.main"

efde.tasks.implemention.setup_environment $RESPONSE_CODE
exit;
if common.tasks.module.exists_function "$RESPONSE_CODE.tasks.install.environment" ;then
efde.tasks.implemention.setup_environment $RESPONSE_CODE
else
common.tasks.message.danger "The installation of the selected environment is not yet available '$RESPONSE_TITLE'"
${RUN_FUNCTION_IMPLEMENTATION_MAIN}
}

common.tasks.prompt.confirm_default_yes "Back to menu?" && menu_init
fi
main(){
if ! efde.tasks.implemention.has_folder_implementation ; then
menu_main
fi
menu_implementation
}

main



80 changes: 43 additions & 37 deletions console/common/core
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,24 @@ _mod_.console_clear() {
clear
}

#_mod_.check_mode_debug() {
# [ "$EFDE_MOD_DEBUG" == "true" ] || [ "$EFDE_MOD_DEBUG" == "core" ]
#}

_mod_.msg_debug(){
local level="${2:-0}"
local end="${3:-0}"
local prefix=""

if [ "$level" -eq 1 ]; then
prefix+="├──"
fi
if [ "$level" -gt 1 ]; then
for ((i=1; i<level; i++)); do
prefix+=""
done
if [ "$end" -eq 0 ]; then
prefix+="├──"
else
prefix+="└──"
fi
fi

_mod_msg_print "$prefix $1" "debug"
_mod_.step(){
_mod_.msg_debug "#######################################################################"
_mod_.msg_debug "# LOAD MODULES "
_mod_.msg_debug "-----------------------------------------------------------------------"
}

_mod_msg_print(){
local color_start=""
local color_end=""
if [ "$2" == "debug" ]; then
_mod_.msg_debug() {
local level="${2:-0}"
local end="${3:-0}"
if _mod_.essential_run; then
common.tasks.msg.debug "$1" "$level" "$end"
else
if [ "$EFDE_MOD_DEBUG" = "true" ] ; then
local color_start="\033[1;35m"
local color_end="\033[0m"
fi

if [ "$EFDE_MOD_DEBUG" = "true" ] ; then
command printf "${color_start}$1${color_end}\n" 2>/dev/null
fi
command printf "${color_start}$1${color_end}\n" 2>/dev/null
fi
fi
}

_mod_.msg_danger(){
Expand All @@ -54,17 +35,31 @@ _mod_.msg_danger(){
fi
}

_mod_.load_common_msg(){
PATH_MODULE=$1
FILE="msg"
MODULE_NAME="common"
ELEMENT="tasks"
_mod_.replacemod --file-name="$FILE" --new-name="$MODULE_NAME.$ELEMENT.$FILE" --source-path="$PATH_MODULE/$ELEMENT/$FILE"
}

_mod_.essential_run() { type "common.tasks.msg.print" &> /dev/null; }

_mod_.load_module(){
# ESSENTIAL MODULE !!!!!
! _mod_.essential_run && _mod_.load_common_msg $1

local PATH_MODULE=$1
local elements=("props" "tasks")

_mod_.step
_mod_.msg_debug "Module: $MODULE_NAME" 1

for element in "${elements[@]}"; do
CHECK_PATH="$PATH_MODULE/$element"
if [ -d "$CHECK_PATH" ]; then
_mod_.msg_debug "Group: $element" 2
for file in $(ls -1 $CHECK_PATH); do
[ "$file" == "msg" ] && continue
_mod_.msg_debug "Element: $file" 3
_mod_.replacemod --file-name="$file" --new-name="$MODULE_NAME.$element.${file%}" --source-path="$CHECK_PATH/$file"
done
Expand All @@ -74,8 +69,10 @@ _mod_.load_module(){

_mod_.replacemod () {
local FILE_NAME NEW_NAME SOURCE_PATH
local USED="The '$FUNCNAME' method must contain the 3 required parameters \n--file-name='file \n--new-name='common.task' \n--source-path='path/folder/file"

local USED="The $FUNCNAME method must contain the 3 required parameters"
USED+="\n--file-name='file"
USED+="\n--new-name='common.tasks'"
USED+="\n--source-path='path/folder/file"
if [[ $# != 3 ]]; then
_mod_.msg_danger $USED 3
_mod_.msg_debug "$@" 3
Expand Down Expand Up @@ -106,7 +103,16 @@ _mod_.replacemod () {


if [ "$EFDE_MOD_DEV" = "true" ] || [ ! -f "$PATH_TARGET" ]; then
sed "s/_mod_/$NEW_NAME/g" "$SOURCE_PATH" > "$PATH_TARGET"
# old only replace functions
#sed "s/_mod_/$NEW_NAME/g" "$SOURCE_PATH" > "$PATH_TARGET"

if echo "$NEW_NAME" | grep -qi ".tasks."; then
sed -E "s/_mod_\.([a-zA-Z_][a-zA-Z0-9_]*)/${NEW_NAME}.\1/g" "$SOURCE_PATH" > "$PATH_TARGET"
else
NEW_NAME_VAR=$(echo "$NEW_NAME" | sed "s/tasks/props/" | tr "." "_")
sed -E "s/_mod_([a-zA-Z_][a-zA-Z0-9_]*)/${NEW_NAME_VAR}_\1/g" "$SOURCE_PATH" > "$PATH_TARGET"
fi

if [ ! $? -eq 0 ]; then
_mod_.msg_danger "[ERROR] The conversion could not be carried out, report this!" 4
_mod_.msg_danger "Source: $SOURCE_PATH" 5
Expand Down
6 changes: 3 additions & 3 deletions console/common/props/menu
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
#declare -a MENU=('tools,Tools, ' 'symfony,Install Symfony, ' 'magento,Coming soon - Install Magento | Wordpress | Prestashop | Drupal | React | Angular | Vue | Next, ')
#ALL_MENUS["MENU_INIT"]="${MENU[@]}"

MENU_INIT=(
'tools,Tools, '
_mod_INIT=(
'tools,Tools, ESTE'
'symfony,Install Symfony, '
'magento,Coming soon - Install Magento | Wordpress | Prestashop | Drupal | React | Angular | Vue | Next, ')
'magento,Coming soon Install Magento | Wordpress | Prestashop | Drupal | React | Angular | Vue | Next ')
# 'magento,Coming soon - Install Magento, '
# 'wordpress,Coming soon - Install Wordpress, '
# 'woocommerce,Coming soon - Install WooCommerce, '
Expand Down
39 changes: 39 additions & 0 deletions console/common/tasks/command_line
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env bash
set -euo pipefail

_mod_.run() {
if [ "$#" -ne 3 ]; then
local USED=""
USED+="Error: Three parameters are required:\n"
USED+=" - FORCE_SHOW_CLI FORCE_SHOW_OUTPUT COMMAND_LINE\n"
USED+="\n parameters:\n ${@}\n"
USED+="\n Example:\n"
USED+=" - $FUNCNAME FORCE_SHOW_CLI=true FORCE_SHOW_OUTPUT=true COMMAND_LINE\n"
USED+=" - $FUNCNAME 1 0 'cd folder'"
common.tasks.message.danger $USED
return 1
fi

local FORCE_SHOW_CLI FORCE_SHOW_OUTPUT COMMAND_LINE

FORCE_SHOW_CLI=$1
FORCE_SHOW_OUTPUT=$2
COMMAND_LINE="$3"

if [ "${GLOBAL_EFDE_CONFIG['CLI_SHOW_DEFAULT']}" = "true" ]; then
FORCE_SHOW_CLI=${GLOBAL_EFDE_CONFIG['CLI_SHOW_CLI']}
FORCE_SHOW_OUTPUT=${GLOBAL_EFDE_CONFIG['CLI_SHOW_OUTPUT']}
#[ "${GLOBAL_EFDE_CONFIG['CLI_SHOW_CLI']}" = "true" ] && FORCE_SHOW_CLI=true
#[ "${GLOBAL_EFDE_CONFIG['CLI_SHOW_OUTPUT']}" = "true" ] && FORCE_SHOW_OUTPUT=true
fi

if [ "${FORCE_SHOW_CLI}" = "true" ]; then
common.tasks.message.info "# RUN CLI > ${COMMAND_LINE}"
fi

if [ "${FORCE_SHOW_OUTPUT}" = "false" ]; then
${COMMAND_LINE} > /dev/null 2>&1
else
${COMMAND_LINE}
fi
}
107 changes: 107 additions & 0 deletions console/common/tasks/env_variable
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#!/usr/bin/env bash
set -euo pipefail

_mod_.set_variable() {

if [ "$#" -ne 3 ]; then
echo "Error: Se requieren tres parámetros: key, value, file"
return 1
fi

local key="$1"
local value="$2"
local file="$3"

key=$(echo "$key" | tr '[:lower:]' '[:upper:]' | tr ' ' '_')

if [ ! -e "$file" ]; then
touch "$file"
fi

if grep -q "^$key=" "$file"; then
# Update existing
sed -i "s/^$key=.*/$key=\"$value\"/" "$file"
else
# add new
echo "$key=\"$value\"" >> "$file"
fi
}

_mod_.get_variable() {
if [ "$#" -ne 2 ]; then
echo "Error: Se requieren dos parámetros: key, file"
return 1
fi

local key="$1"
local file="$2"

key=$(echo "$key" | tr '[:lower:]' '[:upper:]' | tr ' ' '_')

if [ -e "$file" ]; then
local value=$(grep "^$key=" "$file" | sed "s/^$key=//")
if [ -n "$value" ]; then
value=$(echo "$value" | sed 's/^"\(.*\)"$/\1/')
echo -n "$value"
else
echo "No encontrado"
fi
else
echo "Error: El archivo $file no existe."
return 1
fi
}
#
#
## USAGED
## Call:
## SETUP_ENVIRONMENT=(
## [NAME]="MyName"
## [CREATE_AT]="2000-01-01"
## [IMPLEMENTION]="efde"
## )
## VAR_STRING="$(_mod_.prepare_string_to_env SETUP_ENVIRONMENT)"
##
## echo -e "$VAR_STRING" > "$PATH_FILE"
##
## Response:
## 'NAME="MyName"\nCREATE_AT="2000-01-01"\nIMPLEMENTION="efde"'
#_mod_.prepare_string_to_env(){
# local -n env_array=$1
# local env_str=""
#
# for key in "${!env_array[@]}"; do
# value="${env_array[$key]}"
# env_str+="\n$key=\"$value\""
# done
#
# env_str="${env_str:2}" # Remove firts \n
#
# echo "$env_str"
#}
#
#_mod_.load_variables_from_file() {
# local file_path="$1"
# local variables=""
#
# if [ -f "$file_path" ]; then
# # Leer el archivo y construir la cadena de variables
# while IFS='=' read -r key value; do
# # Eliminar espacios en blanco alrededor de la clave y el valor
# key=$(echo "$key" | sed 's/^[ \t]*//;s/[ \t]*$//')
# value=$(echo "$value" | sed 's/^[ \t]*//;s/[ \t]*$//')
#
# # Agregar la variable a la cadena
# variables+="$key=\"$value\" "
# done < "$file_path"
#
# # Eliminar posibles espacios en blanco al final
# variables=$(echo "$variables" | sed 's/[ \t]*$//')
#
# # Devolver la cadena de variables
# echo "$variables"
# else
# echo "Error: El archivo $file_path no existe."
# return 1
# fi
#}
Loading

0 comments on commit bec6901

Please sign in to comment.