-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd-ts-nocheck.ps1
40 lines (28 loc) · 1.21 KB
/
add-ts-nocheck.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# powershell script adds a ts-nocheck comment
# at the beginning of each ts file in the generated
# Public API TypeScript client
# The @ts-nocheck is to ignore the typescript compiler itself, otherwise the
# language server would analyze and throw errors, mostly unused imports
# and variables, on the generated code.
# The issue can be found on their github repo.
# https://github.com/OpenAPITools/openapi-generator/issues/1880
Param ($path)
if (-not ($PSBoundParameters.ContainsKey("path") -and $path)) {
Write-Error "Error: 'path' not set or empty. Use -path './your/path' when calling script."
return
}
Write-Host "Adding ts-nocheck comment to all .ts files in $path..."
$tsFilesCount = 0
$changedTsFilesCount = 0
$tsNoCheckCode = @"
// @ts-nocheck
"@
Get-ChildItem -Path $path -Recurse -Force -Filter *.ts | ForEach-Object {
$tsFilesCount++
$fileContent = Get-Content -Path $_.FullName -Raw
If ($fileContent.StartsWith($tsNoCheckCode)) { return }
$changedTsFilesCount++
$newContent = $tsNoCheckCode + $fileContent
Set-Content -Path $_.FullName -Value $newContent
}
Write-Host "Adding ts-nocheck to all .ts files in $path complete. $changedTsFilesCount/$tsFilesCount .ts files affected." -ForegroundColor DarkGreen