@@ -4,6 +4,8 @@ version: "3"
44vars :
55 # Path of the primary npm-managed project:
66 DEFAULT_NPM_PROJECT_PATH : ./
7+ # Last version of ajv-cli with support for the JSON schema "Draft 4" specification
8+ SCHEMA_DRAFT_4_AJV_CLI_VERSION : 3.3.0
79
810tasks :
911 build :
1517 desc : Check for problems with the project
1618 deps :
1719 - task : npm:validate
20+ - task : ts:validate
21+ vars :
22+ TSCONFIG_PATH : " ./tsconfig.json"
1823
1924 fix :
2025 desc : Make automated corrections to the project's files
@@ -153,6 +158,43 @@ tasks:
153158 - npx tsc
154159 - npx ncc build
155160
161+ ts:validate :
162+ desc : |
163+ Validate TypeScript configuration file against its JSON schema
164+ Environment variable parameters:
165+ TSCONFIG_PATH: Path of the TypeScript configuration file (default: ./tsconfig.json).
166+ vars :
167+ # Source: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/tsconfig.json
168+ SCHEMA_URL : https://json.schemastore.org/tsconfig.json
169+ SCHEMA_PATH :
170+ sh : task utility:mktemp-file TEMPLATE="tsconfig-schema-XXXXXXXXXX.json"
171+ INSTANCE_PATH : ' {{default "./tsconfig.json" .TSCONFIG_PATH}}'
172+ WORKING_FOLDER :
173+ sh : task utility:mktemp-folder TEMPLATE="ts-validate-XXXXXXXXXX"
174+ WORKING_INSTANCE_PATH :
175+ sh : echo "{{.WORKING_FOLDER}}/$(basename "{{.INSTANCE_PATH}}")"
176+ deps :
177+ - task : npm:install-deps
178+ cmds :
179+ - |
180+ # TypeScript allows comments in tsconfig.json.
181+ # ajv-cli did not support comments in JSON at the 3.x version in use (support was added in a later version).
182+ npx strip-json-comments-cli \
183+ --no-whitespace \
184+ "{{.INSTANCE_PATH}}" \
185+ > "{{.WORKING_INSTANCE_PATH}}"
186+ - |
187+ wget \
188+ --quiet \
189+ --output-document="{{.SCHEMA_PATH}}" \
190+ {{.SCHEMA_URL}}
191+ - |
192+ cd "{{.WORKING_FOLDER}}" # Workaround for https://github.com/npm/cli/issues/3210
193+ npx ajv-cli@{{.SCHEMA_DRAFT_4_AJV_CLI_VERSION}} validate \
194+ --all-errors \
195+ -s "{{.SCHEMA_PATH}}" \
196+ -d "{{.WORKING_INSTANCE_PATH}}"
197+
156198 # Make a temporary file named according to the passed TEMPLATE variable and print the path passed to stdout
157199 # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/windows-task/Taskfile.yml
158200 utility:mktemp-file :
@@ -164,6 +206,17 @@ tasks:
164206 vars :
165207 RAW_PATH : " {{.RAW_PATH}}"
166208
209+ # Make a temporary folder named according to the passed TEMPLATE variable and print the path passed to stdout
210+ # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/windows-task/Taskfile.yml
211+ utility:mktemp-folder :
212+ vars :
213+ RAW_PATH :
214+ sh : mktemp --directory --tmpdir "{{.TEMPLATE}}"
215+ cmds :
216+ - task : utility:normalize-path
217+ vars :
218+ RAW_PATH : " {{.RAW_PATH}}"
219+
167220 # Print a normalized version of the path passed via the RAW_PATH variable to stdout
168221 # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/windows-task/Taskfile.yml
169222 utility:normalize-path :
0 commit comments