|
1 | 1 | #!/bin/bash |
2 | 2 |
|
3 | 3 | # 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)" |
5 | 6 |
|
6 | 7 | # Extract project name; handle potential quotes in config.yaml |
7 | 8 | PROJECT_NAME=$(grep '^name:' "$HOST_ROOT/.ddev/config.yaml" | awk '{print $2}' | tr -d '"' | tr -d "'") |
8 | 9 | CONTAINER_NAME="ddev-${PROJECT_NAME}-web" |
9 | 10 |
|
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" |
12 | 14 |
|
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") |
20 | 18 |
|
21 | | - NEW_ARGS+=("$arg") |
22 | | -done |
| 19 | +# Create parent directory inside container |
| 20 | +docker exec -u root "$CONTAINER_NAME" mkdir -p "$PARENT_DIR" |
23 | 21 |
|
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