@@ -625,65 +625,41 @@ tasks:
625625 # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-markdown-task/Taskfile.yml
626626 markdown:check-links :
627627 desc : Check for broken links
628+ vars :
629+ # The command is defined in a Taskfile variable to allow it to be broken into multiple lines for readability.
630+ # This can't be done in the `cmd` object of the Taskfile because `npx --call` uses the native shell, which causes
631+ # standard newline escaping syntax to not work when the task is run on Windows.
632+ #
633+ # Using -regex instead of -name to avoid Task's behavior of globbing even when quoted on Windows
634+ # The odd method for escaping . in the regex is required for windows compatibility because mvdan.cc/sh gives
635+ # \ characters special treatment on Windows in an attempt to support them as path separators.
636+ #
637+ # prettier-ignore
638+ CHECK_LINKS_COMMAND :
639+ "
640+ find . \
641+ -type d -name \" .git\" -prune -o \
642+ -type d -name \" .licenses\" -prune -o \
643+ -type d -name \" __pycache__\" -prune -o \
644+ -type d -name \" node_modules\" -prune -o \
645+ -path \" ./{{.CLANG_FORMAT_GOLDEN_TEST_DATA_FOLDER}}/samples\" -prune -o \
646+ -path \" ./{{.CLANG_FORMAT_INPUT_TEST_DATA_FOLDER}}/samples\" -prune -o \
647+ -regex \" .*[.]md\" \
648+ -exec \
649+ markdown-link-check \
650+ --quiet \
651+ --config \" ./.markdown-link-check.json\" \
652+ \\ {\\ } \
653+ +
654+ "
628655 deps :
629656 - task : docs:generate
630657 - task : npm:install-deps
631658 cmds :
632659 - |
633- if [[ "{{.OS}}" == "Windows_NT" ]]; then
634- # npx --call uses the native shell, which makes it too difficult to use npx for this application on Windows,
635- # so the Windows user is required to have markdown-link-check installed and in PATH.
636- if ! which markdown-link-check &>/dev/null; then
637- echo "markdown-link-check not found or not in PATH."
638- echo "Please install: https://github.com/tcort/markdown-link-check#readme"
639- exit 1
640- fi
641- # Default behavior of the task on Windows is to exit the task when the first broken link causes a non-zero
642- # exit status, but it's better to check all links before exiting.
643- set +o errexit
644- STATUS=0
645- # Using -regex instead of -name to avoid Task's behavior of globbing even when quoted on Windows
646- # The odd method for escaping . in the regex is required for windows compatibility because mvdan.cc/sh gives
647- # \ characters special treatment on Windows in an attempt to support them as path separators.
648- for file in $(
649- find . \
650- -type d -name '.git' -prune -o \
651- -type d -name '.licenses' -prune -o \
652- -type d -name '__pycache__' -prune -o \
653- -type d -name 'node_modules' -prune -o \
654- -path './{{.CLANG_FORMAT_GOLDEN_TEST_DATA_FOLDER}}/samples' -prune -o \
655- -path './{{.CLANG_FORMAT_INPUT_TEST_DATA_FOLDER}}/samples' -prune -o \
656- -regex ".*[.]md" -print
657- ); do
658- markdown-link-check \
659- --quiet \
660- --config "./.markdown-link-check.json" \
661- "$file"
662- STATUS=$(( $STATUS + $? ))
663- done
664- exit $STATUS
665- else
666- npx --package=markdown-link-check --call='
667- STATUS=0
668- for file in $(
669- find . \
670- -type d -name '.git' -prune -o \
671- -type d -name '.licenses' -prune -o \
672- -type d -name '__pycache__' -prune -o \
673- -type d -name 'node_modules' -prune -o \
674- -path './{{.CLANG_FORMAT_GOLDEN_TEST_DATA_FOLDER}}/samples' -prune -o \
675- -path './{{.CLANG_FORMAT_INPUT_TEST_DATA_FOLDER}}/samples' -prune -o \
676- -regex ".*[.]md" -print
677- ); do
678- markdown-link-check \
679- --quiet \
680- --config "./.markdown-link-check.json" \
681- "$file"
682- STATUS=$(( $STATUS + $? ))
683- done
684- exit $STATUS
685- '
686- fi
660+ npx \
661+ --package=markdown-link-check \
662+ --call='{{.CHECK_LINKS_COMMAND}}'
687663
688664 # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-markdown-task/Taskfile.yml
689665 markdown:fix :
0 commit comments