1+ # ##
2+ # Conventient usage:
3+ # 1) generate specific language sdk based on current typespec folder
4+ # ./TypeSpec-Generate-Sdk.ps1 -SdkLanguage {language}
5+ # e.g. ./TypeSpec-Generate-Sdk.ps1 -SdkLanguage dotnet
6+ # The pre-requisite is the sdk repos path in local machine follows below convention:
7+ # 1). "azure-rest-api-specs" and "sdk-repos" are peer folder under same parent folder
8+ # 2). each sdk language repo is under "sdk-repos" folder, i.e.
9+ # sdk-repos/azure-sdk-for-net
10+ # sdk-repos/azure-sdk-for-java
11+ # sdk-repos/azure-sdk-for-python
12+ # sdk-repos/azure-sdk-for-js
13+ # ##
14+
115[CmdletBinding ()]
216param (
317 [Parameter (Position = 0 )]
@@ -8,11 +22,67 @@ param (
822 [Parameter (Position = 2 )]
923 [string ] $CommitHash ,
1024 [Parameter (Position = 3 )]
11- [string ] $RepoUrl
25+ [string ] $RepoUrl ,
26+ [string ] $SdkLanguage
1227)
1328
14- if ($TypeSpecProjectDirectory -contains " ." ) {
15- $TypeSpecProjectDirectory = Resolve-Path $TypeSpecProjectDirectory
29+ $TypeSpecProjectDirectory = (Resolve-Path $TypeSpecProjectDirectory ).Path
30+
31+ if ($SdkLanguage ) {
32+ # example value of TypeSpecProjectDirectory: /workspaces/azure-rest-api-specs/specification/contosowidgetmanager/Contoso.WidgetManager
33+ $index = $TypeSpecProjectDirectory.IndexOf (" specification" )
34+ if ($index -eq -1 ) {
35+ Write-Error " The input TypeSpecProjectDirectory parameter doesn't have 'specification' folder in its path: $TypeSpecProjectDirectory "
36+ exit 1
37+ }
38+ $specFolderPath = $TypeSpecProjectDirectory.Substring (0 , $index - 1 )
39+ $rootPath = Split-Path $specFolderPath - Parent
40+ $sdkRepoRoot = Join-Path $rootPath " sdk-repos"
41+ if (! (Test-Path $sdkRepoRoot )) {
42+ Write-Error " sdk repos root folder doesn't eixst: $sdkRepoRoot "
43+ exit 1
44+ }
45+
46+ # trying to locate the default sdk repo folder under 'sdk-repos' folder by language value
47+ switch ($SdkLanguage ) {
48+ " dotnet" {
49+ Write-Host " Generating dotnet sdk code ..."
50+ $sdkRepoPath = Join-Path $sdkRepoRoot " azure-sdk-for-net"
51+ if (! (Test-Path $sdkRepoPath )) {
52+ Write-Error " sdk repo doesn't exist: $sdkRepoPath "
53+ exit 1
54+ }
55+ }
56+ " java" {
57+ Write-Host " Generating java sdk code ..."
58+ $sdkRepoPath = Join-Path $sdkRepoRoot " azure-sdk-for-java"
59+ if (! (Test-Path $sdkRepoPath )) {
60+ Write-Error " sdk repo doesn't exist: $sdkRepoPath "
61+ exit 1
62+ }
63+ }
64+ " python" {
65+ Write-Host " Generating python sdk code ..."
66+ $sdkRepoPath = Join-Path $sdkRepoRoot " azure-sdk-for-python"
67+ if (! (Test-Path $sdkRepoPath )) {
68+ Write-Error " sdk repo doesn't exist: $sdkRepoPath "
69+ exit 1
70+ }
71+ }
72+ " js" {
73+ Write-Host " Generating js sdk code ..."
74+ $sdkRepoPath = Join-Path $sdkRepoRoot " azure-sdk-for-js"
75+ if (! (Test-Path $sdkRepoPath )) {
76+ Write-Error " sdk repo doesn't exist: $sdkRepoPath "
77+ exit 1
78+ }
79+ }
80+ default {
81+ Write-Error " The input SdkLanguage parameter should be one of this values: dotnet, java, python, js"
82+ exit 1
83+ }
84+ }
85+ $SdkRepoRootDirectory = $sdkRepoPath
1686}
1787
1888try {
0 commit comments