Skip to content

Commit

Permalink
Merge pull request #18 from dermatz/feature/add-gum
Browse files Browse the repository at this point in the history
1.4.0 - Gum Support
  • Loading branch information
dermatz authored Sep 20, 2023
2 parents 76a3356 + 048fd8a commit 3f8446d
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 64 deletions.
2 changes: 1 addition & 1 deletion commands/web/frontend
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ source ".ddev/commands/web/woodoo_components/variables"

echo -e "🛠️ ${bldblu}DDEV Woodoo Frontend Buildtools $WOODOO_VERSION for Magento${txtrst}"
if [ "$WOODOO_VERSION" != "$LATEST_WOODOO_VERSION" ]; then
echo -e "🛠️ ${bldylw}Version $LATEST_WOODOO_VERSION available!${txtrst}"
echo -e "🛠️ ${bldylw}Stable Version $LATEST_WOODOO_VERSION available!${txtrst}"
echo -e " ${txtylw}Install update with: ${txtcyn}ddev frontend-update${txtrst}"
fi

Expand Down
15 changes: 4 additions & 11 deletions commands/web/woodoo_components/build
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,12 @@ if [[ "$1" == "build" && "$2" == "" || "$1" == "b" && "$2" == "" || "$1" == "bui

# if more then one theme is available, ask if all themes should be build
if [[ $(countThemesinConfig) -gt 1 && $2 != '-f' ]]; then
echo -en "Build all $(countThemesinConfig) Themes? [y/n] "
read -r answer
if [ "$answer" = "y" ] || [ "$answer" = "yes" ] || [ "$answer" = "Y" ] || [ "$answer" = "YES" ] || [ "$answer" = "ja" ] || [ "$answer" = "" ]; then
echo -e "\n${txtgrn}Build all Themes ...${txtrst}\n"
else
echo -e "\n${txtylw}stopped!${txtrst}\n"
exit 0
fi
THEMES_TO_BUILD=$(gum choose --cursor-prefix "[ ] " --unselected-prefix "[ ] " --selected-prefix "[✓] " --no-limit $THEMES_IN_CONFIG;)
else
THEMES_TO_BUILD=$THEMES_IN_CONFIG
fi

# Build all themes
for THEME_CODE in $THEMES_IN_CONFIG; do

for THEME_CODE in $THEMES_TO_BUILD; do
THEME_TO_BUILD=$(echo $(grep -oP '(?<='$THEME_CODE': ).*' $PROJECT_CONFIG_FILE) | cut -d ' ' -f 1 | sed 's/"//g')

# checks to figure out if it is a Hyvä Theme
Expand Down
11 changes: 2 additions & 9 deletions commands/web/woodoo_components/checks
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,9 @@ function checkForNewThemeConfig() {
echo -e "\n${txtylw}👉 Since Woodoo Version 1.4, a new $PROJECT_CONFIG_FILE file is required!${txtrst}"
echo -en "${txtblu}What has been changed?${txtrst} You no longer have to add your Themes to ${txtcyn}$OLD_CONFIG_FILE${txtylw}.${txtrst}\n"
echo -en "${txtblu}What is new?${txtrst} Now all Theme Settings are stored in this new file: ${txtcyn}$PROJECT_CONFIG_FILE${txtrst}\n\n"
echo -en "${txtgrn}🛠 Copy and cleanup Theme Settings now? [y/n] ${txtrst}"

read -r answer
gum confirm "Do you wish to update automatically??" && migrateThemesToNewConfigFile || echo -e "${txtylw}You choosed manual update.\n${txtrst}Please create ${txtcyn}${PROJECT_CONFIG_FILE}${txtrst} and add your theme paths manually.\n"

if [ "$answer" = "y" ] || [ "$answer" = "yes" ] || [ "$answer" = "Y" ] || [ "$answer" = "YES" ] || [ "$answer" = "ja" ] || [ "$answer" = "" ]; then
migrateThemesToNewConfigFile
else
echo -e "\n${txtred}Please create $PROJECT_CONFIG_FILE and add your theme pathes manually.${txtrst}\n"
exit 1
fi
fi
}

Expand All @@ -39,7 +32,7 @@ function migrateThemesToNewConfigFile() {
echo -e "\n${txtred}Could not create $PROJECT_CONFIG_FILE.${txtrst}\n"
exit 0
else
echo -e "\n${txtgrn}${ICON_SUCCESS} $PROJECT_CONFIG_FILE created.${txtrst}\n"
echo -e "\n${txtgrn}${ICON_SUCCESS} $PROJECT_CONFIG_FILE created.${txtrst}"
fi

if [ -f $PROJECT_CONFIG_FILE ]; then
Expand Down
91 changes: 58 additions & 33 deletions commands/web/woodoo_components/themes
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
function getMagento2_ThemeStoreCodes() {

# check if mysql is installed
if ! command -v mysql &> /dev/null; then
if ! command -v mysql &> /dev/null
then
echo -e "\n${txtred}mysql could not be found.${txtrst}"
echo -e "${txtred}Please install mysql.${txtrst}\n"
exit 1
Expand All @@ -30,43 +31,67 @@ function addThemesToConfig() {

getMagento2_ThemeStoreCodes

ADDEDTHEMES=0
LINE=4
local ADDEDTHEMES=0
local REMOVEDTHEMES=0
local LINE=4

echo -en "\n${txtcyn}Woodoo has found ${txtpur}$THEME_CODES_DB_COUNT Themes${txtcyn} in your Database.${txtrst}"
echo -en "\n${txtcyn}Add the Theme below to $PROJECT_CONFIG_FILE if you want add it to the Build-Process later:${txtrst}\n\n"

if grep -q "themes:" $PROJECT_CONFIG_FILE; then
echo -e "\n${txtgrn}${ICON_SUCCESS} Themes-Section already exist in $PROJECT_CONFIG_FILE ${txtrst}\n"
if [[ $THEME_CODES_DB_COUNT -gt 1 ]]; then
echo -en "\n${txtcyn}Choose the Themes below which should be added in ${txtpur}$PROJECT_CONFIG_FILE${txtcyn} to watch and build later:${txtrst}\n\n"
else
sed -i $LINE'i\themes:' $PROJECT_CONFIG_FILE
echo -en "\n${txtcyn}Choose the Theme below which should be added in ${txtpur}$PROJECT_CONFIG_FILE${txtcyn} to watch and build later:${txtrst}\n\n"
fi

for THEME_CODE in $THEME_CODES_DB; do
if ! grep -q "themes:" $PROJECT_CONFIG_FILE; then
echo -e "themes:" >> $PROJECT_CONFIG_FILE
fi

((LINE++))
echo -en "${bldgrn}Tip:${txtwht} Navigate with ↑ or ↓ keys and press space to select the option$PLURAL you want to add.\n"
echo -en "${bldred}Reset:${txtwht} Reset configfile and remove all themes with <ESC>.\n\n"

# checks if theme is already in config-themes.yaml
if grep -q "$THEME_CODE" $PROJECT_CONFIG_FILE; then
echo -en "${txtylw}${ICON_ERROR} Theme "$THEME_CODE" already exists (skipped)${txtrst}\n\n"
continue
# Check if theme-code is already in config to set it as selected
local THEMESALLREADYINCONFIG=''
for THEME_CODES in $THEME_CODES_DB; do
if grep -q "$THEME_CODES" $PROJECT_CONFIG_FILE; then
THEMESALLREADYINCONFIG="$THEMESALLREADYINCONFIG --selected $THEME_CODES"
fi
done

SELECTED_THEMES=$(gum choose --cursor-prefix "[ ] " --unselected-prefix "[ ] " --selected-prefix "[✓] " $THEMESALLREADYINCONFIG --no-limit $THEME_CODES_DB)

echo -en "📎 Add Theme ${txtpur}$THEME_CODE${txtrst}? [y/n] "
read -r answer
if [ "$answer" = "y" ] || [ "$answer" = "yes" ] || [ "$answer" = "Y" ] || [ "$answer" = "YES" ] || [ "$answer" = "ja" ] || [ "$answer" = "" ]; then
THEME_PATH="path/to/theme"
sed -i $LINE'i\ - '$THEME_CODE': "'$THEME_PATH'"' $PROJECT_CONFIG_FILE
echo -en "${txtgrn}${ICON_SUCCESS} Theme "$THEME_CODE" added!${txtrst}\n\n"
# Save selected to config file, skip existing ones
for THEME_CODE in $THEME_CODES_DB; do
# if this THEME_CODE is in SELECTED_THEMES, add to config otherwise remove from config
if [[ "$SELECTED_THEMES" =~ "$THEME_CODE" ]]; then
# skip if theme-code is already in config
if grep -q "$THEME_CODE" $PROJECT_CONFIG_FILE; then
continue
fi
local THEMEPATH=$(gum input --cursor.foreground "#CCC" --prompt "Enter Theme-Path ($THEME_CODE): " --prompt.foreground="#84CC16" --placeholder "enter relative path")
echo -e " - ${THEME_CODE}: \"${THEMEPATH}\"" >> $PROJECT_CONFIG_FILE
((ADDEDTHEMES++))
else
((LINE--))
echo -en "${txtylw}${ICON_ERROR} Theme "$THEME_CODE" skipped ${txtrst}\n\n"
if grep -q "$THEME_CODE" $PROJECT_CONFIG_FILE; then
local LINE=$(grep -n "$THEME_CODE" $PROJECT_CONFIG_FILE | cut -d ':' -f 1)
sed -i "${LINE}d" $PROJECT_CONFIG_FILE
((REMOVEDTHEMES++))
fi
fi

done
echo -en "${txtgrn}${ICON_SUCCESS} $ADDEDTHEMES of $THEME_CODES_DB_COUNT Themes added to $PROJECT_CONFIG_FILE ${txtrst}\n"

# Counter output
if [[ $ADDEDTHEMES -gt 0 ]]; then
echo -e "\n${txtgrn}${ADDEDTHEMES} Theme(s) added to ${txtpur}$PROJECT_CONFIG_FILE${txtrst}"
fi
if [[ $REMOVEDTHEMES -gt 0 ]]; then
echo -e "${txtred}${REMOVEDTHEMES} Theme(s) removed from ${txtpur}$PROJECT_CONFIG_FILE${txtrst}"
fi

echo -e "\n"
else
echo -e "\n${txtred}No $PROJECT_CONFIG_FILE found.'${txtrst}\n"
exit 1
fi
}

Expand All @@ -75,19 +100,18 @@ function readThemesInConfig() {
THEMES_IN_CONFIG=""

if [ ! -f $PROJECT_CONFIG_FILE ]; then
echo -e "\n${txtred}No $PROJECT_CONFIG_FILE found.' ${txtrst}\n"
exit 0
echo -e "\n${txtred}No $PROJECT_CONFIG_FILE found.' first.${txtrst}\n"
exit 1
fi

# Read config-themes.yaml to get available themes
# Read $PROJECT_CONFIG_FILE to get available themes
while read -r line; do
# Check whether the line with "Themes:" begins
if [[ "$line" =~ ^themes: ]]; then
while read -r next_line; do
# Check whether the next line begins with "-"
if [[ -n "$next_line" && "$next_line" =~ ^- ]]; then
THEMES_IN_CONFIG="$THEMES_IN_CONFIG $(echo $next_line | cut -d ' ' -f 2 | cut -d ':' -f 1)"

else
break
fi
Expand All @@ -96,7 +120,7 @@ function readThemesInConfig() {
done < $PROJECT_CONFIG_FILE
}

# Count Themes by reading config-themes.yaml with readThemesInConfig()
# Count Themes by reading config.yaml with readThemesInConfig()
function countThemesinConfig() {

readThemesInConfig
Expand All @@ -108,7 +132,7 @@ function countThemesinConfig() {

}

# get all available themes in config-themes.yaml
# get all available themes in $PROJECT_CONFIG_FILE
function getThemesInConfig() {

readThemesInConfig
Expand All @@ -122,7 +146,7 @@ function getThemesInConfig() {

}

#check all available themes in config-themes.yaml if the path is not "path/to/theme"
#check all available themes in config.yaml if the path is not "path/to/theme"
function checkThemePathExists() {

readThemesInConfig
Expand Down Expand Up @@ -150,7 +174,8 @@ function checkThemePathExists() {
if [[ -n "$next_line" && "$next_line" =~ ^- ]]; then
if [[ "$next_line" =~ $THEME_CODE ]]; then
THEME_PATH=$(echo $next_line | cut -d ' ' -f 3 | cut -d '"' -f 2)
if [[ "$THEME_PATH" == "path/to/theme" ]]; then

if [[ "$THEME_PATH" == "" ]]; then
echo -e "${txtred}${ICON_ERROR} Theme ${txtpur}$THEME_CODE ${txtred}has not been configured yet.${txtrst}"
THEME_PATHES_VALID=false
PATH_ERROR=true
Expand Down Expand Up @@ -186,12 +211,12 @@ if [[ "$1" = "init" || "$1" = "install" || "$1" = "i" ]]; then
addThemesToConfig
fi

if [[ "$1" = "themes" && "$2" = "check" ]]; then
if [[ "$1" = "themes" || "$1" = "theme" && "$2" = "check" ]]; then
checkThemePathExists
fi


if [[ "$1" = "themes" && "$2" == "" ]]; then
if [[ "$1" = "themes" || "$1" = "theme" && "$2" == "" ]]; then

echo -e "\n${txtgrn}Themes found in Database:\n"
getThemesFromDB
Expand Down
4 changes: 3 additions & 1 deletion commands/web/woodoo_components/variables
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
#ddev-generated - Do not modify this file; your modifications will be overwritten.
WOODOO_VERSION="1.3.1"
WOODOO_VERSION="1.4.0-alpha"
LATEST_WOODOO_VERSION=$(curl -s https://api.github.com/repos/dermatz/ddev-woodoo-buildtools-magento/releases/latest | grep tag_name | cut -d '"' -f 4)

PROJECT_CONFIG_FILE=".ddev/config-themes.yaml"
Expand All @@ -15,6 +15,8 @@ PROJECT_ARCH=$GOARCH
PROJECT_PHP_VERSION=$DDEV_PHP_VERSION
PROJECT_NODEJS_VERSION=$(node -v)

GUM_CHOOSE=""

if ping -q -c 1 -W 1 nodejs.org >/dev/null; then
LATEST_LTS_VERSION=$(curl -s https://nodejs.org/dist/index.json | jq -r '.[] | select(.lts) | .version' | sort -V | tail -1)
else
Expand Down
17 changes: 11 additions & 6 deletions commands/web/woodoo_components/watch
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,18 @@ if [[ "$1" == "watch" && "$2" == "" || "$1" == "w" && "$2" == "" ]]; then

addThemesToConfig

elif [[ $(countThemesinConfig) == 1 ]]; then
echo -e "\n${txtgrn}$(countThemesinConfig)${txtcyn} Theme is ready to watch:${txtrst}"
for THEME_CODE in $THEMES_IN_CONFIG; do

else

# if more then one theme is available, ask if all themes should be build
if [[ $(countThemesinConfig) -gt 1 && $2 != '-f' ]]; then
THEMES_TO_WATCH=$(gum choose --cursor-prefix "[ ] " --unselected-prefix "[ ] " --selected-prefix "[✓] " $THEMES_IN_CONFIG;)
else
THEMES_TO_WATCH=$THEMES_IN_CONFIG
fi

for THEME_CODE in $THEMES_TO_WATCH; do

THEME_TO_BUILD=$(echo $(grep -oP '(?<='$THEME_CODE': ).*' $PROJECT_CONFIG_FILE) | cut -d ' ' -f 1 | sed 's/"//g')

Expand All @@ -129,9 +138,5 @@ if [[ "$1" == "watch" && "$2" == "" || "$1" == "w" && "$2" == "" ]]; then
fi

done
else
echo -e "\n${txtcyn}Which of the ${txtgrn}$(countThemesinConfig)${txtcyn} Themes you want to watch?\n${txtrst}"
getThemesInConfig
echo -e "\n\n${txtcyn}Type ${txtgrn}ddev frontend watch ${txtpur}[theme-code]${txtcyn} to watch a specific theme\n\n"
fi
fi
6 changes: 3 additions & 3 deletions install.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: ddev-woodoo-buildtools-magento

pre_install_actions:
# https://github.com/Morgy93/ddev-gum
- if ! ddev get --installed | grep -q "Morgy93/ddev-gum"; then ddev get Morgy93/ddev-gum; fi

project_files:
- commands/web/woodoo_components/
- commands/web/frontend
- commands/host/frontend-update

post_install_actions:

0 comments on commit 3f8446d

Please sign in to comment.