1
+ # ----------------------------------------------------------------------------------
2
+ #
3
+ # Copyright Microsoft Corporation
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ # Unless required by applicable law or agreed to in writing, software
9
+ # distributed under the License is distributed on an "AS IS" BASIS,
10
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ # See the License for the specific language governing permissions and
12
+ # limitations under the License.
13
+ # ----------------------------------------------------------------------------------
14
+
15
+ param (
16
+ [Parameter (Mandatory = $false )]
17
+ [string ] $BuildConfig = " Release" ,
18
+ [Parameter (Mandatory = $false )]
19
+ [string ] $OutputFile = " outputtypes.json"
20
+ )
21
+
22
+ $ToolsRootPath = " $PSScriptRoot /.."
23
+ $AzPreviewPath = Get-Item $ToolsRootPath \AzPreview\AzPreview.psd1
24
+ Import-LocalizedData - BindingVariable ModuleMetadata - BaseDirectory $AzPreviewPath.DirectoryName - FileName $AzPreviewPath.Name
25
+ $ModulePath = ($env: PSModulePath -split ' ;' )[0 ]
26
+ $outputTypes = New-Object System.Collections.Generic.HashSet[string ]
27
+ $jsonData = @ ()
28
+ $ProjectPaths = @ ( " $ToolsRootPath /../src" )
29
+
30
+ $ModuleManifestFile = $ProjectPaths | ForEach-Object {
31
+ Get-ChildItem - Path $_ - Filter " *.psd1" - Recurse | Where-Object {
32
+ $_.FullName -notlike " *autorest*"
33
+ }
34
+ }
35
+
36
+ foreach ($item in $jsonData ) {
37
+ $outputTypes.Add ($item ) | Out-Null
38
+ }
39
+
40
+ $ReleaseRepository = " ReleaseRP"
41
+ Register-PSRepository - Name $ReleaseRepository - SourceLocation " $ToolsRootPath /../artifacts" - PackageManagementProvider Nuget - InstallationPolicy Trusted
42
+ Install-Module - Scope CurrentUser - Name AzPreview - Repository $ReleaseRepository - Force - AllowClobber
43
+
44
+ $ModuleMetadata.RequiredModules | ForEach-Object {
45
+ $ModuleName = $_.ModuleName
46
+ $Version = $_.RequiredVersion
47
+ if ($Version -eq $null )
48
+ {
49
+ $Version = $_.ModuleVersion
50
+ }
51
+ $srcFile = $ModuleManifestFile | Where-Object {$_.Name -eq " $ModuleName .psd1" }
52
+ Import-LocalizedData - BindingVariable srcMetadata - BaseDirectory $srcFile.DirectoryName - FileName $srcFile.Name
53
+ $containsPsd1 = $srcMetadata.NestedModules | Where-Object { $_ -like " *.dll" }
54
+ $DestinationModulePath = [System.IO.Path ]::Combine($ModulePath , $ModuleName , $Version )
55
+ $psd1Path = Join-Path - Path $DestinationModulePath - ChildPath " $ModuleName .psd1"
56
+ if (($containsPsd1.count -gt 0 ) -and (Test-Path $psd1Path )){
57
+ Import-Module $Psd1Path - Force
58
+ $Module = Get-Module $ModuleName
59
+ foreach ($ModuleInfo in $Module.NestedModules ){
60
+ if ($srcMetadata.NestedModules -contains $ModuleInfo.Name + " .dll" ) {
61
+ foreach ($Cmdlet in $ModuleInfo.ExportedCmdlets.Values ) {
62
+ $OutputAttributeList = $Cmdlet.ImplementingType.GetTypeInfo ().GetCustomAttributes([System.Management.Automation.OutputTypeAttribute ], $true )
63
+ foreach ($OutputAttribute in $OutputAttributeList )
64
+ {
65
+ foreach ($OutputType in $OutputAttribute.Type )
66
+ {
67
+ $outputTypes.Add ($OutputType.Name ) | Out-Null
68
+ }
69
+ }
70
+ foreach ($Parameter in $Cmdlet.Parameters.Values ){
71
+ if ($Parameter.Attributes.TypeId.FullName -contains " System.Management.Automation.ParameterAttribute" ) {
72
+ if ($Parameter.ParameterType.FullName -like " *System.Nullable*`` [`` [*" )
73
+ {
74
+ $outputTypes.Add (($Parameter.ParameterType.BaseType.FullName -replace " [][]" , " " )) | Out-Null
75
+ }
76
+ elseif ($Parameter.ParameterType.FullName -notlike " *`` [`` [*" )
77
+ {
78
+ $outputTypes.Add (($Parameter.ParameterType.FullName -replace " [][]" , " " )) | Out-Null
79
+ }
80
+ }
81
+ }
82
+ }
83
+ }
84
+ }
85
+ }
86
+ }
87
+ $json = ConvertTo-Json $outputTypes
88
+ $json | Out-File " $OutputFile "
0 commit comments