#!/bin/bash # Mage is a collection of easy commands and aliases for bin/magento # For those who hate typing long shell commands # Global variables RESET='\033[0m' BOLD='\033[1m' ITALIC='\033[3m' RED='\033[0;31m' GREEN='\033[1;32m' BLUE='\033[1;34m' GITNAME="$(git config --global --get user.name | head -n1 | cut -d " " -f1)" GITEMAIL="$(git config --global --get user.email)" ADMINNAME="$(echo "$GITNAME" | tr '[:upper:]' '[:lower:]')" ADMINEMAIL="${GITEMAIL}" ADMINPASS="m2_admin123$" WARDEN=0 MAGENTO_CLI="bin/magento" MAGERUN_CLI="" REDIS_CLI="redis-cli" VARNISH_CLI="varnishadm" # We never use varnish on a local machine, and prefer to never use it PHP_CLI="php" COMPOSER_CLI="composer" NODE_CLI="node" NPM_CLI="npm" PURGE_CLI="rm -rf" OPEN_CLI="xdg-open" # Linux GET_CLI="wget" # Linux # OSX if [[ "$OSTYPE" == "darwin"* ]]; then OPEN_CLI="open" GET_CLI="curl -O" fi # Check if this is the Magento 2 root if [[ ! -d app/etc ]]; then # Allow the following commands to run, even if the folder is not root Magento, # if else exit mage if [[ $1 != "-v" ]] && [[ $1 != "--version" ]] && [[ $1 != "version" ]] && [[ $1 != "help" ]] && [[ $1 != "self-update" ]] && [[ $1 != "install" ]] && [[ $1 != "create" ]]; then echo "This does not look like the Magento 2 root folder, aborting.." && exit 1 fi fi # Magerun NO_MAGERUN_MSG="Magerun2 is not installed" if command -v magerun2 &>/dev/null; then MAGERUN_CLI="magerun2" elif command -v n98-magerun2 &>/dev/null; then MAGERUN_CLI="n98-magerun2" fi # Warden Support if [ -f .env ] && grep -q "WARDEN_ENV_NAME" .env && [[ ! "$PATH" == /var/www/html* ]]; then WARDEN=1 MAGENTO_CLI="warden env exec php-fpm bin/magento" MAGERUN_CLI="warden env exec php-fpm n98-magerun" REDIS_CLI="warden env exec redis redis-cli" VARNISH_CLI="warden env exec -T varnish varnishadm" PHP_CLI="warden env exec php-fpm php" COMPOSER_CLI="warden env exec php-fpm composer" NODE_CLI="warden env exec php-fpm node" NPM_CLI="warden env exec php-fpm npm" # Run removal within environment, so that changes are in effect immediately. # Changes will get synced back to the host PURGE_CLI="warden env exec -T php-fpm rm -rf" fi # Helper to format language inputs function mage_lang_format_arguments() { formatted_args="" for arg in "$@"; do formatted_arg=$(tr '[a-z]' '[A-Z]' <<< "$arg") formatted_arg="${formatted_arg// /}" formatted_args="${formatted_args},${formatted_arg}" done formatted_args="${formatted_args:1}" echo "$formatted_args" } # Creates a file/folder and echo the contents in one command function mage_make_file() { touch $1 if [[ $2 == "rsync" ]]; then if [[ -d $3 ]]; then rsync -ah ${3}/ ${1} --exclude node_modules else echo -e "The folder '${3}' does not exists" fi else echo -e $2 >> $1 fi } # Convert string to kebab-case function mage_kebab_case() { echo "${@}" | sed 's/\([A-Z]\)/-\1/g' | tr '[:upper:]' '[:lower:]' | sed -e 's/^-*//' -e 's/-*$//' | tr -s '[:blank:]' '-' } # Get the Magento 2 Base Url function get_mage_base_uri() { local baseuri="$($MAGENTO_CLI config:show web/secure/base_url)" if [[ -z "${baseuri}" ]]; then local baseuri="$($MAGENTO_CLI config:show web/unsecure/base_url)" fi echo $baseuri } # Get specific Magento 2 Store Url function get_mage_store_uri() { local store_url="" if [[ -n "$MAGERUN_CLI" ]]; then if [[ "$1" == "admin" ]]; then store_url=$($MAGERUN_CLI sys:store:config:base-url:list --format csv | grep 1 -m 1 | head -1 | cut -d ',' -f3) else store_url=$($MAGERUN_CLI sys:store:config:base-url:list --format csv | grep $1 | cut -d ',' -f3) fi else store_url=$(get_mage_base_uri) fi echo $store_url } function get_composer_pkg_version() { echo -e $($COMPOSER_CLI show $1 | grep 'versions' | grep -o -E '\*\ .+' | awk '{print $2}' | cut -d',' -f1) } function mage_add_hyva() { local use_hyva_production=$1 if [[ $use_hyva_production =~ ^[yY]|[yY][eE][sS]$ ]]; then if [ ! -f "auth.json" ]; then read -e -p "No license found, add license? [Y/n] " echo "" if [[ ! $REPLY =~ ^[nN]|[nN][oO]$ ]]; then read -e -p "License key: " hyva_key && echo "" read -e -p "Packagist url: " hyva_url && echo "" $COMPOSER_CLI config --auth http-basic.hyva-themes.repo.packagist.com token $hyva_key $COMPOSER_CLI config repositories.private-packagist composer https://hyva-themes.repo.packagist.com/$hyva_url/ echo "Installing Hyva theme..." $COMPOSER_CLI require hyva-themes/magento2-default-theme else echo "Installing Hyva theme..." $COMPOSER_CLI require hyva-themes/magento2-default-theme fi else echo "Installing Hyva theme..." $COMPOSER_CLI require hyva-themes/magento2-default-theme fi else mage_add_hyva_dev fi; $MAGENTO_CLI config:set customer/captcha/enable 0 } function mage_add_hyva_dev() { echo "Adding repositories..." # Core Theme Deps $COMPOSER_CLI config repositories.hyva-themes/magento2-reset-theme git git@gitlab.hyva.io:hyva-themes/magento2-reset-theme.git $COMPOSER_CLI config repositories.hyva-themes/magento2-theme-module git git@gitlab.hyva.io:hyva-themes/magento2-theme-module.git $COMPOSER_CLI config repositories.hyva-themes/magento2-mollie-theme-bundle git git@gitlab.hyva.io:hyva-themes/hyva-compat/magento2-mollie-theme-bundle.git $COMPOSER_CLI config repositories.hyva-themes/magento2-email-module git git@gitlab.hyva.io:hyva-themes/magento2-email-module.git # magento2-graphql-tokens Found on: https://packagist.org/packages/hyva-themes/magento2-graphql-tokens # magento2-graphql-view-model Found on: https://packagist.org/packages/hyva-themes/magento2-graphql-view-model $COMPOSER_CLI config repositories.hyva-themes/magento2-order-cancellation-webapi git git@gitlab.hyva.io:hyva-themes/magento2-order-cancellation-webapi.git $COMPOSER_CLI config repositories.hyva-themes/magento2-default-theme git git@gitlab.hyva.io:hyva-themes/magento2-default-theme.git # Extra Deps $COMPOSER_CLI config repositories.hyva-themes/magento2-default-theme-csp git git@gitlab.hyva.io:hyva-themes/magento2-default-theme-csp.git $COMPOSER_CLI config repositories.hyva-themes/magento2-cms-tailwind-jit git git@gitlab.hyva.io:hyva-themes/magento2-cms-tailwind-jit.git $COMPOSER_CLI config repositories.hyva-themes/magento2-compat-module-fallback git git@gitlab.hyva.io:hyva-themes/magento2-compat-module-fallback.git $COMPOSER_CLI config repositories.hyva-themes/magento2-theme-fallback git git@gitlab.hyva.io:hyva-themes/magento2-theme-fallback.git $COMPOSER_CLI config repositories.hyva-themes/magento2-luma-checkout git git@gitlab.hyva.io:hyva-themes/magento2-luma-checkout.git # Checkout Deps $COMPOSER_CLI config repositories.hyva-themes/hyva-checkout git git@gitlab.hyva.io:hyva-checkout/checkout.git # Commerce Deps $COMPOSER_CLI config repositories.hyva-themes/commerce git git@gitlab.hyva.io:hyva-commerce/metapackage-commerce.git $COMPOSER_CLI config repositories.hyva-themes/commerce-module-commerce git git@gitlab.hyva.io:hyva-commerce/module-commerce.git $COMPOSER_CLI config repositories.hyva-themes/commerce-module-cms git git@gitlab.hyva.io:hyva-commerce/module-cms.git $COMPOSER_CLI config repositories.hyva-themes/commerce-module-image-editor git git@gitlab.hyva.io:hyva-commerce/module-image-editor.git $COMPOSER_CLI config repositories.hyva-themes/commerce-module-admin-theme git git@gitlab.hyva.io:hyva-commerce/module-admin-theme.git $COMPOSER_CLI config repositories.hyva-themes/commerce-theme-adminhtml git git@gitlab.hyva.io:hyva-commerce/theme-adminhtml.git $COMPOSER_CLI config repositories.hyva-themes/commerce-module-admin-dashboard git git@gitlab.hyva.io:hyva-commerce/module-admin-dashboard.git # Dev Deps $COMPOSER_CLI config repositories.hyva-themes/commerce-module-admin-dashboard-google-crux-history-widget git git@gitlab.hyva.io:hyva-commerce/module-admin-dashboard-google-crux-history-widget.git $COMPOSER_CLI config repositories.hyva-themes/commerce-module-media-optimization git git@gitlab.hyva.io:hyva-commerce/module-media-optimization.git echo "Installing Hyva theme..." $COMPOSER_CLI require hyva-themes/magento2-default-theme --prefer-source } function mage_add_hyva_checkout() { echo "Installing Hyva Checkout..." $COMPOSER_CLI require hyva-themes/magento2-hyva-checkout } function mage_add_hyva_commerce() { local use_hyva_production=$1 echo "Installing Hyva Commerce..." if [[ $use_hyva_production =~ ^[yY]|[yY][eE][sS]$ ]]; then $COMPOSER_CLI require hyva-themes/commerce else $COMPOSER_CLI require hyva-themes/commerce-module-cms $COMPOSER_CLI require hyva-themes/commerce-module-image-editor $COMPOSER_CLI require hyva-themes/commerce-theme-adminhtml $COMPOSER_CLI require hyva-themes/commerce-module-admin-dashboard fi } function mage_build_hyva() { if [ ! -d vendor/hyva-themes/magento2-default-theme/web/tailwind/node_modules ]; then $NPM_CLI --prefix vendor/hyva-themes/magento2-default-theme/web/tailwind install; fi $NPM_CLI --prefix vendor/hyva-themes/magento2-default-theme/web/tailwind run build; } MAGE_VERSION="2.3.4" function mage_version() { echo -e "\n${BOLD}Mage ${GREEN}${MAGE_VERSION}${RESET}" echo -e "${ITALIC}See https://github.com/GrimLink/mage for the last version${RESET}\n" } function mage_help_cmd() { echo -e "- ${BLUE}${1}${RESET} (${2})" } function mage_help() { echo -e "${BOLD}CMD Options:${RESET}" mage_help_cmd "self-update" "Update mage" mage_help_cmd "info" "Show base config for store" mage_help_cmd "start" "Open store and admin with code editor and git client" mage_help_cmd "open" "Open default store view" mage_help_cmd "open admin" "Open store admin" mage_help_cmd "open [storeview]" "Open specific store view" mage_help_cmd "stores" "Show all stores" mage_help_cmd "watch" "Run cache-clean.js from mageTV" mage_help_cmd "browser-sync" "Run browser-sync on default store view" mage_help_cmd "browser-sync [storeview]" "Run browser-sync on specific store view" mage_help_cmd "reindex" "Reindex all indexes and clear cache" mage_help_cmd "purge" "Purge all static assets" mage_help_cmd "new admin" "Create new admin user" mage_help_cmd "new customer" "Create new customer" mage_help_cmd "new theme" "Create new theme" mage_help_cmd "new module" "Create new module" mage_help_cmd "new patch" "Create new patch" mage_help_cmd "new i18n [src] | new translate [src]" "Create new translations" mage_help_cmd "add patch" "Add patch" mage_help_cmd "add sample" "Add sample data" mage_help_cmd "add hyva" "Add Hyva Theme" mage_help_cmd "add checkout" "Add Hyva Checkout" mage_help_cmd "add baldr" "Add Siteation Baldr" mage_help_cmd "set mage-os" "Replace Magento2 with Mage-OS distro" mage_help_cmd "set theme [theme]" "Run yireo theme:change" mage_help_cmd "set hyva" "Set theme: Hyva default" mage_help_cmd "set baldr" "Set theme: Siteation Baldr" mage_help_cmd "set mode [mode]" "Set deploy mode with admin settings for dev or prod" mage_help_cmd "set countries [list_countries]" "Set the store countries" mage_help_cmd "set fsp | set fpc default" "Set the full page cache to system" mage_help_cmd "set fpc varnish" "Set the full page cache to varnish" mage_help_cmd "log | log debug" "watch the debug log" mage_help_cmd "log exception" "watch the exception log" mage_help_cmd "log system" "watch the system log" mage_help_cmd "outdated" "Show all direct outdated composer dependencies" mage_help_cmd "build" "Run setup:static-content:deploy with common defaults" mage_help_cmd "run" "Run magerun2" echo -e "\n${ITALIC}Anything else will run ${BLUE}bin/magento${RESET}, ${ITALIC}To view this again, run ${BLUE}mage help${RESET}" } function mage_info() { echo -e "Magento: $GREEN$($MAGENTO_CLI --version | sed 's/Magento CLI //')$RESET" if $COMPOSER_CLI show hyva-themes/magento2-default-theme > /dev/null 2>&1; then local hyva_version="$(get_composer_pkg_version 'hyva-themes/magento2-theme-module')" local hyva_theme_version="$(get_composer_pkg_version 'hyva-themes/magento2-default-theme')" echo -e "Hyva: $GREEN$hyva_version$RESET" if [ "$hyva_version" != "$hyva_theme_version" ]; then echo -e " - Theme: $GREEN$hyva_theme_version$RESET" fi echo -e " - Modules: $($MAGENTO_CLI module:status | grep 'Hyva_' | sed 's/Hyva_//g' | paste -sd ',')" fi echo -e "PHP: $GREEN$($PHP_CLI --version | grep ^PHP | cut -d' ' -f2)$RESET" echo -e "NODE: $GREEN$($NODE_CLI --version | sed 's/v//')$RESET" echo -e "Base URI: $(get_mage_base_uri)" echo -e "Admin URI: $(grep frontName app/etc/env.php | tail -1 | cut -d ">" -f2 | cut -d "'" -f2)" echo -e "Database: $(grep dbname app/etc/env.php | tail -1 | cut -d ">" -f2 | cut -d "'" -f2)" $MAGENTO_CLI deploy:mode:show $MAGENTO_CLI maintenance:status if [[ -n "$MAGENTO_CLI config:show catalog/search/engine" ]]; then echo -e "Search Engine: $($MAGENTO_CLI config:show catalog/search/engine)" fi } function convert_to_mage_os() { if ! $COMPOSER_CLI show magento/product-community-edition >/dev/null 2>&1; then echo "This is not a Magento Community installation" && exit 1 fi if $COMPOSER_CLI show mage-os/product-community-edition >/dev/null 2>&1; then echo "Mage-OS already installed!" && exit 1 fi echo "Consider removing any composer replaces, before starting"; echo "Consider removing any 3de party moduels that could impact the conversion"; read -rsn1 -p "When ready, press any key to continue"; echo ""; # Setup $COMPOSER_CLI config repositories.0 composer https://repo.mage-os.org/ $COMPOSER_CLI require mage-os/product-community-edition --no-update $COMPOSER_CLI remove magento/product-community-edition magento/composer-dependency-version-audit-plugin magento/composer-root-update-plugin --no-update $COMPOSER_CLI remove sebastian/comparator --dev --no-update # remove if present $COMPOSER_CLI config allow-plugins.'mage-os/*' true rm -rf vendor # Install $COMPOSER_CLI update --no-plugins --with-all-dependencies mage_purge # Cleanup caches $MAGENTO_CLI s:up } function mage_new_in_folder() { if [[ ! -d package-source ]]; then mkdir package-source fi read -e -p "Create in package-source as local composer package? [y/N] " echo "" if [[ $REPLY =~ ^[yY]|[yY][eE][sS]$ ]]; then echo "package-source"; else echo $1 fi; } function mage_new_theme() { local application="frontend" local default_parrent_theme="Hyva/default" read -e -p "Is this a admin theme? [y/N] " echo "" if [[ $REPLY =~ ^[yY]|[yY][eE][sS]$ ]]; then local application="adminhtml" fi; local dest_path=$(mage_new_in_folder "app/design/${application}") read -e -p "Theme Name: " theme_name if [[ -z "$theme_name" ]]; then echo "The 'Name' can not be empty" && exit 1; fi if [[ "$theme_name" == */* ]]; then local theme_vendor="${theme_name%%/*}" local theme_name="${theme_name#*\/}" else read -e -p "Theme Vendor: " theme_vendor if [[ -z "$theme_vendor" ]]; then echo "The 'vendor' can not be empty" && exit 1; fi fi read -e -p "Parrent Theme ($default_parrent_theme): " parrent_theme if [[ -z "$parrent_theme" ]]; then parrent_theme=$default_parrent_theme; fi local theme_vendor="$(echo "$theme_vendor" | tr -d '[:blank:]')" local theme_name="$(echo "$theme_name" | tr -d '[:blank:]')" local folder_name="${theme_vendor}/$(mage_kebab_case "$theme_name")" local dest_path="$dest_path/$folder_name" local file_registration="\n\t${theme_vendor} ${theme_name}\n\t${parrent_theme}\n" mkdir -p $dest_path if [[ $parrent_theme == Hyva/* ]]; then mkdir -p $dest_path/web/tailwind mage_make_file $dest_path/web/tailwind rsync vendor/hyva-themes/magento2-default-theme/web/tailwind fi mage_make_file $dest_path/registration.php "${file_registration}" mage_make_file $dest_path/theme.xml "${file_xml}" } function mage_new_module() { local dest_path=$(mage_new_in_folder "app/code") read -e -p "Module Name: " module_name if [[ -z "$module_name" ]]; then echo "The 'Name' can not be empty" && exit 1; fi if [[ "$module_name" == */* ]]; then local module_vendor="${module_name%%/*}" local module_name="${module_name#*\/}" else read -e -p "Module Vendor: " module_vendor if [[ -z "$module_vendor" ]]; then echo "The 'vendor' can not be empty" && exit 1; fi fi local module_vendor="$(echo "$module_vendor" | tr -d '[:blank:]')" local module_name="$(echo "$module_name" | tr -d '[:blank:]')" local folder_name="${module_vendor}/$(mage_kebab_case "$module_name")" local dest_path="$dest_path/$folder_name" local file_registration="\n\n\t\n\t\t\n\t\t\t\n\t\t\n\t\n" mkdir -p $dest_path/etc mage_make_file $dest_path/registration.php "${file_registration}" mage_make_file $dest_path/etc/module.xml "${file_xml}" } function mage_open() { local store=$1 local store_url=$(get_mage_store_uri ${store:-1}) local admin_path="" # Prefetch admin URL data for open steps if [[ "$store" == "admin" ]]; then local admin_custom_path=$($MAGENTO_CLI config:show admin/url/use_custom_path) if [[ $admin_custom_path == "1" ]]; then local admin_path=$($MAGENTO_CLI config:show admin/url/custom_path) else local admin_path=$(php -r " \$array = include('app/etc/env.php'); if (isset(\$array['backend']['frontName'])) { echo \$array['backend']['frontName']; } " 2>/dev/null) fi fi if [[ -z "$store_url" ]]; then echo "Could not find url for store $store" else echo -e "Opening: ${store_url}${admin_path}" $OPEN_CLI ${store_url}${admin_path} fi } function mage_open_editor() { case $EDITOR in "phpstorm") echo "Opening PHPStorm.."; phpstorm . ;; "code" | "code -w" | "code --wait") echo "Opening VSCode.."; code . ;; "zed" | "zed -w" | "zed --wait") echo "Opening Zed.."; zed . ;; "subl" | "subl -w" | "subl --wait") echo "Opening Sublime Text.."; subl . ;; "*") echo "No valid EDITOR found" ;; esac; } function mage_open_gitclient() { if [ -d .git ]; then if command -v github &>/dev/null; then echo "Opening Github Desktop.."; github .; elif command -v fork &>/dev/null; then echo "Opening Fork.."; fork; elif command -v gittower &>/dev/null; then echo "Opening Gittower.."; gittower; fi fi } function mage_add_patch() { local vendor=${1}; local patch_name=${2}; local patch_src=${3}; if [[ -z "$vendor" ]]; then echo "The vendor your patching, Example: magento/module-theme or hyva-themes/magento_theme" read -e -p "Vendor Name: " vendor && echo "" fi if [[ -z "$patch_name" ]]; then read -e -p "Patch Name: " patch_name && echo "" fi if [[ -z "$patch_src" ]]; then echo "The source to patches/FOLDER or a git raw url" read -e -p "Patch Source: " patch_src && echo "" fi if [[ ! "$patch_src" =~ ^https:// ]]; then local patch_src="${patch_src%.*}.patch" fi $COMPOSER_CLI config extra.patches.$vendor -j "{ \"$patch_name\": \"$patch_src\" }" echo -e "Patch added to the composer.json in extra.patches.$vendor_folder_name" } function mage_new_patch_branch_diff() { git diff $(git rev-parse --abbrev-ref origin/HEAD)..$(git branch --show-current) > $(git branch --show-current).patch } function mage_new_patch_file() { local src=${1} # Remove leading slash if [[ $src == /* ]]; then src="${src:1}"; fi if [[ ! -f "$src" ]]; then echo "Can not find $src make sure this is the right path" && exit 1; fi # Get the module src for the temp git dir local module_src=$(echo "$src" | cut -d '/' -f -3) local file_src=$(echo "$src" | cut -d '/' -f 4-) local patched_file_src="${src%.*}.patch" cd $module_src git init &> /dev/null git add $file_src local patch_file_dir=$(dirname "patches/$patched_file_src") read -rsn1 -p "Make your changes in $src when ready, press any key to continue"; echo ""; mkdir -p "../../../$patch_file_dir" touch "../../../patches/$patched_file_src" git diff > "../../../patches/$patched_file_src" # Cleanup git checkout . &> /dev/null rm -rf .git cd - &> /dev/null # Add composer patch setting read -p "Add patch to composer.json? [Y/n] " echo "" if [[ ! $REPLY =~ ^[nN]|[nN][oO]$ ]]; then local vendor_folder_name=$(echo "$module_src" | sed 's/^vendor\///') # Vendor Folder / Patch Name / Patch Source mage_add_patch $vendor_folder_name "Patch: ${file_src}" "patches/${src}" fi; echo -e "Patch created in $patched_file_src". echo "Make sure the patch and settings in composer.json are correct before running composer install" } function mage_purge() { local cleantasks=( 'generated/metadata/*' 'generated/code/*' 'pub/static/*' 'var/cache/*' 'var/composer_home/*' 'var/page_cache/*' 'var/view_preprocessed/*' ); for i in "${cleantasks[@]}"; do $PURGE_CLI ${i} & echo -e " [${GREEN}✓${RESET}] ${i}" done if command -v $REDIS_CLI >/dev/null 2>&1; then $REDIS_CLI flushall > /dev/null 2>&1 echo -e " [${GREEN}✓${RESET}] Redis caches flushed" fi if command -v $VARNISH_CLI >/dev/null 2>&1; then $VARNISH_CLI 'ban req.url ~ .' > /dev/null 2>&1 echo -e " [${GREEN}✓${RESET}] Varnish caches flushed" fi } function mage_add_sample() { read -e -p "What is your Magento base version (sample: 2.4): " mversion && echo "" if [[ -z "$mversion" ]]; then echo "The Magento 2 version is empty, aborting.." && exit 1; fi if [[ ! -d "$HOME/.magento-sampledata/$mversion" ]]; then git clone -b $mversion git@github.com:magento/magento2-sample-data.git $HOME/.magento-sampledata/$mversion fi echo -e "Installing $mversion sample data" # Lets make sure these folder exist, to prevent them being made as a symlink mkdir -p app/code/Magento mkdir -p pub/media/catalog/product mkdir -p pub/media/downloadable/files mkdir -p pub/media/wysiwyg touch README.md php -f $HOME/.magento-sampledata/$mversion/dev/tools/build-sample-data.php -- --ce-source="$PWD" $MAGENTO_CLI setup:upgrade # Set theme to Hyva if present if $COMPOSER_CLI show hyva-themes/magento2-default-theme >/dev/null 2>&1; then if $COMPOSER_CLI show yireo/magento2-theme-commands >/dev/null 2>&1; then $MAGENTO_CLI theme:change Hyva/default fi # Unset default styles from sample data $MAGENTO_CLI config:set design/head/includes "" fi $MAGENTO_CLI indexer:reindex $MAGENTO_CLI cache:flush } case "${@}" in "version" | "-v" | "--version") mage_version ;; "help") mage_version mage_help ;; "self-update") cd $(dirname "${BASH_SOURCE}") && rm mage && $GET_CLI https://raw.githubusercontent.com/GrimLink/mage/main/mage && chmod +x mage ;; "info") mage_info ;; # "install"*) # mage_install $2 # ;; # "setup"*) # mage_setup $2 # ;; # "create"*) # mage_install $2 # mage_setup $2 # read -p "Add ? [y/N] " # echo "" # if [[ $REPLY =~ ^[yY]|[yY][eE][sS]$ ]]; then # mage_add_sample # fi # ;; "stores") if [[ -n "$MAGERUN_CLI" ]]; then $MAGERUN_CLI sys:store:config:base-url:list --format txt else echo $NO_MAGERUN_MSG fi ;; "start") mage_open_editor mage_open_gitclient mage open admin mage open ;; "open"*) mage_open $2; ;; "watch") cache_cli="echo cache-clean not installed ( https://github.com/mage2tv/magento-cache-clean ) 'composer global require mage2tv/magento-cache-clean'" if command -v vendor/bin/cache-clean.js &> /dev/null; then cache_cli="vendor/bin/cache-clean.js --watch" elif command -v cache-clean.js &> /dev/null; then cache_cli="cache-clean.js --watch" fi if [[ $WARDEN == 1 ]]; then # NOTE: we need to sadly hard code the path, # but lucky we can since the warden container is always the same warden env exec php-fpm /home/www-data/.composer/vendor/bin/cache-clean.js -w else $cache_cli fi ;; "browser-sync"*) store_url=$(get_mage_store_uri ${2:-1}) files_to_watch="app/**/*.phtml, app/**/*.xml, app/**/*.css, app/**/*.js" if [[ -z "$store_url" ]]; then echo "Could not find url for store $store" else npx browser-sync start --proxy ${store_url} --https --files $files_to_watch fi ;; "reindex") $MAGENTO_CLI indexer:reindex && $MAGENTO_CLI cache:flush ;; "purge") mage_purge ;; "new admin") read -e -p "Email (${GITEMAIL}) or: " useremail read -e -p "Firstname (${GITNAME}) or: " userfirst read -e -p "Lastname (admin) or: " userlast read -e -p "User name (${ADMINNAME}) or: " username read -sp "Password (${ADMINPASS}) or: " userpass $MAGENTO_CLI admin:user:create \ --admin-user="${username:-$ADMINNAME}" \ --admin-password="${userpass:-$ADMINPASS}" \ --admin-email="${useremail:-$GITEMAIL}" \ --admin-firstname="${userfirst:-$GITNAME}" \ --admin-lastname="${userlast:-"admin"}" ;; "new customer") if [[ -n "$MAGERUN_CLI" ]]; then $MAGERUN_CLI customer:create else echo $NO_MAGERUN_MSG fi ;; "new theme") mage_new_theme ;; "new module") mage_new_module ;; "new patch"*) mage_new_patch_file ${3} ;; "new i18n"* | "new translate"*) src=${3:-.} if [[ ! -f "$src/registration.php" ]]; then echo "This does not look like a Magento 2 module or theme" read -e -p "Are you sure if you want to continue? [y/N] " echo "" if [[ $REPLY =~ ^[yY]|[yY][eE][sS]$ ]]; then echo "Running '$MAGENTO_CLI i18n:collect-phrases' in '$src'" else exit 1 fi; fi mkdir -p $src/i18n $MAGENTO_CLI i18n:collect-phrases $src -o $src/i18n/temp.csv sed -i '' -e 's/^\([^"].*\),\([^"].*\)$/"\1","\2"/' $src/i18n/temp.csv sort -o $src/i18n/en_US.csv $src/i18n/temp.csv rm $src/i18n/temp.csv ;; "add patch"*) mage_add_patch ${@:3} ;; "add sample") mage_add_sample ;; "add hyva") echo "Make sure you have and license key or access to the gitlab env" read -rsn1 -p "When ready, press any key to continue"; echo ""; read -p "Is this a production setup (use license)? [N/y]" HYVA_PRODUCTION && echo "" read -p "Add Checkout? [Y/n]" HYVA_ADD_CHECKOUT && echo "" read -p "Add Commerce? [Y/n]" HYVA_ADD_COMMERCE && echo "" if [[ -z "$HYVA_PRODUCTION" ]]; then HYVA_PRODUCTION="No"; fi if [[ -z "$HYVA_ADD_CHECKOUT" ]]; then HYVA_ADD_CHECKOUT="Yes"; fi if [[ -z "$HYVA_ADD_COMMERCE" ]]; then HYVA_ADD_COMMERCE="Yes"; fi mage_add_hyva $HYVA_PRODUCTION if [[ ! $HYVA_ADD_CHECKOUT =~ ^[nN]|[nN][oO]$ ]]; then echo "" mage_add_hyva_checkout fi if [[ ! $HYVA_ADD_COMMERCE =~ ^[nN]|[nN][oO]$ ]]; then echo "" mage_add_hyva_commerce $HYVA_PRODUCTION fi $MAGENTO_CLI s:up if $COMPOSER_CLI show yireo/magento2-theme-commands >/dev/null 2>&1; then $MAGENTO_CLI theme:change Hyva/default fi mage_build_hyva echo "Done!" echo "For more information, see the docs -> https://docs.hyva.io/hyva-themes/getting-started/ " ;; "add checkout" | "add hyva checkout") mage_add_hyva_checkout ;; "add hyva commerce") mage_add_hyva_commerce ;; "add baldr") $COMPOSER_CLI config repositories.siteation/magento2-theme-baldr git git@github.com:Siteation/magento2-theme-baldr.git $COMPOSER_CLI require siteation/magento2-theme-baldr ;; "set theme"*) if $COMPOSER_CLI show yireo/magento2-theme-commands > /dev/null 2>&1; then $MAGENTO_CLI theme:change $3 $MAGENTO_CLI cache:flush; else echo "yireo/magento2-theme-commands is not installed." fi ;; "set hyva") mage set theme Hyva/default ;; "set baldr") mage set theme Siteation/baldr ;; "set mage-os") convert_to_mage_os ;; "set mode"*) deploy_mode="developer" is_mode_prod=0 admin_session_lifetime=86400 # 24h in seconds admin_password_lifetime=0 if [[ $3 == "production" ]] || [[ $3 == "prod" ]]; then deploy_mode="production --skip-compilation" is_mode_prod=1 admin_session_lifetime=43200 # 12h in seconds admin_password_lifetime=90 # days echo "Also make sure to run 'mage build' or 'bin/magento setup:static-content:deploy', when running production mode" else $PURGE_CLI generated/metadata/* $PURGE_CLI generated/code/* fi $MAGENTO_CLI config:set -q dev/static/sign $is_mode_prod $MAGENTO_CLI config:set -q admin/captcha/enable $is_mode_prod $MAGENTO_CLI config:set -q admin/security/session_lifetime $admin_session_lifetime $MAGENTO_CLI config:set -q admin/security/password_lifetime $admin_password_lifetime $MAGENTO_CLI config:set -q admin/security/password_is_forced $is_mode_prod $MAGENTO_CLI deploy:mode:set $deploy_mode ;; "set countries"*) scope="" countries="" for option in "${@:3}"; do if [[ "$option" =~ ^store: ]]; then # Extract argument after 'store:' (remove prefix) stripped_option=${option#store:} scope="$stripped_option" else countries="$countries $option" fi done if [[ -z "$countries" ]]; then countries="NL,BE,LU,DE" fi countries="$(mage_lang_format_arguments $countries)" country=$(echo "${countries}" | cut -d ',' -f 1 | tr '[:lower:]' '[:upper:]') if [[ -n "$scope" ]]; then echo "Setting the following countries: $countries for $scope" scope="--scope=stores --scope-code=${scope}" else echo "Setting the following countries: $countries" $MAGENTO_CLI config:set -q general/country/allow $countries fi $MAGENTO_CLI config:set -q $scope general/country/default $country $MAGENTO_CLI config:set -q $scope general/country/destinations $countries ;; "set fpc" | "set fpc default") $MAGENTO_CLI config:set system/full_page_cache/caching_application 1 ;; "set fpc varnish") $MAGENTO_CLI config:set system/full_page_cache/caching_application 2 ;; "log" | "log debug") tail -f -n 4 var/log/debug.log ;; "log exception") tail -f -n 8 var/log/exception.log ;; "log system") tail -f -n 8 var/log/system.log ;; "outdated") $COMPOSER_CLI outdated --direct --no-dev --ignore symfony/finder --ignore symfony/process --format json > composer-outdated.json ;; "build hyva") mage_build_hyva ;; "build"*) default_args="-j 4" args=${@:2} $MAGENTO_CLI setup:static-content:deploy ${args:-$default_args} ;; "run"*) if [[ -n "$MAGERUN_CLI" ]]; then $MAGERUN_CLI "${@:2}" else echo $NO_MAGERUN_MSG fi ;; *) $MAGENTO_CLI "$@" ;; esac