Skip to content

Commit e4412d0

Browse files
committed
refactor(setup-psalm-symlink): improve comments and streamline script execution flow
1 parent 18dd7f1 commit e4412d0

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed
Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
#!/bin/bash
22

33
# Determine the project root on the host dynamically
4-
HOST_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
4+
# This script is in .ddev/scripts/, so we need to go up two levels to get to the project root
5+
HOST_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
56

67
# Extract project name; handle potential quotes in config.yaml
78
PROJECT_NAME=$(grep '^name:' "$HOST_ROOT/.ddev/config.yaml" | awk '{print $2}' | tr -d '"' | tr -d "'")
89
CONTAINER_NAME="ddev-${PROJECT_NAME}-web"
910

10-
# Initialize an array for the new arguments
11-
NEW_ARGS=()
11+
echo "Setting up Psalm symlink for $PROJECT_NAME..."
12+
echo "Host Root: $HOST_ROOT"
13+
echo "Container Name: $CONTAINER_NAME"
1214

13-
for arg in "$@"; do
14-
# Skip arguments that would confuse the Psalm Phar inside the container
15-
[[ "$arg" == *"psalm.phar" ]] && continue
16-
[[ "$arg" == *"vendor/bin/psalm" ]] && continue
17-
[[ "$arg" == -d* ]] && continue
18-
[[ "$arg" == -f* ]] && continue
19-
[[ "$arg" == "--" ]] && continue
15+
# Create the directory structure for the symlink inside the container
16+
# We need to create the parent directory of the host root path
17+
PARENT_DIR=$(dirname "$HOST_ROOT")
2018

21-
NEW_ARGS+=("$arg")
22-
done
19+
# Create parent directory inside container
20+
docker exec -u root "$CONTAINER_NAME" mkdir -p "$PARENT_DIR"
2321

24-
# Execute Psalm
25-
# -i: keeps STDIN open (critical for Language Server Protocol)
26-
# -w: sets the working dir to the HOST path (which is symlinked in the container)
27-
# exec: replaces the bash process with docker so signals (like SIGTERM) are passed through
28-
exec docker exec -i -w "$HOST_ROOT" "$CONTAINER_NAME" ./vendor/bin/psalm.phar "${NEW_ARGS[@]}"
22+
# Create the symlink: HOST_ROOT -> /var/www/html
23+
# -s: symbolic link
24+
# -f: force (remove existing destination file)
25+
# -n: no dereference (treat destination as normal file if it is a symlink to a directory)
26+
docker exec -u root "$CONTAINER_NAME" ln -sfn /var/www/html "$HOST_ROOT"
27+
28+
echo "Symlink created: $HOST_ROOT -> /var/www/html inside $CONTAINER_NAME"

0 commit comments

Comments
 (0)