Skip to content

add mage destroy <NAME> to fully remove a project#44

Open
allrude wants to merge 1 commit intomainfrom
feature/destroy-command
Open

add mage destroy <NAME> to fully remove a project#44
allrude wants to merge 1 commit intomainfrom
feature/destroy-command

Conversation

@allrude
Copy link
Collaborator

@allrude allrude commented Feb 22, 2026

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 *

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 GrimLink self-requested a review February 22, 2026 15:08
if [[ -f "$valet_env" ]]; then
while IFS= read -r _d; do
[[ -n "$_d" ]] && domains+=("$_d")
done < <(python3 -c "
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Convert to php

function mage_destroy_project() {
local name="$1"

if [[ -z "$name" ]]; then
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rework to work directly from the project folder

# 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"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optimize

echo "No name was given for the magento project, aborting.."
;;

"destroy")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add alias nuke

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants