@@ -188,60 +188,39 @@ tasks:
188
188
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-markdown-task/Taskfile.yml
189
189
markdown:check-links :
190
190
desc : Check for broken links
191
+ vars :
192
+ # The command is defined in a Taskfile variable to allow it to be broken into multiple lines for readability.
193
+ # This can't be done in the `cmd` object of the Taskfile because `npx --call` uses the native shell, which causes
194
+ # standard newline escaping syntax to not work when the task is run on Windows.
195
+ #
196
+ # Using -regex instead of -name to avoid Task's behavior of globbing even when quoted on Windows
197
+ # The odd method for escaping . in the regex is required for windows compatibility because mvdan.cc/sh gives
198
+ # \ characters special treatment on Windows in an attempt to support them as path separators.
199
+ #
200
+ # prettier-ignore
201
+ CHECK_LINKS_COMMAND :
202
+ "
203
+ find . \
204
+ -type d -name \" .git\" -prune -o \
205
+ -type d -name \" .licenses\" -prune -o \
206
+ -type d -name \" __pycache__\" -prune -o \
207
+ -type d -name \" node_modules\" -prune -o \
208
+ -regex \" .*[.]md\" \
209
+ -exec \
210
+ markdown-link-check \
211
+ --quiet \
212
+ --config \" ./.markdown-link-check.json\" \
213
+ \\ {\\ } \
214
+ +
215
+ "
191
216
deps :
192
217
- task : docs:generate
193
218
- task : npm:install-deps
194
219
cmds :
195
220
- |
196
- if [[ "{{.OS}}" == "Windows_NT" ]]; then
197
- # npx --call uses the native shell, which makes it too difficult to use npx for this application on Windows,
198
- # so the Windows user is required to have markdown-link-check installed and in PATH.
199
- if ! which markdown-link-check &>/dev/null; then
200
- echo "markdown-link-check not found or not in PATH. Please install: https://github.com/tcort/markdown-link-check#readme"
201
- exit 1
202
- fi
203
- # Default behavior of the task on Windows is to exit the task when the first broken link causes a non-zero
204
- # exit status, but it's better to check all links before exiting.
205
- set +o errexit
206
- STATUS=0
207
- # Using -regex instead of -name to avoid Task's behavior of globbing even when quoted on Windows
208
- # The odd method for escaping . in the regex is required for windows compatibility because mvdan.cc/sh gives
209
- # \ characters special treatment on Windows in an attempt to support them as path separators.
210
- for file in $(
211
- find . \
212
- -type d -name '.git' -prune -o \
213
- -type d -name '.licenses' -prune -o \
214
- -type d -name '__pycache__' -prune -o \
215
- -type d -name 'node_modules' -prune -o \
216
- -regex ".*[.]md" -print
217
- ); do
218
- markdown-link-check \
219
- --quiet \
220
- --config "./.markdown-link-check.json" \
221
- "$file"
222
- STATUS=$(( $STATUS + $? ))
223
- done
224
- exit $STATUS
225
- else
226
- npx --package=markdown-link-check --call='
227
- STATUS=0
228
- for file in $(
229
- find . \
230
- -type d -name '.git' -prune -o \
231
- -type d -name '.licenses' -prune -o \
232
- -type d -name '__pycache__' -prune -o \
233
- -type d -name 'node_modules' -prune -o \
234
- -regex ".*[.]md" -print
235
- ); do
236
- markdown-link-check \
237
- --quiet \
238
- --config "./.markdown-link-check.json" \
239
- "$file"
240
- STATUS=$(( $STATUS + $? ))
241
- done
242
- exit $STATUS
243
- '
244
- fi
221
+ npx \
222
+ --package=markdown-link-check \
223
+ --call='{{.CHECK_LINKS_COMMAND}}'
245
224
246
225
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-markdown-task/Taskfile.yml
247
226
markdown:fix :
0 commit comments