Skip to content

Commit fb6f54c

Browse files
test-launcher
1 parent 0cbff3f commit fb6f54c

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed

dev/launch.ps1

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
[CmdletBinding()]
2+
param (
3+
[switch]
4+
$Local,
5+
6+
[ValidateSet('Desktop', 'Core')]
7+
[string]
8+
$PSVersion
9+
)
10+
11+
#region Launch in new cponsole
12+
if (-not $Local) {
13+
$application = (Get-Process -id $PID).Path
14+
if ($PSVersion -and $PSVersionTable.Edition -ne $PSVersion) {
15+
$application = 'pwsh.exe'
16+
if ($PSVersion -eq 'Desktop') { $application = 'powershell.exe'}
17+
}
18+
19+
Start-Process $application -ArgumentList @('-NoExit', '-NoProfile', '-File', "$PSScriptRoot\launch.ps1", '-Local')
20+
return
21+
}
22+
#endregion Launch in new cponsole
23+
24+
$ErrorActionPreference = 'Stop'
25+
trap {
26+
Write-Warning "Script failed: $_"
27+
throw $_
28+
}
29+
30+
#region Functions
31+
function New-TemporaryPath {
32+
[OutputType([string])]
33+
[CmdletBinding()]
34+
param (
35+
[Parameter(Mandatory = $true)]
36+
[string]
37+
$Prefix
38+
)
39+
40+
Write-Host "Creating new temporary path: $Prefix"
41+
42+
# Remove Previous Temporary Paths
43+
Remove-Item -Path "$env:Temp\$Prefix*" -Force -Recurse -ErrorAction SilentlyContinue
44+
45+
# Create New Temporary Path
46+
$item = New-Item -Path $env:TEMP -Name "$($Prefix)_$(Get-Random)" -ItemType Directory
47+
$item.FullName
48+
}
49+
50+
function Build-Template {
51+
[CmdletBinding()]
52+
param (
53+
[Parameter(Mandatory = $true)]
54+
[string]
55+
$RootPath,
56+
57+
[Parameter(Mandatory = $true)]
58+
[string]
59+
$ProjectPath
60+
)
61+
62+
Write-Host "Building Templates from Source"
63+
$buildScriptPath = Join-Path -Path $ProjectPath -ChildPath "templates\build.ps1"
64+
& $buildScriptPath -Path $RootPath
65+
66+
Set-PSFConfig -FullName 'PSModuleDevelopment.Template.Store.PSModuleDevelopment' -Value "$RootPath\output"
67+
}
68+
69+
function Import-PsmdModule {
70+
[CmdletBinding()]
71+
param (
72+
[Parameter(Mandatory = $true)]
73+
[string]
74+
$ProjectPath
75+
)
76+
77+
Write-Host "Importing PSModuleDevelopment from source code"
78+
Import-Module "$ProjectPath\PSModuleDevelopment\PSModuleDevelopment.psd1" -Global
79+
80+
# Does not work during initial start
81+
# [Microsoft.PowerShell.PSConsoleReadLine]::AddToHistory("ipmo '$ProjectPath\PSModuleDevelopment\PSModuleDevelopment.psd1'")
82+
}
83+
#endregion Functions
84+
85+
$projectRoot = Resolve-Path -Path "$PSScriptRoot\.."
86+
$templateRoot = New-TemporaryPath -Prefix PsmdTemplate
87+
#Build-PsmdModule -ProjectPath $projectRoot
88+
Import-PsmdModule -ProjectPath $projectRoot
89+
Build-Template -RootPath $templateRoot -ProjectPath $projectRoot

0 commit comments

Comments
 (0)