forked from microsoft/kiota
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-code.ps1
executable file
·65 lines (55 loc) · 2.13 KB
/
generate-code.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env pwsh
param(
[Parameter(Mandatory = $true)][string]$descriptionUrl,
[Parameter(Mandatory = $true)][string]$language,
[Parameter(Mandatory = $false)][switch]$dev
)
if ([string]::IsNullOrEmpty($descriptionUrl)) {
Write-Error "Description URL is empty"
exit 1
}
if ([string]::IsNullOrEmpty($language)) {
Write-Error "Language is empty"
exit 1
}
$additionalArgumentCmd = Join-Path -Path $PSScriptRoot -ChildPath "get-additional-arguments.ps1"
$additionalArguments = Invoke-Expression "$additionalArgumentCmd -descriptionUrl $descriptionUrl -language $language"
$rootPath = Join-Path -Path $PSScriptRoot -ChildPath ".."
$Env:KIOTA_TUTORIAL_ENABLED = "false"
$executableName = "kiota"
if ($IsWindows) {
$executableName = "kiota.exe"
}
switch ($dev) {
$true {
Write-Warning "Using kiota in dev mode"
$kiotaExec = Join-Path -Path $rootPath -ChildPath "src" -AdditionalChildPath "kiota", "bin", "Debug", "net8.0", $executableName
break
}
default {
$kiotaExec = Join-Path -Path $rootPath -ChildPath "publish" -AdditionalChildPath $executableName
break
}
}
$targetOpenapiPath = Join-Path -Path $PSScriptRoot -ChildPath "openapi.yaml"
if (Test-Path $targetOpenapiPath) {
Remove-Item $targetOpenapiPath
}
if ($descriptionUrl.StartsWith("./")) {
Copy-Item -Path $descriptionUrl -Destination $targetOpenapiPath -Force
}
elseif ($descriptionUrl.StartsWith("http")) {
Invoke-WebRequest -Uri $descriptionUrl -OutFile $targetOpenapiPath
}
else {
$downloadProcess = Start-Process "$kiotaExec" -ArgumentList "download ${descriptionUrl} --clean-output --output $targetOpenapiPath" -Wait -NoNewWindow -PassThru
if ($downloadProcess.ExitCode -ne 0) {
Write-Error "Failed to download the openapi description"
exit 1
}
}
$generationProcess = Start-Process "$kiotaExec" -ArgumentList "generate --exclude-backward-compatible --clean-output --language ${language} --openapi ${targetOpenapiPath}${additionalArguments}" -Wait -NoNewWindow -PassThru
if ($generationProcess.ExitCode -ne 0) {
Write-Error "Failed to generate the code for ${language}"
exit 1
}