-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBuild.ps1
645 lines (551 loc) · 20.3 KB
/
Build.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
# -------------------------------------------------------------------
# Input Variable
# -------------------------------------------------------------------
$VerbosePreference = 'Continue'
$ErrorActionPreference = 'Stop'
$Generator = @{
NugetPackageName = 'ClrCli'
Module = @{
Name = 'PSClrCli'
Version = '1.0.0.0'
Path = $PSScriptRoot
}
}
# -------------------------------------------------------------------
# Functions
# -------------------------------------------------------------------
function New-Function {
Param(
$Name, $OutputType, $Parameters, $BeginBlock, $ProcessBlock, $EndBlock
)
if ($OutputType -ne $null) {
$OutputType = "`n`t[OutputType([{0}])]" -f $OutputType
}
$Pattern = "function {0} {{{1}`n`tparam(`n{2}`n`t)`n`tbegin {{`n`n`t`t{3}`n`n`t}}`n`tprocess {{`n`n`t`t{4}`n`n`t}}`n`tend {{`n`n`t`t{5}`n`n`t}}`n}}"
$Pattern -f @(
$Name
$OutputType
$Parameters -join ", `n`n"
$BeginBlock -join "`n`t`t"
$ProcessBlock -join "`n`t`t"
$EndBlock -join "`n`t`t"
)
}
# -------------------------------------------------------------------
# Main Variable
# -------------------------------------------------------------------
$Module = @{
Name = $Generator.Module.Name
Version = "1.0.0"
GUID = "$(New-Guid)"
Path = "{0}" -f $Generator.Module.Path
File = "{0}.psm1" -f $Generator.Module.Name
Manifest = "{0}.psd1" -f $Generator.Module.Name
NugetPackage = $Generator.NugetPackageName
Assembly = "{0}.dll" -f $Generator.NugetPackageName
Functions = @()
Aliases = @()
Pattern = @{
ModuleFile = @"
#requires -Version 5`n`n
Add-Type -Path `$PSScriptRoot\ClrCli.dll
{0}`n`n
{1}`n`n
{2}`n`n
Export-ModuleMember -Function * -Alias *
"@
ModuleManifestFile = @"
@{{
`tGuid = '{0}'
`tModuleVersion = '{1}'
`tDescription = ''
`tModuleToProcess = '{2}'
`tFunctionsToExport = '*'
}}
"@
Function = @"
function {0} {{
`t[OutputType([{1}])]
`tparam(
{2}
`t)
`tBegin {{`n{3}`n`t}}
`tProcess {{`n{4}`n`t}}
`tEnd {{`n{5}`n`t}}
}}
"@
Alias = @"
New-Alias -Name {0} -Value {1} -Force
"@
}
}
$FunctionArgs = @{
Name = [string]::Empty
OutputType = [string]::Empty
Parameters = @()
BeginBlock = @()
ProcessBlock = @()
EndBlock = @()
}
# Create Module Directory
New-Item -Type Directory -Path $Module.Path -Force | Out-Null
# -------------------------------------------------------------------
# Download NugetPackge
# -------------------------------------------------------------------
if ( -not ( Test-Path "$($Module.Path)\$($Module.Assembly)" ) ) {
Write-Verbose "Downloading NugetPackge $($Module.NugetPackage) ..."
$TempPath = New-Item -Type Directory -Path "$($Module.Path)\TempPath" -Force | Select -Expand FullName
$Package = Save-Package -Name $Module.NugetPackage -Source https://www.nuget.org/api/v2/ -ProviderName nuget -Path $TempPath
$Filename = "{0}\{1}" -f $TempPath, $Package.PackageFilename
$NewFilename = "{0}\{1}" -f $TempPath, $Package.PackageFilename.Replace(".nupkg",".zip")
Rename-Item -Path $Filename -NewName $NewFilename -Force -EA 0
Expand-Archive -Path $NewFilename -DestinationPath $TempPath -Force
Write-Verbose "Moving ClrCli CLR ..."
Move-Item -Path "$TempPath\lib\net45\$($Module.Assembly)" -Destination "$($Module.Path)\$($Module.Assembly)" -Force
Write-Verbose "Cleaning Temp Download Folder ..."
Remove-Item -Path "$TempPath\*" -Recurse -Force
Remove-Item -Path "$TempPath" -Force
}
# -------------------------------------------------------------------
# Filter and Browse Type List
# -------------------------------------------------------------------
$InstanceFlags = [System.Reflection.BindingFlags]'Instance, Public, NonPublic'
$StaticFlags = [System.Reflection.BindingFlags]'Static, Public, NonPublic'
$BaseFilterScript = @{
Module = @{
Name = { $_.Name }
}
Type = {
$_.Name -notlike "*_*" -and
-not $_.IsInterface -and
-not $_.IsGenericType
}
Member = {
$_.Name -notlike "*_*" -and
$_.Module.ToString() -notin @('CommonLanguageRuntimeLibrary')
}
}
<#
$Rules = @{
ModuleName = {}
Type = { }
Member = {}
Instance = @{
FunctionName = {}
AliasName = {}
ConstructorParameters = {}
Constructor = {}
Parameters = {}
Methods ={}
}
Static = @{
FunctionName = {}
AliasName = {}
Parameters = {}
Methods ={}
}
}
#>
$TypeList = Add-Type -Path "$($Module.Path)\$($Module.Assembly)" -PassThru
$FilteredTypeList = $TypeList | Where -FilterScript $BaseFilterScript.Type
foreach ( $Type in @( $FilteredTypeList ) ) {
Write-Verbose ( "Analyzing Type {0} ..." -f $Type.FullName )
$MemberList = @( @( $Type.GetMembers($StaticFlags) + $Type.GetMembers($InstanceFlags) ) | Where -FilterScript $BaseFilterScript.Member )
if ($Type.IsClass) {
Write-Verbose ( "Type {0} is Class" -f $Type.FullName )
$ConstructorList = @( $MemberList | Where { $_.IsConstructor } ) #-FilterScript $Rules.Instance.Constructor
if ($MemberList.Where{$_.IsConstructor}.Count -gt 0) {
Write-Verbose ( "Type {0} has constructor" -f $Type.FullName )
$Constructor = $ConstructorList.Where{$_.IsPublic} | Select -First 1 -EA 0
if ($null -eq $Constructor) {
$Constructor = $ConstructorList.Where{-not $_.IsPublic} | Select -First 1 -EA 0
}
$Function = $FunctionArgs.Clone()
$Function.OutputType = $Type.FullName
$Function.Name =
switch($Type) {
{ $_.FullName -eq "CLRCLI.Widgets.RootWindow" } {
"New-CursesWindow" ; break;
}
{ $_.FullName -like "CLRCLI.Widgets.*" } {
"New-Curses{0}" -f $_.Name ; break;
}
default { "New-Curses{0}" -f $_.Name }
}
$Alias =
switch($Type) {
{ $_.FullName -eq "CLRCLI.Widgets.RootWindow" } {
@{ Name = "CWindow" ; Value = $Function.Name } ; break;
}
{ $_.FullName -like "CLRCLI.Widgets.*" } {
@{ Name = ( "C{0}" -f $_.Name ) ; Value = $Function.Name } ; break;
}
default {
@{ Name = ( "C{0}" -f $_.Name ) ; Value = $Function.Name } ; break;
}
}
Write-Verbose ( "Mapping Type {0} Instance Class to Function {1} ({2}) ..." -f $Type.FullName, $Function.Name, $Alias.Name )
#------------------------------------------------------------------------------------
# Wrapping Constructors
#------------------------------------------------------------------------------------
$ConstructorParameterList = @( $Constructor.GetParameters() )
if ($ConstructorParameterList.Count -gt 0) {
Write-Verbose ( "Type {0} Found {1} Constructor(s) Parameter" -f $Type.FullName, $ConstructorParameterList.Count )
$ConstructorArgsList = @()
foreach ($ConstructorParameter in $ConstructorParameterList) {
switch($ConstructorParameter) {
{ $Type.FullName -like "CLRCLI.Widgets.*" } {
$Function.Parameters += "`t`t[{0}] `n`t`t`${1}" -f $_.ParameterType, $_.Name
$Function.BeginBlock += 'if ($PSBoundParameters.ContainsKey("{0}")) {{ [void] $PSBoundParameters.Remove("{0}") }}' -f $_.Name
break ;
}
default {
$Function.Parameters += "`t`t[{0}] `n`t`t`${1}" -f $_.ParameterType, $_.Name
$Function.BeginBlock += 'if ($PSBoundParameters.ContainsKey("{0}")) {{ [void] $PSBoundParameters.Remove("{0}") }}' -f $_.Name
}
}
$ConstructorArgsList += '${0}' -f $ConstructorParameter.Name
}
$ConstructorArgs = $ConstructorArgsList -join ", "
}
else {
$ConstructorArgs = [string]::Empty
}
# Construct Object and Keep Parent in global Scope
# Wrap Function Parameters to Object's properties or Remaining Arguments
switch($Type) {
{ $_.FullName -like "CLRCLI.Widgets.*" } {
$Function.Parameters += "`t`t[parameter(ParameterSetName=`"Remaining`",ValueFromRemainingArguments=`$true)]`n`t`t`$RemainingArguments"
$Function.BeginBlock += 'if ($PSBoundParameters.ContainsKey("RemainingArguments")) { [void] $PSBoundParameters.Remove("RemainingArguments") } else { $RemainingArguments = $null }'
if ($_.FullName -eq "CLRCLI.Widgets.RootWindow") {
$Function.ProcessBlock += '$Object = [{0}]::new()' -f $_.FullName
}
else {
$Function.ProcessBlock += 'if ($null -ne $parent) { $ObjectArgs = $parent } else { $ObjectArgs = Get-Variable -Scope 1 -Name ParentObject -ValueOnly -ErrorAction 0 } '
$Function.ProcessBlock += '$Object = [{0}]::new($ObjectArgs)' -f $_.FullName
}
$Function.ProcessBlock += @'
$ParentObject = $Object
if ($null -ne $RemainingArguments) {
$Children = @()
foreach($RemainingArgument in @($RemainingArguments) ) {
if ($RemainingArgument -is [scriptblock]) {
$Children += & $RemainingArgument
}
}
<#
if ($Children.Count -gt 0) {
for ($i = 1 ; $i -lt $Children.Count ; $i++) {
[void] $Object.Children.Add($Children[$i])
}
}
#>
}
foreach ($Key in @($PSBoundParameters.Keys)) {
$Object.$Key = $PSBoundParameters[$Key]
}
if ($Object.Children.Count -gt 0) {
$ObjectList = @($Object) + @($Object.Children)
}
else {
$ObjectList = @($Object)
}
@( $ObjectList ).Where{ -not [string]::IsNullOrEmpty($_.Id) }.Foreach{ New-Variable -Name $_.Id -Value $_ -Scope global -Force }
'@
$Function.EndBlock += 'return $Object'
break;
}
default {
$Function.ProcessBlock += '$Object = [{0}]::new({1})' -f @( $_.FullName, $ConstructorArgs )
if ($ParameterList.Count -gt 0) {
$Function.ProcessBlock += 'foreach ($Key in @($PSBoundParameters.Keys)) { $Object.$Key = $PSBoundParameters[$Key] }'
}
$Function.EndBlock += 'return $Object'
}
}
#------------------------------------------------------------------------------------
# Wrapping Properties
#------------------------------------------------------------------------------------
foreach ($Member in $MemberList.Where{$_.MemberType -eq [System.Reflection.MemberTypes]::Property -and $_.CanWrite}) {
if ($Member.Name -notin $ConstructorParameterList.Name) {
$Parameter = [ordered]@{}
# Build Parameter Definition
$Parameter.Definition =
switch($Member) {
default { '[parameter()]' }
}
# Build Parameter Name
$Parameter.Name =
switch($Member) {
{ $Type.FullName -like "CLRCLI.Widgets.*" -and $_.Name -like "*ground" } {
$NewName = $_.Name.Replace('ground', 'groundColor')
$NewName
$Function.BeginBlock += 'if ($PSBoundParameters.ContainsKey("{1}")) {{ [void] $PSBoundParameters.Remove("{1}") ; $PSBoundParameters["{0}"] = ${1} }}' -f $_.Name, $NewName
break
}
default { $_.Name }
}
# Build Parameter Type
$Parameter.Type =
switch($Member) {
{ $Type.FullName -like "CLRCLI.Widgets.*" -and $_.Name -eq 'Text' } {
'string[]'
$Function.BeginBlock += 'if ($PSBoundParameters.ContainsKey("Text") -and $PSBoundParameters["Text"] -is [string[]]) { $PSBoundParameters["Text"] = $Text = $Text -join "`n" }'
break
}
{ $Type.FullName -like "CLRCLI.Widgets.*" -and $_.Name -like "*Children" } {
'CLRCLI.Widget[]'
break
}
{ $_.PropertyType -eq [System.Boolean] } {
'switch'
break ;
}
default { "{0}" -f $_.PropertyType }
}
# Build Parameter Validation
$Parameter.Validation =
switch($Member) {
{([type]$_.PropertyType).IsEnum } { "[ValidateSet({0})]`n" -f ( [Enum]::GetValues($_.PropertyType).Foreach{"'$_'"} -join ", " ) }
}
# Build Parameter Default Value
$Parameter.DefaultValue =
switch($Member) {
{ $_.Name -eq "Background" -and $Type.FullName -eq 'CLRCLI.Widgets.RootWindow' } {
' = $host.UI.RawUI.BackgroundColor'
break;
}
{ $_.Name -eq 'Foreground' -and $Type.FullName -eq 'CLRCLI.Widgets.RootWindow' } {
' = $host.UI.RawUI.ForegroundColor'
break;
}
default { '' }
}
# Build All Parameters
$Function.Parameters += "`t`t{1}`n`t`t{3}`t`t[{2}] `n`t`t`${0}{4}" -f @(
$Parameter.Name
$Parameter.Definition
$Parameter.Type
$Parameter.Validation
$Parameter.DefaultValue
)
}
}
#------------------------------------------------------------------------------------
# Wrapping Methods
#------------------------------------------------------------------------------------
foreach ($Member in $MemberList.Where{ ( $_.IsPublic -and $_.MemberType -eq [System.Reflection.MemberTypes]::Method ) -or ($_.MemberType -eq [System.Reflection.MemberTypes]::Event) }) {
$Parameter = [ordered]@{}
# Build Parameter Name
$Parameter.Name =
switch($Member) {
{ $Type.FullName -like "CLRCLI.Widgets.*" -and $_.Name -in @('SetFocus', 'Run') } {
$_.Name
}
{ $_.MemberType -eq [System.Reflection.MemberTypes]::Event } {
"On" + $_.Name
}
}
# Only Build on Matched Parameter Name Rules
if ($Parameter.Name -eq $null) {
Continue
}
$Function.BeginBlock += 'if ($PSBoundParameters.ContainsKey("{0}")) {{ [void] $PSBoundParameters.Remove("{0}") }}' -f $Parameter.Name
# Build Parameter Definition
$Parameter.Definition =
switch($Member) {
default { '[parameter()]' }
}
# Build Parameter Type
$Parameter.Type =
switch($Member) {
{ $Type.FullName -like "CLRCLI.Widgets.*" -and $_.Name -in @('SetFocus', 'Run') } {
'switch'
$Function.EndBlock += 'if (${0} -eq $true) {{ [void] $Object.{1}() }}' -f $Parameter.Name, $_.Name
break;
}
{ $_.MemberType -eq [System.Reflection.MemberTypes]::Event } {
'scriptblock'
$Function.ProcessBlock += 'if ($null -ne ${0}) {{ [void] $Object.Add_{1}(${0}) }}' -f $Parameter.Name, $_.Name
break;
}
}
# Build All Parameters
$Function.Parameters += "`t`t{1}`t`t[{2}] `n`t`t`${0}" -f @(
$Parameter.Name
$Parameter.Definition
$Parameter.Type
)
}
#------------------------------------------------------------------------------------
# Update Module
#------------------------------------------------------------------------------------
$Module.Functions += New-Function @Function
if ($null -ne $Alias) {
$Module.Aliases += "New-Alias -Name {0} -Value {1} -Force" -f $Alias.Name, $Alias.Value
}
}
if ($MemberList.Where{$_.IsStatic -and ( $_.IsPublic -or $_.IsPublic -eq $Type.IsPublic ) }.Count -gt 0) {
Write-Verbose ( "Type {0} has Static Members" -f $Type.FullName )
foreach ($Member in $MemberList.Where{$_.IsStatic}) {
$Function = $FunctionArgs.Clone()
$Function.OutputType = $Member.ReturnType
$Function.Name =
switch($Type) {
{ $_.FullName -eq "CLRCLI.ConsoleHelper" -and $Member.Name -eq "ResetConsoleWindow" } {
"Reset-CursesConsole"
break;
}
{ $_.FullName -eq "CLRCLI.ConsoleHelper" -and $Member.Name -like "Draw*"} {
"New-Curses{0}" -f $Member.Name.Replace('Draw','').Replace('Rect','Rectangle')
break;
}
default {
"Invoke-{0}{1}" -f $Type.Name, $Member.Name
}
}
$Alias =
switch($Type) {
{ $_.FullName -eq "CLRCLI.ConsoleHelper" -and $Member.Name -eq "ResetConsoleWindow" } {
@{ Name = "CReset" ; Value = $Function.Name } ; break;
}
{ $_.FullName -eq "CLRCLI.ConsoleHelper" -and $Member.Name -like "Draw*"} {
@{ Name = $Function.Name.Replace('New-Curses','C') ;Value = $Function.Name } ; break;
}
default {
$null
}
}
Write-Verbose ( "Mapping Type {0} Static Method Class to Function {1} ({2}) ..." -f $Type.FullName, $Function.Name, $Alias.Name )
#--------------
# Wrapping Methods
#--------------
#
$ParameterList = $Member.GetParameters()
if ($ParameterList.Count -gt 0) {
foreach ($MemberParameter in $ParameterList) {
$Parameter = [ordered]@{}
# Build Parameter Definition
$Parameter.Definition =
switch($MemberParameter) {
default { '[parameter()]' }
}
# Build Parameter Name
$Parameter.Name =
switch($MemberParameter.Name) {
'c' { 'Color' ; break ; }
'w' { 'Width'; break ; }
'h' { 'Height' ; break ; }
'ch' { 'Char'; break ; }
'fg' { 'ForegroundColor'; break ; }
'bg' { 'BackgroundColor' ; break ; }
'args' { 'InputObject'; break ; }
default { $_ }
}
if ($MemberParameter.Name -ne $Parameter.Name) {
$Function.BeginBlock += 'if ($PSBoundParameters.ContainsKey("{1}")) {{ [void] $PSBoundParameters.Remove("{1}") ; ${0} = ${1} }}' -f $MemberParameter.Name, $Parameter.Name
}
# Build Parameter Type
$Parameter.Type =
switch($MemberParameter) {
{ $_.ParameterType -eq 'System.Boolean' } { 'switch' ; break ; }
default { $_.ParameterType }
}
# Build Parameter Validation
$Parameter.Validation =
switch($MemberParameter) {
{([type]$_.ParameterType).IsEnum } {
"[ValidateSet({0})]`n" -f ( [Enum]::GetValues($_.ParameterType).Foreach{"'$_'"} -join ", " )
}
}
# Build Parameter Default Value
$Parameter.DefaultValue =
switch($MemberParameter) {
{ $Type.Name -eq 'ConsoleHelper' -and $_.Name -eq 'bg' } {
' = $host.UI.RawUI.BackgroundColor'
break;
}
{ $Type.Name -eq 'ConsoleHelper' -and $_.Name -eq 'fg' } {
' = $host.UI.RawUI.ForegroundColor'
break;
}
default { '' }
}
# Build All Parameters
$Function.Parameters += "`t`t{1}`n`t`t{3}`t`t[{2}] `n`t`t`${0}{4}" -f @(
$Parameter.Name
$Parameter.Definition
$Parameter.Type
$Parameter.Validation
$Parameter.DefaultValue
)
}
}
# Manage Return Object
switch($Type) {
{ -not $_.IsPublic } {
$Function.ProcessBlock += '$Type = [CLRCLI.BorderStyle].Assembly.GetType("{0}")' -f $Type.Fullname
$Function.ProcessBlock += '$Method = $Type.GetMethods("NonPublic,Static").Where{{$_.Name -eq "{0}"}} | Select-Object -First 1' -f $Member.Name
$Function.ProcessBlock += '$Object = $Method.Invoke($null, @({0}))' -f $( $ParameterList.Foreach{'${0}' -f $_.Name} -join ", " )
# if ($ParameterList.Count -gt 0) {
# $Function.ProcessBlock += 'foreach ($Key in @($PSBoundParameters.Keys)) { $Object.$Key = $PSBoundParameters[$Key] }'
# }
$Function.EndBlock += 'return $Object'
break;
}
default {
$Function.ProcessBlock += '$Object = [{0}]::{1}.Invoke($null, @({2}))' -f @(
$_.FullName
$Member.Name
( $ParameterList.Foreach{'${0}' -f $_.Name} -join ", " )
)
# if ($ParameterList.Count -gt 0) {
# $Function.ProcessBlock += 'foreach ($Key in @($PSBoundParameters.Keys)) { $Object.$Key = $PSBoundParameters[$Key] }'
# }
$Function.EndBlock += 'return $Object'
}
}
#--------------
# Update Module
#--------------
#
$Module.Functions += New-Function @Function
if ($null -ne $Alias) {
$Module.Aliases += "New-Alias -Name {0} -Value {1} -Force" -f $Alias.Name, $Alias.Value
}
}
}
}
elseif ($Type.IsEnum) {
Write-Verbose ( "Type {0} is Enum" -f $Type.FullName )
}
}
# -------------------------------------------------------------------
# Building Module
# -------------------------------------------------------------------
Write-Verbose "Building Module File ..."
$ModuleContent = $Module.Pattern.ModuleFile -f @(
''
$Module.Functions -join "`n`n"
$Module.Aliases -join "`n"
)
Set-Content -Path "$($Module.Path)\$($Module.File)" -Value $ModuleContent -Force
Write-Verbose "Building Manifest Module ..."
$ModuleManifestContent = $Module.Pattern.ModuleManifestFile -f @(
$Module.Guid
$Module.Version
$Module.File
)
Set-Content -Path "$($Module.Path)\$($Module.Manifest)" -Value $ModuleManifestContent -Force
Write-Verbose "Module is ready."
# -------------------------------------------------------------------
# Kitchen
# -------------------------------------------------------------------
$HostArgs = @{Foreground='Cyan'}
Write-Host @HostArgs "Importing Module ..."
Import-Module $Module.Path -Force -PassThru | Format-Table -Auto
Write-Host @HostArgs "Module Functions :"
Get-Command -CommandType Function -Module $Module.Name | Format-Wide -Auto
Write-Host @HostArgs "Module Alias : "
Get-Command -CommandType Alias -Module $Module.Name | Format-Wide -Auto
# Invoke-Item $Module.Path