add mage destroy <NAME> to fully remove a project#44
Open
Conversation
Adds a safe, interactive teardown command that removes everything
created by `mage create` for a given project in one step.
Usage (run from the parent directory of the project):
mage destroy my-project
What it destroys:
- Valet TLS certificates (cert files + macOS keychain entry)
- Valet nginx configs
- Valet site symlinks
- MySQL database (DROP DATABASE IF EXISTS)
- Project folder (rm -rf)
Safety:
- The command is explicitly allowlisted in the Magento root guard so it
can run from any directory (not just inside a Magento root).
- Shows a clear WARNING listing exactly what will be removed.
- Requires the user to type the full project name to confirm — any
mismatch aborts immediately with no changes made.
Valet cleanup is done directly on the filesystem (removing files from
~/.config/valet/Certificates/, Nginx/, and Sites/) so that nginx only
restarts once at the end, regardless of how many store domains exist,
instead of restarting once per domain as valet unsecure would do.
Domains are read from .valet-env.php; only top-level array keys are
treated as domain names (MAGE_RUN_CODE / MAGE_RUN_TYPE values are
ignored).
Changes:
src/_destroy.sh (new) — mage_destroy_project function
src/_global.sh — added destroy to the root-guard allowlist
src/_info.sh — added help entry for destroy [NAME]
src/_mage.sh — added dispatch cases for destroy and destroy *
GrimLink
reviewed
Feb 22, 2026
| if [[ -f "$valet_env" ]]; then | ||
| while IFS= read -r _d; do | ||
| [[ -n "$_d" ]] && domains+=("$_d") | ||
| done < <(python3 -c " |
GrimLink
reviewed
Feb 22, 2026
| function mage_destroy_project() { | ||
| local name="$1" | ||
|
|
||
| if [[ -z "$name" ]]; then |
Owner
There was a problem hiding this comment.
Rework to work directly from the project folder
GrimLink
reviewed
Feb 22, 2026
| # Valet cleanup — delete cert files, nginx configs, and site symlinks directly | ||
| # so we can do a single valet restart instead of one nginx restart per domain. | ||
| if [[ $VALET == 1 && ${#domains[@]} -gt 0 ]]; then | ||
| local _valet_cfg="$HOME/.config/valet" |
GrimLink
reviewed
Feb 22, 2026
| echo "No name was given for the magento project, aborting.." | ||
| ;; | ||
|
|
||
| "destroy") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a safe, interactive teardown command that removes everything created by
mage createfor a given project in one step.Usage (run from the parent directory of the project):
mage destroy my-project
What it destroys:
Safety:
Valet cleanup is done directly on the filesystem (removing files from ~/.config/valet/Certificates/, Nginx/, and Sites/) so that nginx only restarts once at the end, regardless of how many store domains exist, instead of restarting once per domain as valet unsecure would do. Domains are read from .valet-env.php; only top-level array keys are treated as domain names (MAGE_RUN_CODE / MAGE_RUN_TYPE values are ignored).
Changes:
src/_destroy.sh (new) — mage_destroy_project function
src/_global.sh — added destroy to the root-guard allowlist
src/_info.sh — added help entry for destroy [NAME]
src/_mage.sh — added dispatch cases for destroy and destroy *