-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNew-NetCoreManifest.ps1
114 lines (93 loc) · 2.95 KB
/
New-NetCoreManifest.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<#
.SYNOPSIS
Generates a new Powershell Core module manifest from the Windows PowerShell one
.DESCRIPTION
Reads in aws-toolbox.psd1 and writes out aws-toolbox.netcore.psd1 making the following alterations
Adds
- CompatiblePSEditions = @('Core')
Modifies
GUID = a different GUID
RequiredModules = @('AWSPowerShell.netcore')
PowerShellVersion = "6.0"
PrivateData\PSData\ExternalModuleDependencies = @('AWSPowerShell.netcore')
#>
function RenderArray
{
<#
.SYNOPSIS
Render an array of strings to PowerShell code, i.e. @( ... )
.PARAMETER Arry
Array to render
.OUTPUTS
Array definition
#>
param
(
[Parameter(Position = 0)]
[Array]$Arry
)
$sb = New-Object System.Text.StringBuilder
$sb.Append("@(").
Append((($arry | ForEach-Object { "`"$_`"" }) -join ', ')).
Append(")").
ToString()
}
function RenderHashTable
{
<#
.SYNOPSIS
Recursively render a hashtable to PowerShell code, i.e. @{ ... }
Not smart - only expects the types found in a manifest file.
.PARAMETER Arry
Hash to render
.OUTPUTS
Hash definition
#>
param
(
[hashtable]$Hash,
[int]$Level = 0
)
$sb = New-Object System.Text.StringBuilder
$sb.AppendLine("@{") | Out-Null
$Hash.Keys |
ForEach-Object {
$value = $Hash[$_]
$pad = " " * ($Level + 1) * 4
if ($value -is [Array])
{
$sb.AppendLine(("{0}{1} = {2}" -f $pad, $_, (RenderArray $value))) | Out-Null
}
elseif ($value -is [hashtable])
{
$sb.AppendLine(("{0}{1} = {2}" -f $pad, $_, (RenderHashTable -Hash $value -Level ($Level + 1)))) | Out-Null
}
else
{
$sb.AppendLine(("{0}{1} = `"{2}`"" -f $pad, $_, $value)) | Out-Null
}
}
$sb.AppendLine(((" " * $Level * 4) + "}")) | Out-Null
$sb.ToString()
}
# Input manifest
$manifestFile = [IO.Path]::Combine($PSScriptRoot, "aws-toolbox", "aws-toolbox.psd1")
# Output manifest
$netCoreManifestFile = [IO.Path]::Combine($PSScriptRoot, "aws-toolbox", "aws-toolbox.netcore.psd1")
# GUID for netcore module
$netcoreGuid = 'ec15ab6d-29ac-4613-acda-5ed39a4cb655'
# Read manifest to hashtable
$manifest = Invoke-Expression "$(Get-Content -Raw $manifestFile)"
# Update values
$manifest['CompatiblePSEditions'] = @('Core')
$manifest['GUID'] = $netcoreGuid
$manifest['RequiredModules'] = @('AWSPowerShell.netcore')
$manifest['PowerShellVersion'] = '6.0'
$manifest['PrivateData']['PSData']['ExternalModuleDependencies'] = @('AWSPowerShell.netcore')
# Render hash back to powershell code
$netCoreManifest = RenderHashtable -Hash $manifest
# UTF8 without BOM encoding
$enc = New-Object System.Text.UTF8Encoding -ArgumentList $false
# Write new manifest
[IO.File]::WriteAllText($netCoreManifestFile, $netCoreManifest, $enc)
Write-Host "Generated $netCoreManifestFile"