-
-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathlaunch.ps1
More file actions
113 lines (92 loc) · 2.72 KB
/
Copy pathlaunch.ps1
File metadata and controls
113 lines (92 loc) · 2.72 KB
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
[CmdletBinding()]
param (
[switch]
$Local,
[switch]
$Build,
[ValidateSet('Desktop', 'Core')]
[string]
$PSVersion
)
#region Launch in new cponsole
if (-not $Local) {
$application = (Get-Process -id $PID).Path
if ($PSVersion -and $PSVersionTable.Edition -ne $PSVersion) {
$application = 'pwsh.exe'
if ($PSVersion -eq 'Desktop') { $application = 'powershell.exe'}
}
$arguments = @('-NoExit', '-NoProfile', '-File', "$PSScriptRoot\launch.ps1", '-Local')
if ($Build) { $arguments += '-Build' }
Start-Process $application -ArgumentList $arguments
return
}
#endregion Launch in new cponsole
$ErrorActionPreference = 'Stop'
trap {
Write-Warning "Script failed: $_"
throw $_
}
#region Functions
function New-TemporaryPath {
[OutputType([string])]
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string]
$Prefix
)
Write-Host "Creating new temporary path: $Prefix"
$temp = [System.IO.Path]::GetTempPath()
# Remove Previous Temporary Paths
Remove-Item -Path "$temp\$Prefix*" -Force -Recurse -ErrorAction SilentlyContinue
# Create New Temporary Path
$item = New-Item -Path $temp -Name "$($Prefix)_$(Get-Random)" -ItemType Directory
$item.FullName
}
function Build-Template {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string]
$RootPath,
[Parameter(Mandatory = $true)]
[string]
$ProjectPath
)
Write-Host "Building Templates from Source"
$buildScriptPath = Join-Path -Path $ProjectPath -ChildPath "templates\build.ps1"
& $buildScriptPath -Path $RootPath
Set-PSFConfig -FullName 'PSModuleDevelopment.Template.Store.PSModuleDevelopment' -Value "$RootPath\output"
}
function Import-PsmdModule {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string]
$ProjectPath
)
Write-Host "Importing PSModuleDevelopment from source code"
Import-Module "$ProjectPath\PSModuleDevelopment\PSModuleDevelopment.psd1" -Global
# Does not work during initial start
# [Microsoft.PowerShell.PSConsoleReadLine]::AddToHistory("ipmo '$ProjectPath\PSModuleDevelopment\PSModuleDevelopment.psd1'")
}
function Build-PsmdModule {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string]
$ProjectPath
)
Write-Host "Building Library. This may require the .NET 4.8 Targeting Pack"
try { $null = & "$ProjectPath\build\vsts-build-library.ps1" }
catch {
Write-Host "Targeting pack Download Link: https://dotnet.microsoft.com/en-us/download/visual-studio-sdks?cid=getdotnetsdk"
throw
}
}
#endregion Functions
$projectRoot = Resolve-Path -Path "$PSScriptRoot\.."
$templateRoot = New-TemporaryPath -Prefix PsmdTemplate
if ($Build) { Build-PsmdModule -ProjectPath $projectRoot }
Import-PsmdModule -ProjectPath $projectRoot
Build-Template -RootPath $templateRoot -ProjectPath $projectRoot