forked from zijianhuang/webapiclientgen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreateAspNetCoreClientApi.ps1
53 lines (46 loc) · 1.74 KB
/
CreateAspNetCoreClientApi.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
cd $PSScriptRoot
#Make sure CodeGen.json is saved in format ANSI or UTF-8 without BOM, since ASP.NET Core 2.0 Web API will fail to deserialize POST Body that contains BOM.
#Step 1: Launch Website
$path = "$PSScriptRoot\DemoCoreWeb\bin\Debug\netcoreapp3.1"
$procArgs = @{
FilePath = "dotnet.exe"
ArgumentList = "$path\DemoCoreWeb.dll"
WorkingDirectory = $path
PassThru = $true
}
$process = Start-Process @procArgs
#Step 2: Run CodeGen
$restArgs = @{
Uri = 'http://localhost:5000/api/codegen'
Method = 'Post'
InFile = "$PSScriptRoot\DemoCoreWeb\CodeGen.json"
ContentType = 'application/json'
}
try {
$result = Invoke-RestMethod @restArgs
Write-Output $result
}
catch {
Write-Output $_.Exception.Response.StatusCode
$response = $_.Exception.Response.GetResponseStream()
$reader = New-Object System.IO.StreamReader($response)
$reader.BaseStream.Position = 0
$reader.DiscardBufferedData()
$responseBody = $reader.ReadToEnd()
Write-Output $responseBody
}
#Step 3: Compile generated TS codes to JS for jQuery
$procTscArgs = @{
FilePath = "node"
ArgumentList = "`"C:\Program Files (x86)\Microsoft SDKs\TypeScript\3.2\tsc.js`" $PSScriptRoot\DemoCoreWeb\Scripts\ClientApi\WebApiCoreJQClientAuto.ts"
PassThru = $true
}
$processTsc = Start-Process @procTscArgs
# Compile for axios, if the app is coded on JS
$procTscArgs = @{
FilePath = "node"
ArgumentList = "`"C:\Program Files (x86)\Microsoft SDKs\TypeScript\3.2\tsc.js`" $PSScriptRoot\axios\src\clientapi\WebApiCoreAxiosClientAuto.ts"
PassThru = $false
}
$processTsc = Start-Process @procTscArgs
Stop-Process $process