-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathlpd
More file actions
executable file
·1707 lines (1535 loc) · 46.1 KB
/
lpd
File metadata and controls
executable file
·1707 lines (1535 loc) · 46.1 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
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
# @script lpd
# @category orchestrator
# @purpose infrastructure:pipeline-orchestration
# @scope full-repo
# @owner docs
# @needs R-R29
# @purpose-statement Developer CLI orchestrator — unified command surface for setup, dev server, testing, hooks, and script execution across all repo domains
# @pipeline manual — not yet in pipeline
set -euo pipefail
CLI_VERSION="0.2.0"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$SCRIPT_DIR"
if git_root="$(git -C "$PWD" rev-parse --show-toplevel 2>/dev/null)"; then
if [ -f "$git_root/docs.json" ] && [ -d "$git_root/tools" ]; then
REPO_ROOT="$git_root"
fi
fi
cd "$REPO_ROOT"
GLOBAL_JSON=0
if [ "${1:-}" = "--json" ]; then
GLOBAL_JSON=1
shift
fi
print_main_help() {
cat <<'EOF'
Root command: `lpd` (preferred, when on PATH) or `./lpd` (repo-local fallback).
`lpd` is the Livepeer Docs command-line interface for setting up this repo, running local docs development, executing tests, managing hooks, and invoking project scripts through one consistent entrypoint.
Usage:
lpd help
- info: Show command summary and examples.
lpd info
- info: Show CLI purpose, command groups, and workflows.
lpd version
- info: Print CLI version.
lpd setup [--yes] [--no-tools] [--no-tests] [--no-hooks] [--with-mintlify] [--no-cli] [--json]
- flags: control dependency installs, hook install, Mintlify install, and CLI PATH wiring.
- info: Bootstrap local environment for docs development.
lpd doctor [--strict] [--json]
- flags: `--strict` makes warnings fail.
- info: Check local environment and repo readiness.
lpd dev [--test] [--test-mode fast|staged|full] [--script <path>] [--scoped] [--scope-...] [-- ...mint args]
- flags: run advisory tests first, optional scoped docs profile for large docs.json, override launcher script, pass-through Mintlify args.
- info: Run local docs dev launcher.
lpd mint dev [--scoped] [--scope-...] [-- ...mint args]
- flags: same as `lpd dev`, plus pass-through Mintlify args.
- info: Compatibility alias to `lpd dev`.
lpd test [--staged|--full] [--browser] [--domain v1|v2|both] [--wcag] [--wcag-no-fix] [--link-audit-external] [--base-url URL]
- flags: choose test scope and optional browser/domain/WCAG/external-link-audit checks.
- info: Run test suite with optional integration checks.
lpd ai-sitemap [--write|--check] [--json]
- flags: write or verify the AI sitemap artifact.
- info: Generate or validate sitemap-ai.xml.
lpd ci [--skip-browser] [--base-url URL]
- flags: optionally skip browser checks and set domain audit base URL.
- info: Run CI-like validation flow locally.
lpd hooks <install|status|verify|info|<hook-script tokens...>>
- flags: subcommands define the hook action.
- info: Manage hooks or run hook scripts.
lpd scripts <list|run> ...
- flags: use `list` to discover commands and `run` to execute.
- info: List or execute managed scripts.
lpd <tools|tasks|tests|v2> <script-path tokens...> [-- script args]
- flags: script-path tokens resolve to a managed script in that group.
- info: Shorthand for `lpd scripts run <group> ...`.
Examples:
lpd dev
- Starts local docs development server with default options.
lpd dev --test --test-mode staged -- --port 3333
- Runs staged checks, then launches docs server on port 3333.
lpd dev --scoped --scope-version v2 --scope-language en --scope-tab Developers
- Launches Mint with a reduced dev-only docs profile for faster startup and route transitions.
lpd test --browser
- Runs tests plus browser integration checks.
lpd test --staged --wcag
- Runs staged tests and a staged/capped WCAG audit (autofix enabled by default).
lpd ai-sitemap --write
- Generates sitemap-ai.xml at repo root.
lpd scripts list --group tools
- Lists available scripts in the tools group.
lpd tools dev test-add-callouts -- --help
- Shows help for a managed tools/dev script via shorthand.
lpd scripts run tasks run-audit --dry-run
- Previews the exact task-script command without executing.
Notes:
- `lpd dev` auto-installs/updates pre-commit hooks via tools/scripts/mint-dev.sh.
- Human `.allowlist` edits require: `git commit -m "msg" --trailer "allowlist-edit=true"`.
- Human deletions require: `git commit -m "msg" --trailer "allow-deletions=true"`.
- Script discovery supports `.lpdignore` (gitignore-style patterns) if present in repo root.
EOF
}
cmd_info() {
while [ "$#" -gt 0 ]; do
case "$1" in
--help|-h)
cat <<'EOF'
Usage: lpd info
Shows CLI-tool information (purpose, command map, and common workflows).
EOF
return 0
;;
*)
finish 1 "info" "Unknown option: $1"
return 1
;;
esac
shift
done
cat <<'EOF'
lpd (Livepeer Docs CLI) is a task runner for docs development operations in this repository.
It standardizes setup, local preview, test runs, hooks, and curated script execution behind one command surface.
Command Groups:
core
lpd setup [--yes] [--no-tools] [--no-tests] [--no-hooks] [--with-mintlify] [--no-cli]
lpd doctor [--strict] [--json]
lpd dev [--test] [--test-mode fast|staged|full] [--scoped] [--scope-...] [-- ...mint args]
lpd test [--staged|--full] [--browser] [--domain v1|v2|both] [--wcag] [--wcag-no-fix] [--link-audit-external] [--base-url URL]
lpd ai-sitemap [--write|--check] [--json]
lpd ci [--skip-browser] [--base-url URL]
hooks
lpd hooks install
lpd hooks status
lpd hooks verify
lpd hooks info
script runner
lpd scripts list [--group tools|tasks|tests|v2|hooks] [--show-ignored]
lpd scripts run <group> <script-path tokens...> [--yes] [--dry-run] [-- script args]
shorthand: lpd <tools|tasks|tests|v2> <script-path tokens...> [-- script args]
Common Workflows:
first-time setup
bash lpd setup --yes
start docs preview
lpd dev
fast staged validation
lpd test --staged
run a managed script
lpd tools dev test-add-callouts -- --help
regenerate AI sitemap
lpd ai-sitemap --write
Notes:
- lpd uses .lpdignore (if present) to hide/block scripts from discovery and execution.
- Human `.allowlist` edits require: `git commit -m "msg" --trailer "allowlist-edit=true"`.
- Human deletions require: `git commit -m "msg" --trailer "allow-deletions=true"`.
- High-risk script groups require confirmation unless --yes is supplied.
EOF
}
emit_json() {
local ok="$1"
local command="$2"
local message="$3"
local code="${4:-0}"
if command -v node >/dev/null 2>&1; then
node -e '
const [ok, command, message, code] = process.argv.slice(1);
console.log(JSON.stringify({
ok: ok === "1",
command,
message,
exit_code: Number(code),
repo_root: process.cwd()
}, null, 2));
' "$ok" "$command" "$message" "$code"
return
fi
if [ "$ok" = "1" ]; then
printf '{"ok":true,"command":"%s","message":"%s","exit_code":%s}\n' "$command" "$message" "$code"
else
printf '{"ok":false,"command":"%s","message":"%s","exit_code":%s}\n' "$command" "$message" "$code"
fi
}
finish() {
local code="$1"
local command="$2"
local message="$3"
if [ "$GLOBAL_JSON" = "1" ]; then
if [ "$code" -eq 0 ]; then
emit_json "1" "$command" "$message" "$code"
else
emit_json "0" "$command" "$message" "$code"
fi
else
if [ "$code" -eq 0 ]; then
echo "$message"
else
echo "Error: $message" >&2
fi
fi
return "$code"
}
require_repo_layout() {
if [ ! -f "$REPO_ROOT/docs.json" ] || [ ! -d "$REPO_ROOT/tools" ]; then
finish 1 "init" "Not in livepeer-docs repo root."
exit 1
fi
}
is_in_path() {
local dir="$1"
case ":$PATH:" in
*":$dir:"*) return 0 ;;
*) return 1 ;;
esac
}
preferred_cli_install_dir() {
local candidate
for candidate in "$HOME/.local/bin" "$HOME/Library/pnpm" "$HOME/bin"; do
if is_in_path "$candidate"; then
echo "$candidate"
return 0
fi
done
echo "$HOME/.local/bin"
}
shell_rc_file() {
case "${SHELL:-}" in
*/zsh) echo "$HOME/.zshrc" ;;
*/bash) echo "$HOME/.bashrc" ;;
*)
if [ -f "$HOME/.zshrc" ]; then
echo "$HOME/.zshrc"
else
echo "$HOME/.bashrc"
fi
;;
esac
}
install_cli_link() {
local install_dir="${LPD_INSTALL_DIR:-$(preferred_cli_install_dir)}"
local target="$REPO_ROOT/lpd"
local link_path="$install_dir/lpd"
local rc_file
local export_line
mkdir -p "$install_dir"
ln -sf "$target" "$link_path"
if is_in_path "$install_dir"; then
return 0
fi
rc_file="$(shell_rc_file)"
export_line="export PATH=\"$install_dir:\$PATH\""
if [ -f "$rc_file" ] && grep -Fq "$export_line" "$rc_file"; then
return 0
fi
{
echo ""
echo "# Added by lpd setup"
echo "$export_line"
} >> "$rc_file"
echo "Updated $rc_file to include $install_dir on PATH."
echo "Run: source $rc_file"
return 0
}
group_root() {
case "$1" in
tools) echo "tools/scripts" ;;
tasks) echo "tasks/scripts" ;;
tests) echo "tests" ;;
v2) echo "tools/scripts/dev" ;;
hooks) echo ".githooks" ;;
*)
return 1
;;
esac
}
group_risk() {
case "$1" in
tests) echo "low" ;;
tools|hooks) echo "medium" ;;
tasks|v2) echo "high" ;;
*)
echo "medium"
;;
esac
}
is_builtin_excluded() {
local rel="$1"
case "$rel" in
*/node_modules/*|*.bak|*.bak2|*~|*.tmp|*.temp|*.log|logs/*|tests/reports/*|*/README|*/README.md|*/README.mdx|*/README-test-*.md)
return 0
;;
*)
return 1
;;
esac
}
LPIGNORE_MATCH=""
is_lpignored() {
local rel="$1"
local lpignore_file="$REPO_ROOT/.lpdignore"
LPIGNORE_MATCH=""
if [ ! -f "$lpignore_file" ]; then
return 1
fi
local out
out=$(git -c core.excludesfile="$lpignore_file" check-ignore --no-index -v -- "$rel" 2>/dev/null || true)
if [ -z "$out" ]; then
return 1
fi
case "$out" in
"$lpignore_file":*|".lpdignore:"*)
LPIGNORE_MATCH="$out"
return 0
;;
*)
return 1
;;
esac
}
is_runnable_file() {
local abs="$1"
if [ -x "$abs" ]; then
return 0
fi
local first_line=""
first_line="$(head -n 1 "$abs" 2>/dev/null || true)"
case "$first_line" in
'#!'*)
return 0
;;
*)
return 1
;;
esac
}
script_id_from_rel() {
local group="$1"
local root="$2"
local rel="$3"
local sub="${rel#$root/}"
sub="${sub%.*}"
sub="${sub//\// }"
echo "$group $sub"
}
# Output records:
# script|<id>|<rel>|<risk>
# ignored|<id>|<rel>|<risk>|<pattern>
discover_group_scripts() {
local group="$1"
local include_ignored="${2:-0}"
local root
root="$(group_root "$group")" || return 1
local abs_root="$REPO_ROOT/$root"
local risk
risk="$(group_risk "$group")"
if [ ! -d "$abs_root" ]; then
return 0
fi
while IFS= read -r abs; do
local rel="$abs"
if [[ "$abs" == "$REPO_ROOT/"* ]]; then
rel="${abs:${#REPO_ROOT}+1}"
fi
if is_builtin_excluded "$rel"; then
continue
fi
if ! is_runnable_file "$abs"; then
continue
fi
local id
id="$(script_id_from_rel "$group" "$root" "$rel")"
if is_lpignored "$rel"; then
if [ "$include_ignored" = "1" ]; then
echo "ignored|$id|$rel|$risk|$LPIGNORE_MATCH"
fi
continue
fi
echo "script|$id|$rel|$risk"
done < <(find "$abs_root" -type f | LC_ALL=C sort)
}
resolve_script_entry() {
local group="$1"
shift
local target="$*"
RESOLVED_REL=""
RESOLVED_ID=""
RESOLVED_RISK=""
RESOLVED_IGNORE=""
while IFS='|' read -r kind id rel risk extra; do
local tail="${id#"$group "}"
if [ "$tail" = "$target" ]; then
if [ "$kind" = "script" ]; then
RESOLVED_REL="$rel"
RESOLVED_ID="$id"
RESOLVED_RISK="$risk"
return 0
fi
if [ "$kind" = "ignored" ]; then
RESOLVED_IGNORE="$extra"
fi
fi
done < <(discover_group_scripts "$group" 1)
return 1
}
run_script_file() {
local rel="$1"
shift
local dry_run="${LP_DRY_RUN:-0}"
local abs="$REPO_ROOT/$rel"
local first_line=""
local -a cmd
cmd=()
if [ -x "$abs" ]; then
cmd=("$abs")
else
first_line="$(head -n 1 "$abs" 2>/dev/null || true)"
case "$first_line" in
'#!'*)
local shebang="${first_line#\#!}"
if [[ "$shebang" == /usr/bin/env* ]]; then
shebang="${shebang#/usr/bin/env }"
fi
local -a interpreter
read -r -a interpreter <<<"$shebang"
if [ "${#interpreter[@]}" -eq 0 ]; then
finish 1 "scripts run" "Could not parse shebang in $rel"
return 1
fi
cmd=("${interpreter[@]}" "$abs")
;;
*)
case "$abs" in
*.sh|*.bash)
cmd=(bash "$abs")
;;
*.py)
cmd=(python3 "$abs")
;;
*.js|*.mjs|*.cjs)
cmd=(node "$abs")
;;
*)
finish 1 "scripts run" "File is not runnable: $rel"
return 1
;;
esac
;;
esac
fi
if [ "$#" -gt 0 ]; then
cmd+=("$@")
fi
if [ "$dry_run" = "1" ]; then
printf 'Dry run:'
printf ' %q' "${cmd[@]}"
printf '\n'
return 0
fi
"${cmd[@]}"
}
confirm_high_risk() {
local id="$1"
if [ "${LP_ASSUME_YES:-0}" = "1" ]; then
return 0
fi
if [ ! -t 0 ]; then
finish 1 "scripts run" "High-risk command requires confirmation or --yes: $id"
return 1
fi
printf "High-risk command '%s'. Continue? [y/N]: " "$id"
local answer
read -r answer
case "$answer" in
y|Y|yes|YES)
return 0
;;
*)
finish 1 "scripts run" "Cancelled."
return 1
;;
esac
}
run_step() {
local label="$1"
shift
if "$@"; then
echo "✓ $label"
return 0
fi
echo "✗ $label" >&2
return 1
}
hook_status_check() {
local source_hook="$REPO_ROOT/.githooks/pre-commit"
# Support both regular repos and worktrees
local git_common_dir
git_common_dir=$(cd "$REPO_ROOT" && git rev-parse --git-common-dir 2>/dev/null)
if [ -z "$git_common_dir" ] || [ "$git_common_dir" = "--git-common-dir" ]; then
git_common_dir="$REPO_ROOT/.git"
fi
local target_hook="$git_common_dir/hooks/pre-commit"
if [ ! -f "$source_hook" ]; then
echo "missing-source"
return 1
fi
if [ ! -f "$target_hook" ]; then
echo "not-installed"
return 1
fi
if [ ! -x "$target_hook" ]; then
echo "not-executable"
return 1
fi
if ! cmp -s "$source_hook" "$target_hook"; then
echo "out-of-date"
return 1
fi
echo "installed"
return 0
}
cmd_version() {
finish 0 "version" "lpd $CLI_VERSION"
}
cmd_hooks() {
local sub="${1:-status}"
shift || true
case "$sub" in
install)
if ./.githooks/install.sh; then
finish 0 "hooks install" "Hooks installed."
else
finish 1 "hooks install" "Hook installation failed."
fi
;;
status)
local status
status="$(hook_status_check)" || true
case "$status" in
installed)
finish 0 "hooks status" "Hooks are installed and up to date."
;;
not-installed)
finish 1 "hooks status" "Hooks are not installed."
;;
out-of-date)
finish 1 "hooks status" "Installed hooks are out of date."
;;
not-executable)
finish 1 "hooks status" "Hook exists but is not executable."
;;
*)
finish 1 "hooks status" "Hook status check failed: $status"
;;
esac
;;
verify)
if bash ./.githooks/verify.sh; then
finish 0 "hooks verify" "Hook verification passed."
else
finish 1 "hooks verify" "Hook verification failed."
fi
;;
info)
cat <<'EOF'
`lpd hooks` manages repository git hooks and related validation scripts.
Usage:
lpd hooks install
- info: Install/update `.git/hooks/pre-commit` from `.githooks/pre-commit`.
lpd hooks status
- info: Check whether the installed pre-commit hook exists, is executable, and matches source.
lpd hooks verify
- info: Run hook verification checks from `.githooks/verify.sh`.
lpd hooks <hook-script tokens...> [-- script args]
- info: Run managed scripts under `.githooks/` (via script runner fallback).
Hook Scripts:
- `.githooks/install.sh`
- `.githooks/pre-commit`
- `.githooks/pre-commit-no-deletions`
- `.githooks/verify.sh`
- `.githooks/verify-browser.js`
- `.githooks/server-manager.js`
Bypass Flags (pre-commit; use sparingly):
- `SKIP_STRUCTURE_CHECK=1` : skip root/snippets/v1 structure checks.
- `SKIP_STYLE_CHECK=1` : skip style-guide compliance checks.
- `SKIP_VERIFICATION=1` : skip verification script checks.
- `SKIP_TESTS=1` : skip staged test suite checks.
- `SKIP_ALL=1` : skip all pre-commit checks.
Human-Only Overrides:
- `git commit ... --trailer "allowlist-edit=true"`
- `git commit ... --trailer "allow-deletions=true"`
Legacy Environment Overrides:
- `ALLOWLIST_EDIT=1` (legacy fallback for allowlist edits)
- `ALLOW_DELETIONS=1` (legacy fallback for deletions)
Notes:
- Human `.allowlist` edits require explicit human override.
- Human deletions outside `tasks/` require explicit human override.
- See `.githooks/BYPASS.md` and `contribute/CONTRIBUTING/GIT-HOOKS.md` for policy and details.
EOF
;;
--help|-h)
cat <<'EOF'
Usage:
lpd hooks install
lpd hooks status
lpd hooks verify
lpd hooks info
lpd hooks <hook-script tokens...> [-- script args]
Note:
Human `.allowlist` edits require:
git commit -m "msg" --trailer "allowlist-edit=true"
Human deletions require:
git commit -m "msg" --trailer "allow-deletions=true"
EOF
;;
*)
# Fallback: treat as .githooks script path.
cmd_scripts_run_internal "hooks" "$sub" "$@"
;;
esac
}
cmd_doctor() {
local strict=0
while [ "$#" -gt 0 ]; do
case "$1" in
--strict)
strict=1
;;
--json)
GLOBAL_JSON=1
;;
--help|-h)
cat <<'EOF'
Usage: lpd doctor [--strict] [--json]
EOF
return 0
;;
*)
finish 1 "doctor" "Unknown option: $1"
return 1
;;
esac
shift
done
local failures=0
if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
echo "✓ git repository"
else
echo "✗ git repository" >&2
failures=$((failures + 1))
fi
if command -v node >/dev/null 2>&1; then
echo "✓ node: $(node --version)"
else
echo "✗ node not found" >&2
failures=$((failures + 1))
fi
if command -v mint >/dev/null 2>&1; then
echo "✓ mint: $(mint --version 2>/dev/null || echo available)"
else
echo "✗ mint CLI not found" >&2
failures=$((failures + 1))
fi
if [ -d "$REPO_ROOT/tools/node_modules" ]; then
echo "✓ tools dependencies installed"
else
echo "✗ tools dependencies missing (run: cd tools && npm install)" >&2
failures=$((failures + 1))
fi
if [ -d "$REPO_ROOT/tests/node_modules" ]; then
echo "✓ tests dependencies installed"
else
echo "✗ tests dependencies missing (run: cd tests && npm install)" >&2
failures=$((failures + 1))
fi
local hook_state
hook_state="$(hook_status_check)" || true
if [ "$hook_state" = "installed" ]; then
echo "✓ hooks installed and synced"
else
echo "✗ hooks state: $hook_state" >&2
failures=$((failures + 1))
fi
if [ "$strict" = "1" ] && [ "$failures" -gt 0 ]; then
finish 1 "doctor" "Doctor found $failures issue(s)."
return 1
fi
if [ "$failures" -gt 0 ]; then
finish 0 "doctor" "Doctor completed with $failures warning(s)."
else
finish 0 "doctor" "Doctor passed."
fi
}
cmd_setup() {
local assume_yes=0
local install_tools=1
local install_tests=1
local install_hooks=1
local install_mint=0
local install_cli=1
while [ "$#" -gt 0 ]; do
case "$1" in
--yes)
assume_yes=1
;;
--no-tools)
install_tools=0
;;
--no-tests)
install_tests=0
;;
--no-hooks)
install_hooks=0
;;
--with-mintlify)
install_mint=1
;;
--no-cli)
install_cli=0
;;
--json)
GLOBAL_JSON=1
;;
--help|-h)
cat <<'EOF'
Usage: lpd setup [--yes] [--no-tools] [--no-tests] [--no-hooks] [--with-mintlify] [--no-cli] [--json]
EOF
return 0
;;
*)
finish 1 "setup" "Unknown option: $1"
return 1
;;
esac
shift
done
if [ "$assume_yes" != "1" ] && [ -t 0 ]; then
local answer=""
printf "Install tools dependencies (cd tools && npm install)? [Y/n]: "
read -r answer || true
case "$answer" in
n|N|no|NO) install_tools=0 ;;
*) install_tools=1 ;;
esac
printf "Install tests dependencies (cd tests && npm install)? [Y/n]: "
read -r answer || true
case "$answer" in
n|N|no|NO) install_tests=0 ;;
*) install_tests=1 ;;
esac
printf "Install/update git hooks? [Y/n]: "
read -r answer || true
case "$answer" in
n|N|no|NO) install_hooks=0 ;;
*) install_hooks=1 ;;
esac
printf "Install Mintlify globally (npm i -g mintlify)? [y/N]: "
read -r answer || true
case "$answer" in
y|Y|yes|YES) install_mint=1 ;;
*) install_mint=0 ;;
esac
printf "Install lpd on PATH for this user? [Y/n]: "
read -r answer || true
case "$answer" in
n|N|no|NO) install_cli=0 ;;
*) install_cli=1 ;;
esac
fi
local failures=0
if [ "$install_tools" = "1" ]; then
if ! (cd "$REPO_ROOT/tools" && npm install); then
failures=$((failures + 1))
fi
fi
if [ "$install_tests" = "1" ]; then
if ! (cd "$REPO_ROOT/tests" && npm install); then
failures=$((failures + 1))
fi
fi
if [ "$install_hooks" = "1" ]; then
if ! ./.githooks/install.sh; then
failures=$((failures + 1))
fi
fi
if [ "$install_mint" = "1" ]; then
if ! npm i -g mintlify; then
failures=$((failures + 1))
fi
fi
if [ "$install_cli" = "1" ]; then
if ! install_cli_link; then
failures=$((failures + 1))
fi
fi
if [ "$failures" -gt 0 ]; then
finish 1 "setup" "Setup completed with $failures failure(s)."
return 1
fi
finish 0 "setup" "Setup completed."
}
run_test_mode() {
local mode="$1"
case "$mode" in
fast)
node tests/run-all.js --skip-browser
;;
staged)
node tests/run-all.js --staged --skip-browser
;;
full)
node tests/run-all.js
;;
*)
return 1
;;
esac
}
cmd_dev() {
local run_tests=0
local test_mode="fast"
local script_path="$REPO_ROOT/tools/scripts/mint-dev.sh"
local dry_run=0
local scoped_mode=0
local scope_interactive=0
local scope_file=""
local scope_versions=""
local scope_languages=""
local scope_tabs=""
local scope_prefixes=""
local skip_external_fetch=0
local disable_openapi=0
local -a mint_args
mint_args=()
while [ "$#" -gt 0 ]; do
case "$1" in
--test)
run_tests=1
;;
--test-mode)
if [ "$#" -lt 2 ]; then
finish 1 "dev" "--test-mode requires a value."
return 1
fi
test_mode="$2"
shift
;;
--script)
if [ "$#" -lt 2 ]; then
finish 1 "dev" "--script requires a path."
return 1
fi
script_path="$2"
shift
;;
--script=*)
script_path="${1#--script=}"
;;
--dry-run)
dry_run=1
;;
--scoped)
scoped_mode=1
;;
--scope-interactive)
scoped_mode=1
scope_interactive=1
;;
--scope-file)
if [ "$#" -lt 2 ]; then
finish 1 "dev" "--scope-file requires a path."
return 1
fi
scoped_mode=1
scope_file="$2"
shift
;;
--scope-file=*)
scoped_mode=1
scope_file="${1#--scope-file=}"
;;
--scope-version)
if [ "$#" -lt 2 ]; then
finish 1 "dev" "--scope-version requires a value."
return 1
fi
scoped_mode=1
if [ -n "$scope_versions" ]; then
scope_versions="$scope_versions,$2"
else
scope_versions="$2"