-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathn
More file actions
executable file
·545 lines (527 loc) · 24.8 KB
/
Copy pathn
File metadata and controls
executable file
·545 lines (527 loc) · 24.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
#!/bin/bash
NABSPATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
source "$(dirname "${BASH_SOURCE[0]}")/bin/repos.sh"
# Use -it flags only when TTY is available
if [ -t 0 ] && [ -t 1 ]; then
DOCKER_IT="-it"
else
DOCKER_IT=""
fi
# Determine target container based on current directory
# If inside a worktree, find the environment whose compose file mounts that
# exact worktree path; otherwise use newspack_dev.
#
# Earlier versions used a 2-segment regex prefix that collapsed branches with
# slashes (e.g. `jl/news-2239-pr1b-frontend` -> `jl`), causing false matches
# when multiple envs mounted `jl/*` worktrees. This version reads each compose
# file's actual mount lines and picks the LONGEST absolute path that PWD
# starts with — unambiguous regardless of branch-name shape.
get_target_container() {
if [[ "$PWD" == "$NABSPATH/worktrees/"* ]]; then
local best_match="" best_env=""
for f in "$NABSPATH"/docker-compose.env-*.yml; do
[[ -f "$f" ]] || continue
while IFS= read -r mount; do
# Mounts can take two shapes — pre-monorepo per-plugin worktrees
# (./worktrees/<repo>/<branch>:/newspack-repos/<repo>) and
# monorepo workspace worktrees (./worktrees/<safe_branch>/plugins/<name>:/newspack-plugins/<name>,
# or .../themes/<name>:/newspack-themes/<name>). For the
# monorepo shape, the env mounts a per-plugin subdir but we
# also want to route correctly from elsewhere inside the
# worktree (its root, bin/, packages/, sibling plugins). Match
# by the enclosing worktree root instead of only the mounted
# subdir. Regex extraction tolerates tabs/multi-space and cuts
# cleanly at the next `:` so mount-mode suffixes (`:ro`) and
# trailing comments don't corrupt the captured paths.
[[ "$mount" =~ ^[[:space:]]*-[[:space:]]+\./worktrees/([^[:space:]:]+):/newspack-(repos|plugins|themes)/[^[:space:]:]+ ]] || continue
local rel="worktrees/${BASH_REMATCH[1]}"
local container_type="${BASH_REMATCH[2]}"
local abs="$NABSPATH/$rel"
local worktree_root="$abs"
case "$container_type" in
plugins|themes)
worktree_root="${abs%/plugins/*}"
worktree_root="${worktree_root%/themes/*}"
;;
esac
# Prefer the deeper mounted-subpath match (more specific) so
# PWD inside a mounted plugin/theme routes to that env even
# when a sibling env mounts a different plugin from the same
# worktree. Fall back to the worktree root for PWDs in
# shared dirs (bin/, packages/, the worktree root itself).
if [[ "$PWD" == "$abs" || "$PWD" == "$abs"/* ]] && [ ${#abs} -gt ${#best_match} ]; then
best_match="$abs"
best_env=$(basename "$f" | sed 's/docker-compose\.env-//;s/\.yml//')
elif [[ "$PWD" == "$worktree_root" || "$PWD" == "$worktree_root"/* ]] && [ ${#worktree_root} -gt ${#best_match} ]; then
best_match="$worktree_root"
best_env=$(basename "$f" | sed 's/docker-compose\.env-//;s/\.yml//')
fi
done < <(grep -E '^[[:space:]]*-[[:space:]]+\./worktrees/[^[:space:]:]+:/newspack-(repos|plugins|themes)/[^[:space:]:]+' "$f" 2>/dev/null)
done
if [ -n "$best_env" ]; then
echo "newspack_env_${best_env}" | tr '-' '_'
return
fi
fi
echo "newspack_dev"
}
# Cache the target container for this invocation
TARGET_CONTAINER=$(get_target_container)
# Show feedback when targeting an isolated environment
if [[ "$TARGET_CONTAINER" != "newspack_dev" ]]; then
echo "[n] Targeting container: $TARGET_CONTAINER" >&2
fi
# Infer the current working project from the current folder;
projects=("${newspack_plugins[@]}" "newspack-theme" "newspack-block-theme") # create a new list with the appended value
target_folder=""
# Match on path-segment boundaries (not a raw substring) so a checkout whose
# name merely contains a monorepo slug (e.g. newspack-ads-pro) isn't
# mis-identified as the monorepo project (newspack-ads).
for plugin in "${projects[@]}"; do
if [[ "$PWD" == *"/$plugin/"* || "$PWD" == *"/$plugin" ]]; then
target_folder=$plugin
fi
done
# Standalone/local checkouts under repos/{plugins,themes}/<name> need no
# registration: derive the project from the path via parameter expansion (no
# subprocess). Gated on no monorepo match above so a tracked project of the
# same name still wins.
if [[ -z "$target_folder" && "$PWD" == *"/repos/plugins/"* ]]; then
rest="${PWD##*/repos/plugins/}"
target_folder="${rest%%/*}"
elif [[ -z "$target_folder" && "$PWD" == *"/repos/themes/"* ]]; then
rest="${PWD##*/repos/themes/}"
target_folder="${rest%%/*}"
fi
path_param=""
current_site_path="/var/www/html"
current_site_relative_path="html"
# if current working folder is a folder inside the additional-sites folder, set the current_site to it
# if I am inside this folder several levels, return only the name of the first folder after additional-sites
if [[ "$PWD" == *"additional-sites-html"* ]]; then
current_site=$(echo $PWD | sed -e 's/.*additional-sites-html\///' | cut -d'/' -f1)
current_site_path="/var/www/additional-sites-html/$current_site"
current_site_relative_path="additional-sites-html/$current_site"
path_param="--path=$current_site_path"
fi
if [[ "$PWD" == *"manager-html"* ]]; then
current_site_path="/var/www/manager-html"
current_site_relative_path="manager-html"
path_param="--path=$current_site_path"
fi
cd "$(dirname "$0")"
source .env
if [ $# -eq 0 ]; then
echo "No arguments provided. Run 'n help' to see available commands." >&2
exit 1
fi
if [ ! -z "$USE_CUSTOM_APACHE_USER" ]
then
USER_COMMAND="--user $USE_CUSTOM_APACHE_USER "
else
USER_COMMAND=""
fi
require_target_folder() {
if [[ -z "$target_folder" ]]; then
echo "Error: You must be inside one of the repos to run this command." >&2
exit 1
fi
}
start() {
file="docker-compose.yml"
if [ "$1" == "8.2" ]; then
file="docker-compose-82.yml"
fi
docker compose -f $file up -d
# Create shared network for inter-container communication.
# Env containers join this network with their domain as an alias,
# so they can reach each other by domain name via Docker DNS.
if ! docker network inspect newspack_envs >/dev/null 2>&1; then
if ! docker network create newspack_envs >/dev/null; then
echo "Error: failed to create Docker network 'newspack_envs'. Is Docker running?" >&2
exit 1
fi
echo "Created shared network: newspack_envs"
fi
# macOS: set up loopback aliases for isolated environments.
# Pre-allocate 127.0.0.2–100 so agents can create envs without sudo later.
# These don't survive reboots, so this runs on every start.
if [[ "$(uname)" == "Darwin" ]]; then
missing_aliases=()
lo0_addrs=$(ifconfig lo0 2>/dev/null)
for octet in $(seq 2 100); do
ip="127.0.0.$octet"
if ! echo "$lo0_addrs" | grep -qE "inet $ip( |$)"; then
missing_aliases+=("$ip")
fi
done
missing_hosts=()
for f in "$NABSPATH"/docker-compose.env-*.yml; do
[[ -f "$f" ]] || continue
domain=$(grep 'WP_DOMAIN=' "$f" | head -1 | sed 's/.*WP_DOMAIN=//')
ip=$(grep -o '127\.0\.0\.[0-9]*' "$f" | head -1)
# Only add hosts entries for custom domains, not IP-based ones.
if [[ -n "$domain" && "$domain" != "$ip" ]] && ! grep -q "[[:space:]]${domain}" /etc/hosts 2>/dev/null; then
missing_hosts+=("$ip $domain")
fi
done
if [[ ${#missing_aliases[@]} -gt 0 || ${#missing_hosts[@]} -gt 0 ]]; then
# Use the wrapper script if installed (passwordless sudo), otherwise fall back to raw sudo.
if command -v newspack-manage-host >/dev/null 2>&1; then
for ip in "${missing_aliases[@]}"; do
sudo newspack-manage-host alias-add "$ip"
done
for entry in "${missing_hosts[@]}"; do
read -r ip domain <<< "$entry"
if [[ "$domain" == *.test || "$domain" == *.local ]]; then
sudo newspack-manage-host host-add "$ip" "$domain"
else
echo "$ip $domain" | sudo tee -a /etc/hosts > /dev/null
fi
done
else
echo ""
echo "Setting up networking for isolated environments (requires sudo)..."
for ip in "${missing_aliases[@]}"; do
sudo ifconfig lo0 alias "$ip"
done
for entry in "${missing_hosts[@]}"; do
echo "$entry" | sudo tee -a /etc/hosts > /dev/null
done
fi
echo "Ready: loopback aliases 127.0.0.2–100, $(( ${#missing_hosts[@]} )) hosts entries."
fi
fi
}
stop() {
docker compose down
}
switch_all_repos_to_branch() {
echo "In a monorepo, all code shares a single branch."
echo "Use 'git checkout $1' at the workspace root instead."
}
# NOTE: when adding a new command, update the 'help' case below.
case $1 in
start)
start "${@:2}"
;;
stop)
stop
;;
restart)
stop
start "${@:2}"
;;
sh)
if [[ -n "$2" ]]; then
container=$(echo "newspack_env_${2}" | tr '-' '_')
docker exec $DOCKER_IT $USER_COMMAND "$container" /bin/bash
else
docker exec $DOCKER_IT $USER_COMMAND $TARGET_CONTAINER /bin/bash
fi
;;
rsh)
docker exec $DOCKER_IT $TARGET_CONTAINER /bin/bash
;;
cd-install)
echo "This will install the ncd command in your system. Please inform the file you want to add this to (e.g. .bashrc)"
read -e -p "> $HOME/" file
target="$HOME/$file"
# Resolve symlinks so sed -i works on the real file
if [ -L "$target" ]; then
target="$(readlink -f "$target")"
fi
snippet="source \"$NABSPATH/bin/ncd.sh\""
if grep -q "bin/ncd.sh" "$target" 2>/dev/null; then
# Update existing installation if the path has changed (e.g. repo moved or renamed)
current_root=$(grep "NEWSPACK_DOCKER_ROOT=" "$target" | head -1 | cut -d= -f2- | tr -d '"')
if [ "$current_root" = "$NABSPATH" ]; then
echo "ncd is already installed on $target"
else
root_sub="s|NEWSPACK_DOCKER_ROOT=.*|NEWSPACK_DOCKER_ROOT=\"$NABSPATH\"|"
source_sub="s|source .*/bin/ncd\.sh\"*|source \"$NABSPATH/bin/ncd.sh\"|"
# Try BSD sed first, fall back to GNU sed
{ sed -i '' "$root_sub" "$target" 2>/dev/null || sed -i "$root_sub" "$target"; } && \
{ sed -i '' "$source_sub" "$target" 2>/dev/null || sed -i "$source_sub" "$target"; }
if [ $? -eq 0 ]; then
echo "ncd path updated in $target"
echo
echo "Restart your terminal or run 'source $target' to apply the changes"
else
echo "Error: failed to update $target."
fi
fi
else
echo "NEWSPACK_DOCKER_ROOT=\"$NABSPATH\"" >> "$target"
echo "$snippet" >> "$target"
echo "ncd installed!"
echo
echo "Restart your terminal or run 'source $target' to start using it"
echo
echo "To use it, just type 'ncd <folder>'"
echo "It will look for matches on the repos folder, the additional-sites-html folder and the plugins folder of the main site"
fi
;;
install)
docker exec $DOCKER_IT $USER_COMMAND $TARGET_CONTAINER sh -c "/var/scripts/install.sh $current_site_path"
;;
uninstall)
docker exec $DOCKER_IT $USER_COMMAND $TARGET_CONTAINER sh -c "/var/scripts/uninstall.sh $current_site_path"
;;
reset-site)
docker exec $DOCKER_IT $USER_COMMAND $TARGET_CONTAINER sh -c "/var/scripts/reset-site.sh $current_site_path"
;;
setup)
shift
setup_container="$TARGET_CONTAINER"
setup_env_name=""
setup_args=()
while [[ $# -gt 0 ]]; do
if [[ "$1" == "--env" ]]; then
if [[ $# -lt 2 || "$2" == --* ]]; then
echo "Error: --env requires an environment name." >&2
echo "Usage: n setup [--env ENV_NAME] [setup-args...]" >&2
exit 1
fi
setup_env_name="$2"
setup_container=$(echo "newspack_env_${2}" | tr '-' '_')
current_site_path="/var/www/html"
shift 2
else
setup_args+=("$1")
shift
fi
done
# For isolated envs with --woocommerce, copy third-party plugins from the main site.
if [[ -n "$setup_env_name" ]] && [[ " ${setup_args[*]} " == *" --woocommerce "* ]]; then
main_plugins="$NABSPATH/html/wp-content/plugins"
env_plugins="$NABSPATH/envs/${setup_env_name}/html/wp-content/plugins"
mkdir -p "$env_plugins"
for plugin in "${woocommerce_plugins[@]}"; do
if [[ -e "$env_plugins/$plugin" ]]; then
continue
elif [[ -d "$main_plugins/$plugin" || -L "$main_plugins/$plugin" ]]; then
# Use -L to also match symlinks to container-only paths (e.g. /newspack-repos/).
# Resolve symlinks via readlink so cp can follow the host-side path.
src="$main_plugins/$plugin"
if [[ -L "$src" ]]; then
target="$(readlink "$src")"
# Translate container path /newspack-plugins/<name> to host path plugins/<name>.
if [[ "$target" == /newspack-plugins/* ]]; then
src="$NABSPATH/plugins/${target#/newspack-plugins/}"
elif [[ "$target" == /newspack-themes/* ]]; then
src="$NABSPATH/themes/${target#/newspack-themes/}"
fi
fi
if [[ -d "$src" ]]; then
echo "Copying $plugin from main site to $setup_env_name..."
cp -r "$src" "$env_plugins/$plugin" || echo "Warning: failed to copy $plugin." >&2
else
echo "Warning: $plugin symlink target not found. WooCommerce setup may be incomplete." >&2
fi
else
echo "Warning: $plugin not found in main site. WooCommerce setup may be incomplete." >&2
fi
done
fi
docker exec $DOCKER_IT $USER_COMMAND "$setup_container" /var/scripts/site-setup.sh "$current_site_path" "${setup_args[@]}"
;;
tail)
tail -f $current_site_relative_path/wp-content/debug.log
;;
wp)
cmd="wp --allow-root $path_param ${@:2}"
docker exec $DOCKER_IT $USER_COMMAND $TARGET_CONTAINER $cmd
;;
db)
docker exec $DOCKER_IT $USER_COMMAND $TARGET_CONTAINER sh -c "wp db cli --allow-root $path_param"
;;
shell)
docker exec $DOCKER_IT $USER_COMMAND $TARGET_CONTAINER sh -c "wp shell --allow-root $path_param"
;;
install-manager)
docker exec $DOCKER_IT $USER_COMMAND $TARGET_CONTAINER sh -c "/var/scripts/install-manager.sh"
;;
setup-manager)
docker exec $DOCKER_IT $USER_COMMAND $TARGET_CONTAINER sh -c "/var/scripts/init-wp-manager.sh"
docker exec $DOCKER_IT $USER_COMMAND $TARGET_CONTAINER sh -c "/var/scripts/setup-manager.sh"
;;
sites-add)
docker exec $DOCKER_IT $TARGET_CONTAINER sh -c "/var/scripts/sites-add.sh $2"
if ! grep -q "[[:space:]]$2\.test" /etc/hosts; then
read -p "Do you want to add this domain to your local hosts file? (Y/n): " choice
choice=$(echo "$choice" | tr '[:upper:]' '[:lower:]')
if [[ "$choice" != "n" ]]; then
echo "127.0.0.1 $2.test" | sudo tee -a /etc/hosts
fi
fi
;;
sites-list)
docker exec $DOCKER_IT $TARGET_CONTAINER sh -c "/var/scripts/sites-list.sh ${@:2}"
;;
sites-drop)
docker exec $DOCKER_IT $TARGET_CONTAINER sh -c "/var/scripts/sites-drop.sh ${@:2}"
;;
build)
if [[ -n "$2" ]]; then
target_folder=$2
fi
docker exec $DOCKER_IT $USER_COMMAND $TARGET_CONTAINER sh -c "/var/scripts/build-repos.sh $target_folder"
;;
ci-build)
if [[ -n "$2" ]]; then
target_folder=$2
fi
docker exec $DOCKER_IT $USER_COMMAND $TARGET_CONTAINER sh -c "/var/scripts/build-repos.sh $target_folder ci"
;;
watch)
if [[ -n "$2" ]]; then
target_folder=$2
fi
if [[ -z "$target_folder" ]]; then
# No project: watch every unit from the monorepo root, spawning each
# unit's own watcher lazily on its first edit. Note this also covers
# running `n watch` from a non-project dir (e.g. additional-sites-html/
# or manager-html/), where cwd detection yields no target_folder.
docker exec $DOCKER_IT $USER_COMMAND $TARGET_CONTAINER sh -c "/var/scripts/watch-all.sh"
else
# Run the script directly (no `sh -c`) and quote the folder so a
# project name can't be word-split or injected into a shell string.
docker exec $DOCKER_IT $USER_COMMAND $TARGET_CONTAINER /var/scripts/watch-repo.sh "$target_folder"
fi
;;
test-php)
require_target_folder
command="/var/scripts/test-php.sh $target_folder ${@:2}"
docker exec $DOCKER_IT $USER_COMMAND $TARGET_CONTAINER sh -c "$command"
;;
test-js)
require_target_folder
docker exec $DOCKER_IT $USER_COMMAND $TARGET_CONTAINER sh -c "/var/scripts/test-js.sh $target_folder"
;;
composer)
require_target_folder
command="/var/scripts/composer.sh $target_folder ${@:2}"
docker exec $DOCKER_IT $USER_COMMAND $TARGET_CONTAINER sh -c "$command"
;;
npm)
require_target_folder
command="/var/scripts/npm.sh $target_folder ${@:2}"
docker exec $DOCKER_IT $USER_COMMAND $TARGET_CONTAINER sh -c "$command"
;;
secrets)
docker exec $DOCKER_IT $USER_COMMAND $TARGET_CONTAINER sh -c "wp eval-file /var/scripts/generate-secrets.php --allow-root"
;;
secrets-import)
docker exec $DOCKER_IT $USER_COMMAND $TARGET_CONTAINER sh -c "/var/scripts/import-secrets.sh"
;;
snapshot)
docker exec $DOCKER_IT $USER_COMMAND $TARGET_CONTAINER sh -c "/var/scripts/snapshot-create.sh $2"
;;
snapshot-load)
docker exec $DOCKER_IT $USER_COMMAND $TARGET_CONTAINER sh -c "/var/scripts/snapshot-load.sh $2"
;;
jncp)
cmd="/var/scripts/jn-cp.sh ${@:2}"
docker exec $DOCKER_IT $USER_COMMAND $TARGET_CONTAINER $cmd
;;
jninit)
cmd="/var/scripts/jn-init.sh ${@:2}"
docker exec $DOCKER_IT $USER_COMMAND $TARGET_CONTAINER $cmd
;;
pull)
echo "Pulling latest from origin..."
cd "$NABSPATH" && git pull
;;
branch)
switch_all_repos_to_branch $2
;;
trunk)
switch_all_repos_to_branch trunk
;;
alpha)
switch_all_repos_to_branch alpha
;;
release)
switch_all_repos_to_branch release
;;
setup-newspack-network)
docker exec $DOCKER_IT $USER_COMMAND $TARGET_CONTAINER sh -c "/var/scripts/setup-newspack-network.sh"
;;
worktree)
"$NABSPATH/bin/worktree.sh" "${@:2}"
;;
env)
"$NABSPATH/bin/env.sh" "${@:2}"
;;
root)
echo "$NABSPATH"
;;
setup-agents)
"$NABSPATH/bin/setup-agents.sh"
;;
help)
echo "Available commands:"
echo ""
echo "Container Management:"
echo " start [version] Start the Docker containers. Optionally specify a PHP version (e.g. 8.2)."
echo " stop Stop the Docker containers."
echo " restart [version] Restart the Docker containers. Optionally specify a PHP version (e.g. 8.2)."
echo " sh Open a bash shell inside the container as the Apache user."
echo " rsh Open a bash shell inside the container as root."
echo ""
echo "WordPress:"
echo " install Run the installation script for the current site."
echo " uninstall Run the uninstallation script for the current site."
echo " reset-site Reset the current site to a clean state."
echo " setup [--env name] [opts] Bootstrap a Newspack site. Run 'n setup --help' for options."
echo " wp [args] Run a WP-CLI command for the current site."
echo " db Open a WP-CLI database shell for the current site."
echo " shell Open a WP-CLI shell for the current site."
echo " tail Tail the debug.log file of the current site."
echo " secrets Export current site secrets (API keys, options, constants) as JSON."
echo " secrets-import Import secrets from secrets.json into the current site."
echo " snapshot [name] Create a snapshot of the current site with the given name."
echo " snapshot-load [name] Load a snapshot with the given name into the current site."
echo ""
echo "Building & Testing:"
echo " build [folder] Build the specified folder (plugin/theme) or all for every repo."
echo " ci-build [folder] Build for CI environment with specific optimizations."
echo " watch [folder] Watch & rebuild the given/current repo; no arg watches every unit from the root."
echo " test-php [args] Run PHP tests for the current repo with optional arguments."
echo " test-js Run JavaScript tests for the current repo."
echo " composer [args] Run a composer command for the current repo."
echo " npm [args] Run an npm command for the current repo."
echo ""
echo "Multi-site:"
echo " sites-add [name] Add a new additional site with the given name."
echo " sites-list List all additional sites."
echo " sites-drop [name] Remove an additional site with the given name."
echo " install-manager Install WordPress on the Newspack Manager site."
echo " setup-manager Set up WordPress Manager plugin on the manager site."
echo " setup-newspack-network Set up Newspack Network Docker environment."
echo ""
echo "Repository Management:"
echo " pull Pull the latest changes for all repositories."
echo " branch [name] Switch all repositories to the specified branch."
echo " trunk Switch all repositories to the trunk branch."
echo " alpha Switch all repositories to the alpha branch."
echo " release Switch all repositories to the release branch."
echo ""
echo "Isolated Environments:"
echo " worktree [args] Manage Git worktrees for repositories (add, list, remove, cleanup)."
echo " env [args] Manage isolated environments (create, up, down, destroy, list, cleanup)."
echo ""
echo "AI Agents:"
echo " setup-agents Set up AI agent tooling for Newspack development."
echo ""
echo "Other:"
echo " root Print the absolute path to the workspace root directory."
echo " cd-install Install the ncd command for easy navigation to repos and sites."
echo " jncp [args] Copy selected plugins to a Jurassic Ninja site via SSH."
echo " jninit [args] Initialize a Jurassic Ninja site with Newspack and WooCommerce plugins."
;;
*)
echo "Unknown command: $1. Run 'n help' to see available commands."
;;
esac