|
1 | 1 | # See: https://taskfile.dev/#/usage
|
2 | 2 | version: "3"
|
3 | 3 |
|
| 4 | +vars: |
| 5 | + # Last version of ajv-cli with support for the JSON schema "Draft 4" specification |
| 6 | + SCHEMA_DRAFT_4_AJV_CLI_VERSION: 3.3.0 |
| 7 | + |
4 | 8 | tasks:
|
5 | 9 | # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-dependencies-task/Taskfile.yml
|
6 | 10 | general:cache-dep-licenses:
|
@@ -116,3 +120,70 @@ tasks:
|
116 | 120 | - task: npm:install-deps
|
117 | 121 | cmds:
|
118 | 122 | - npx markdownlint-cli "**/*.md"
|
| 123 | + |
| 124 | + ts:validate: |
| 125 | + desc: Validate TypeScript configuration file against its JSON schema |
| 126 | + vars: |
| 127 | + # Source: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/tsconfig.json |
| 128 | + SCHEMA_URL: https://json.schemastore.org/tsconfig.json |
| 129 | + SCHEMA_PATH: |
| 130 | + sh: task utility:mktemp-file TEMPLATE="tsconfig-schema-XXXXXXXXXX.json" |
| 131 | + INSTANCE_PATH: '{{default "./tsconfig.json" .TSCONFIG_PATH}}' |
| 132 | + WORKING_FOLDER: |
| 133 | + sh: task utility:mktemp-folder TEMPLATE="ts-validate-XXXXXXXXXX" |
| 134 | + WORKING_INSTANCE_PATH: |
| 135 | + sh: echo "{{.WORKING_FOLDER}}/$(basename "{{.INSTANCE_PATH}}")" |
| 136 | + cmds: |
| 137 | + - | |
| 138 | + # TypeScript allows comments in tsconfig.json. |
| 139 | + # ajv-cli did not support comments in JSON at the 3.x version in use (support was added in a later version). |
| 140 | + npx strip-json-comments-cli \ |
| 141 | + --no-whitespace \ |
| 142 | + "{{.INSTANCE_PATH}}" \ |
| 143 | + > "{{.WORKING_INSTANCE_PATH}}" |
| 144 | + - | |
| 145 | + wget \ |
| 146 | + --quiet \ |
| 147 | + --output-document="{{.SCHEMA_PATH}}" \ |
| 148 | + {{.SCHEMA_URL}} |
| 149 | + - | |
| 150 | + cd "{{.WORKING_FOLDER}}" # Workaround for https://github.com/npm/cli/issues/3210 |
| 151 | + npx ajv-cli@{{.SCHEMA_DRAFT_4_AJV_CLI_VERSION}} validate \ |
| 152 | + --all-errors \ |
| 153 | + -s "{{.SCHEMA_PATH}}" \ |
| 154 | + -d "{{.WORKING_INSTANCE_PATH}}" |
| 155 | +
|
| 156 | + # Make a temporary file named according to the passed TEMPLATE variable and print the path passed to stdout |
| 157 | + # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/windows-task/Taskfile.yml |
| 158 | + utility:mktemp-file: |
| 159 | + vars: |
| 160 | + RAW_PATH: |
| 161 | + sh: mktemp --tmpdir "{{.TEMPLATE}}" |
| 162 | + cmds: |
| 163 | + - task: utility:normalize-path |
| 164 | + vars: |
| 165 | + RAW_PATH: "{{.RAW_PATH}}" |
| 166 | + |
| 167 | + # Make a temporary folder named according to the passed TEMPLATE variable and print the path passed to stdout |
| 168 | + # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/windows-task/Taskfile.yml |
| 169 | + utility:mktemp-folder: |
| 170 | + vars: |
| 171 | + RAW_PATH: |
| 172 | + sh: mktemp --directory --tmpdir "{{.TEMPLATE}}" |
| 173 | + cmds: |
| 174 | + - task: utility:normalize-path |
| 175 | + vars: |
| 176 | + RAW_PATH: "{{.RAW_PATH}}" |
| 177 | + |
| 178 | + # Print a normalized version of the path passed via the RAW_PATH variable to stdout |
| 179 | + # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/windows-task/Taskfile.yml |
| 180 | + utility:normalize-path: |
| 181 | + cmds: |
| 182 | + - | |
| 183 | + if [[ "{{.OS}}" == "Windows_NT" ]] && which cygpath &>/dev/null; then |
| 184 | + # Even though the shell handles POSIX format absolute paths as expected, external applications do not. |
| 185 | + # So paths passed to such applications must first be converted to Windows format. |
| 186 | + cygpath -w "{{.RAW_PATH}}" |
| 187 | + else |
| 188 | + echo "{{.RAW_PATH}}" |
| 189 | + fi |
0 commit comments