- Notifications
You must be signed in to change notification settings - Fork 187
/
Copy pathManageGeneratedModule.ps1
54 lines (49 loc) · 2.28 KB
/
ManageGeneratedModule.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
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
<#
.DESCRIPTION
Manages generated modules by managing dependencies and configuring authentication.
.PARAMETERModule
The name of the module to manage.
#>
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()][string]$ModuleName,
[Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()][string]$ModuleSrc,
[Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()][string] $NamespacePrefix
)
$NugetPackagesToAdd=@("Hyak.Common","PowerShellStandard.Library")
$NugetPackagesToRemove=@("Microsoft.CSharp")
$AuthenticationProj=Join-Path$PSScriptRoot"..\src\Authentication\Authentication\Microsoft.Graph.Authentication.csproj"
$ModuleCsProj=Join-Path$ModuleSrc"$ModuleName.csproj"
$CustomCodePath=Join-Path$PSScriptRoot"\Custom\"
# Add authentication project reference to generated module reference.
Write-Debug"Executing: dotnet add $ModuleCsProj reference $AuthenticationProj"
dotnet add $ModuleCsProj reference $AuthenticationProj|Out-Null
if ($LastExitCode) {
Write-Error"Failed to execute: dotnet add $ModuleCsProj reference $AuthenticationProj"
}
# Copy custom code to generated module.
foreach ($customFilein (Get-ChildItem$CustomCodePath-Recurse)) {
Write-Debug"Copying $customFile to $ModuleSrc\custom"
# Resolve namespaces.
$fileContent=Get-Content$customFile
$fileContent=$fileContent.Replace("NamespacePrefixPlaceholder",$NamespacePrefix);
$fileContent|Out-File (Join-Path$ModuleSrc"custom"$customFile.Name)
}
# Remove unnecessary packages from generate modules.
foreach ($Packagein$NugetPackagesToRemove) {
Write-Debug"Executing: dotnet remove $ModuleCsProj package $Package"
dotnet remove $ModuleCsProj package $Package|Out-Null
if ($LastExitCode) {
Write-Error"Failed to execute: dotnet remove $ModuleCsProj package $Package"
}
}
# Add nuget packages from generate modules.
foreach ($Packagein$NugetPackagesToAdd) {
Write-Debug"Executing: dotnet add $ModuleCsProj package $Package"
dotnet add $ModuleCsProj package $Package-s https://api.nuget.org/v3/index.json |Out-Null
if ($LastExitCode) {
Write-Error"Failed to execute: dotnet add $ModuleCsProj package $Package"
}
}