@@ -4,6 +4,8 @@ version: "3"
4
4
vars :
5
5
# Path of the primary npm-managed project:
6
6
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
7
9
8
10
tasks :
9
11
build :
15
17
desc : Check for problems with the project
16
18
deps :
17
19
- task : npm:validate
20
+ - task : ts:validate
21
+ vars :
22
+ TSCONFIG_PATH : " ./tsconfig.json"
18
23
19
24
fix :
20
25
desc : Make automated corrections to the project's files
@@ -153,6 +158,43 @@ tasks:
153
158
- npx tsc
154
159
- npx ncc build
155
160
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
+
156
198
# Make a temporary file named according to the passed TEMPLATE variable and print the path passed to stdout
157
199
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/windows-task/Taskfile.yml
158
200
utility:mktemp-file :
@@ -164,6 +206,17 @@ tasks:
164
206
vars :
165
207
RAW_PATH : " {{.RAW_PATH}}"
166
208
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
+
167
220
# Print a normalized version of the path passed via the RAW_PATH variable to stdout
168
221
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/windows-task/Taskfile.yml
169
222
utility:normalize-path :
0 commit comments