Skip to content

Commit

Permalink
ADD: new cmd new-module
Browse files Browse the repository at this point in the history
  • Loading branch information
GrimLink committed Aug 20, 2020
1 parent b2b0802 commit b528d11
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 1.4.0 - (2020-08-21)
* ADD:
* new cmd `new-module`
* IMP:
* casing of variables in `new-theme`

## 1.3.0 - (2020-05-16)
* ADD:
* new cmd `new-theme`
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ _Or download it via wget_
| purge | Purge all static assets |
| new-admin | Create new admin user _(*)_ |
| new-theme | Create new theme in app _(*)_ |
| new-module | Create new module in app |
| run | Run magerun2 (requires n98-magerun2) |

Any other command will run the same as `bin/magento`
Expand Down
55 changes: 47 additions & 8 deletions mage
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ help)
echo -e "${BOLD}Mage ${GREEN}1.3.0${RESET}"
echo -e "${ITALIC}See https://github.com/GrimLink/mage for the last version${RESET}\n"
echo -e "${BOLD}CMD Options:${RESET}"
echo -e "- ${BLUE}info${RESET} (Show base config for store)"
echo -e "- ${BLUE}open${RESET} (Open store in browser)"
echo -e "- ${BLUE}auth${RESET} (Copy the auth.json from root)"
echo -e "- ${BLUE}config${RESET} (Set configs for dev env)"
echo -e "- ${BLUE}purge${RESET} (Purge all static assets)"
echo -e "- ${BLUE}new-admin${RESET} (Create new admin user)"
echo -e "- ${BLUE}new-theme${RESET} (Create new theme in app)"
echo -e "- ${BLUE}run${RESET} (Run magerun2)"
echo -e "- ${BLUE}info${RESET} (Show base config for store)"
echo -e "- ${BLUE}open${RESET} (Open store in browser)"
echo -e "- ${BLUE}auth${RESET} (Copy the auth.json from root)"
echo -e "- ${BLUE}config${RESET} (Set configs for dev env)"
echo -e "- ${BLUE}purge${RESET} (Purge all static assets)"
echo -e "- ${BLUE}new-admin${RESET} (Create new admin user)"
echo -e "- ${BLUE}new-theme${RESET} (Create new theme in app)"
echo -e "- ${BLUE}new-module${RESET} (Create new module in app)"
echo -e "- ${BLUE}run${RESET} (Run magerun2)"
echo -e "\n${ITALIC}Anything else will run ${BLUE}bin/magento${RESET}"
echo -e "${ITALIC}To see those cmd's just run ${BLUE}mage${RESET}"
;;
Expand Down Expand Up @@ -190,6 +191,44 @@ ComponentRegistrar::register(
</theme>" >> $THEME/theme.xml
;;

new-module)
read -p "Vendor: " VENDOR
if [[ -z "$VENDOR" ]]; then echo "The 'Vendor' can not be empty" && exit 1; fi
read -p "Name: " NAME
if [[ -z "$NAME" ]]; then echo "The 'Name' can not be empty" && exit 1; fi

VENDOR="$(echo $VENDOR | tr '[:upper:]' '[:lower:]' | awk '{for(i=1;i<=NF;i++){ $i=toupper(substr($i,1,1)) substr($i,2) }}1' | tr -d '[:blank:]')";

CAMEL_NAME="$(echo $NAME | tr '[:upper:]' '[:lower:]' | awk '{for(i=1;i<=NF;i++){ $i=toupper(substr($i,1,1)) substr($i,2) }}1' | tr -d '[:blank:]')";
LOWER_NAME="$(tr '[:upper:][:blank:]' '[:lower:]-' <<< ${NAME})"

MODULE="app/code/$VENDOR/${CAMEL_NAME}"
mkdir -p $MODULE/etc

touch $MODULE/registration.php &&
echo -e "<?php
use Magento\Framework\Component\ComponentRegistrar;
ComponentRegistrar::register(
ComponentRegistrar::MODULE,
'${VENDOR}_${CAMEL_NAME}',
__DIR__
);" >> $MODULE/registration.php

touch $MODULE/etc/module.xml &&
echo -e "<?xml version=\"1.0\"?>
<config
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
xsi:noNamespaceSchemaLocation=\"urn:magento:framework:Module/etc/module.xsd\">
<module name=\"${VENDOR}_${CAMEL_NAME}\" setup_version=\"1.0.0\">
<sequence>
<module name=\"Magento_Theme\" />
</sequence>
</module>
</config>" >> $MODULE/etc/module.xml
;;

run)
if command -v magerun2 &>/dev/null; then
magerun2 ${@:2}
Expand Down

0 comments on commit b528d11

Please sign in to comment.