diff --git a/wizards.mk b/wizards.mk index e648605..2a4d2be 100644 --- a/wizards.mk +++ b/wizards.mk @@ -6,6 +6,8 @@ include .onyx $(error .onyx file is missing) convert-namespace = $(subst ::,\\,$1) +convert-path-into-namespace = $(subst /,\\,$1) +extract-last-dir = $(lastword $(subst /, ,$1)) wizard-set-namespace: core-wizard-set-namespace composer-dumpautoload @@ -66,17 +68,17 @@ wizard-new-repository: .onyx @echo "" wizard-new-query: .onyx - $(eval QUERY_NAME := $(shell bash -c 'read -p "Enter your query name : " queryName; echo $$queryName')) - $(eval PARENT_TARGET_DIR := "src/Domain/Queries") - $(eval TARGET_DIR := "${PARENT_TARGET_DIR}/${QUERY_NAME}") + $(eval QUERY_FULL_PATH := $(shell bash -c 'read -p "Enter your query name [ex: Pony/Dimensions] : " queryName; echo $$queryName')) + $(eval QUERY_NAME := $(call extract-last-dir,${QUERY_FULL_PATH})) + $(eval TARGET_DIR := "src/Domain/Queries/${QUERY_FULL_PATH}") # Create directories - @mkdir -p ${PARENT_TARGET_DIR} + @mkdir -p ${TARGET_DIR} # Copy files - @cp -rf vendor/onyx/core/wizards/query/* ${PARENT_TARGET_DIR} + @cp -rf vendor/onyx/core/wizards/query/* ${TARGET_DIR} # Rename files - @mv ${PARENT_TARGET_DIR}/__ONYX_QueryName ${TARGET_DIR} @mv ${TARGET_DIR}/__ONYX_QueryNameQuery.php ${TARGET_DIR}/${QUERY_NAME}Query.php # Replace placeholders in code + @find ${TARGET_DIR} -type f -exec sed -i 's,__ONYX_QueryNamespace,$(call convert-path-into-namespace,${QUERY_FULL_PATH}),g' {} \; @find ${TARGET_DIR} -type f -exec sed -i 's/__ONYX_QueryName/${QUERY_NAME}/g' {} \; @find ${TARGET_DIR} -type f -exec sed -i 's/__ONYX_Namespace/$(call convert-namespace,$(NAMESPACE))/g' {} \; # Done @@ -86,17 +88,17 @@ wizard-new-query: .onyx @echo "" wizard-new-command: .onyx - $(eval COMMAND_NAME := $(shell bash -c 'read -p "Enter your command name : " commandName; echo $$commandName')) - $(eval PARENT_TARGET_DIR := "src/Domain/Commands") - $(eval TARGET_DIR := "${PARENT_TARGET_DIR}/${COMMAND_NAME}") + $(eval COMMAND_FULL_PATH := $(shell bash -c 'read -p "Enter your command name [ex: Pony/Mount] : " commandName; echo $$commandName')) + $(eval COMMAND_NAME := $(call extract-last-dir,${COMMAND_FULL_PATH})) + $(eval TARGET_DIR := "src/Domain/Commands/${COMMAND_FULL_PATH}") # Create directories - @mkdir -p ${PARENT_TARGET_DIR} + @mkdir -p ${TARGET_DIR} # Copy files - @cp -rf vendor/onyx/core/wizards/command/* ${PARENT_TARGET_DIR} + @cp -rf vendor/onyx/core/wizards/command/* ${TARGET_DIR} # Rename files - @mv ${PARENT_TARGET_DIR}/__ONYX_CommandName ${TARGET_DIR} @mv ${TARGET_DIR}/__ONYX_CommandNameCommand.php ${TARGET_DIR}/${COMMAND_NAME}Command.php # Replace placeholders in code + @find ${TARGET_DIR} -type f -exec sed -i 's,__ONYX_CommandNamespace,$(call convert-path-into-namespace,${COMMAND_FULL_PATH}),g' {} \; @find ${TARGET_DIR} -type f -exec sed -i 's/__ONYX_CommandName/${COMMAND_NAME}/g' {} \; @find ${TARGET_DIR} -type f -exec sed -i 's/__ONYX_Namespace/$(call convert-namespace,$(NAMESPACE))/g' {} \; # Done diff --git a/wizards/command/__ONYX_CommandName/Handler.php b/wizards/command/Handler.php similarity index 83% rename from wizards/command/__ONYX_CommandName/Handler.php rename to wizards/command/Handler.php index e75117c..e87fc74 100644 --- a/wizards/command/__ONYX_CommandName/Handler.php +++ b/wizards/command/Handler.php @@ -2,7 +2,7 @@ declare(strict_types = 1); -namespace __ONYX_Namespace\Domain\Commands\__ONYX_CommandName; +namespace __ONYX_Namespace\Domain\Commands\__ONYX_CommandNamespace; use Onyx\Services\CQS\Command; use Onyx\Services\CQS\CommandHandler; diff --git a/wizards/command/__ONYX_CommandName/__ONYX_CommandNameCommand.php b/wizards/command/__ONYX_CommandNameCommand.php similarity index 77% rename from wizards/command/__ONYX_CommandName/__ONYX_CommandNameCommand.php rename to wizards/command/__ONYX_CommandNameCommand.php index 072aa8f..a32bb2e 100644 --- a/wizards/command/__ONYX_CommandName/__ONYX_CommandNameCommand.php +++ b/wizards/command/__ONYX_CommandNameCommand.php @@ -2,7 +2,7 @@ declare(strict_types = 1); -namespace __ONYX_Namespace\Domain\Commands\__ONYX_CommandName; +namespace __ONYX_Namespace\Domain\Commands\__ONYX_CommandNamespace; use Onyx\Services\CQS\Command; diff --git a/wizards/query/__ONYX_QueryName/Handler.php b/wizards/query/Handler.php similarity index 86% rename from wizards/query/__ONYX_QueryName/Handler.php rename to wizards/query/Handler.php index 50bfb4e..ef6763d 100644 --- a/wizards/query/__ONYX_QueryName/Handler.php +++ b/wizards/query/Handler.php @@ -2,7 +2,7 @@ declare(strict_types = 1); -namespace __ONYX_Namespace\Domain\Queries\__ONYX_QueryName; +namespace __ONYX_Namespace\Domain\Queries\__ONYX_QueryNamespace; use Onyx\Services\CQS\Query; use Onyx\Services\CQS\QueryHandler; diff --git a/wizards/query/__ONYX_QueryName/Result.php b/wizards/query/Result.php similarity index 77% rename from wizards/query/__ONYX_QueryName/Result.php rename to wizards/query/Result.php index d5e3a3c..65afb03 100644 --- a/wizards/query/__ONYX_QueryName/Result.php +++ b/wizards/query/Result.php @@ -2,7 +2,7 @@ declare(strict_types = 1); -namespace __ONYX_Namespace\Domain\Queries\__ONYX_QueryName; +namespace __ONYX_Namespace\Domain\Queries\__ONYX_QueryNamespace; use Onyx\Services\CQS\QueryResult; diff --git a/wizards/query/__ONYX_QueryName/__ONYX_QueryNameQuery.php b/wizards/query/__ONYX_QueryNameQuery.php similarity index 77% rename from wizards/query/__ONYX_QueryName/__ONYX_QueryNameQuery.php rename to wizards/query/__ONYX_QueryNameQuery.php index 1df23d5..47ceeb8 100644 --- a/wizards/query/__ONYX_QueryName/__ONYX_QueryNameQuery.php +++ b/wizards/query/__ONYX_QueryNameQuery.php @@ -2,7 +2,7 @@ declare(strict_types = 1); -namespace __ONYX_Namespace\Domain\Queries\__ONYX_QueryName; +namespace __ONYX_Namespace\Domain\Queries\__ONYX_QueryNamespace; use Onyx\Services\CQS\Query;