Skip to content

Commit 2cb9c6c

Browse files
committed
Merge branch 'import-submodules-build'
2 parents 1067b92 + 6fff81c commit 2cb9c6c

File tree

6 files changed

+167
-116
lines changed

6 files changed

+167
-116
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ docs/_site/
3333
docs/_repo/
3434
docs/metadata/
3535
tools/
36+
*.zip
3637

3738
# quickbuild.exe
3839
/VersionGeneratingLogs/
@@ -67,4 +68,4 @@ module/PowerShellEditorServices/Commands/en-US/*-help.xml
6768
module/PowerShellEditorServices/Third\ Party\ Notices.txt
6869

6970
# Visual Studio for Mac generated file
70-
*.userprefs
71+
*.userprefs

PowerShellEditorServices.build.ps1

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,21 @@
55

66
param(
77
[ValidateSet("Debug", "Release")]
8-
[string]$Configuration = "Debug"
8+
[string]$Configuration = "Debug",
9+
10+
[string]$PsesSubmodulePath = "$PSScriptRoot/module",
11+
12+
[string]$ModulesJsonPath = "$PSScriptRoot/modules.json",
13+
14+
[string]$DefaultModuleRepository = "PSGallery"
915
)
1016

1117
#Requires -Modules @{ModuleName="InvokeBuild";ModuleVersion="3.2.1"}
1218

1319
$script:IsCIBuild = $env:APPVEYOR -ne $null
1420
$script:IsUnix = $PSVersionTable.PSEdition -and $PSVersionTable.PSEdition -eq "Core" -and !$IsWindows
1521
$script:TargetFrameworksParam = "/p:TargetFrameworks=\`"$(if (!$script:IsUnix) { "net451;" })netstandard1.6\`""
22+
$script:SaveModuleSupportsAllowPrerelease = (Get-Command Save-Module).Parameters.ContainsKey("AllowPrerelease")
1623

1724
if ($PSVersionTable.PSEdition -ne "Core") {
1825
Add-Type -Assembly System.IO.Compression.FileSystem
@@ -179,7 +186,7 @@ task TestProtocol -If { !$script:IsUnix} {
179186
task TestHost -If { !$script:IsUnix} {
180187
Set-Location .\test\PowerShellEditorServices.Test.Host\
181188
exec { & $script:dotnetExe build -c $Configuration -f net452 }
182-
exec { & $script:dotnetExe xunit -configuration $Configuration -framework net452 -verbose -nobuild -x86 }
189+
exec { & $script:dotnetExe xunit -configuration $Configuration -framework net452 -verbose -nobuild }
183190
}
184191

185192
task CITest ?Test, {
@@ -220,6 +227,67 @@ task LayoutModule -After Build {
220227
}
221228
}
222229

230+
task RestorePsesModules -After Build {
231+
$submodulePath = (Resolve-Path $PsesSubmodulePath).Path + [IO.Path]::DirectorySeparatorChar
232+
Write-Host "`nRestoring EditorServices modules..."
233+
234+
# Read in the modules.json file as a hashtable so it can be splatted
235+
$moduleInfos = @{}
236+
237+
(Get-Content -Raw $ModulesJsonPath | ConvertFrom-Json).PSObject.Properties | ForEach-Object {
238+
$name = $_.Name
239+
$body = @{
240+
Name = $name
241+
MinimumVersion = $_.Value.MinimumVersion
242+
MaximumVersion = $_.Value.MaximumVersion
243+
Repository = if ($_.Value.Repository) { $_.Value.Repository } else { $DefaultModuleRepository }
244+
Path = $submodulePath
245+
}
246+
247+
if (-not $name)
248+
{
249+
throw "EditorServices module listed without name in '$ModulesJsonPath'"
250+
}
251+
252+
if ($script:SaveModuleSupportsAllowPrerelease)
253+
{
254+
$body += @{ AllowPrerelease = $_.Value.AllowPrerelease }
255+
}
256+
257+
$moduleInfos.Add($name, $body)
258+
}
259+
260+
# Save each module in the modules.json file
261+
foreach ($moduleName in $moduleInfos.Keys)
262+
{
263+
if (Test-Path -Path (Join-Path -Path $submodulePath -ChildPath $moduleName))
264+
{
265+
Write-Host "`tModule '${moduleName}' already detected. Skipping"
266+
continue
267+
}
268+
269+
$moduleInstallDetails = $moduleInfos[$moduleName]
270+
271+
$splatParameters = @{
272+
Name = $moduleName
273+
MinimumVersion = $moduleInstallDetails.MinimumVersion
274+
MaximumVersion = $moduleInstallDetails.MaximumVersion
275+
Repository = if ($moduleInstallDetails.Repository) { $moduleInstallDetails.Repository } else { $DefaultModuleRepository }
276+
Path = $submodulePath
277+
}
278+
279+
if ($script:SaveModuleSupportsAllowPrerelease)
280+
{
281+
$splatParameters += @{ AllowPrerelease = $moduleInstallDetails.AllowPrerelease }
282+
}
283+
284+
Write-Host "`tInstalling module: ${moduleName}"
285+
286+
Save-Module @splatParameters
287+
}
288+
Write-Host "`n"
289+
}
290+
223291
task BuildCmdletHelp {
224292
New-ExternalHelp -Path $PSScriptRoot\module\docs -OutputPath $PSScriptRoot\module\PowerShellEditorServices\Commands\en-US -Force
225293
}

module/Start-EditorServices.ps1 renamed to module/PowerShellEditorServices/Start-EditorServices.ps1

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,9 @@
1414
# canonical version of this script at the PowerShell Editor
1515
# Services GitHub repository:
1616
#
17-
# https://github.com/PowerShell/PowerShellEditorServices/blob/master/module/Start-EditorServices.ps1
17+
# https://github.com/PowerShell/PowerShellEditorServices/blob/master/module/PowerShellEditorServices/Start-EditorServices.ps1
1818

1919
param(
20-
[Parameter(Mandatory=$true)]
21-
[ValidateNotNullOrEmpty()]
22-
[string]
23-
$EditorServicesVersion,
24-
2520
[Parameter(Mandatory=$true)]
2621
[ValidateNotNullOrEmpty()]
2722
[string]
@@ -106,6 +101,13 @@ function ExitWithError($errorString) {
106101
exit 1;
107102
}
108103

104+
function WriteSessionFile($sessionInfo) {
105+
$sessionInfoJson = ConvertTo-Json -InputObject $sessionInfo -Compress
106+
Log "Writing session file with contents:"
107+
Log $sessionInfoJson
108+
$sessionInfoJson | Set-Content -Force -Path "$SessionDetailsPath" -ErrorAction Stop
109+
}
110+
109111
# Are we running in PowerShell 2 or earlier?
110112
if ($PSVersionTable.PSVersion.Major -le 2) {
111113
# No ConvertTo-Json on PSv2 and below, so write out the JSON manually
@@ -115,12 +117,6 @@ if ($PSVersionTable.PSVersion.Major -le 2) {
115117
ExitWithError "Unsupported PowerShell version $($PSVersionTable.PSVersion), language features are disabled."
116118
}
117119

118-
function WriteSessionFile($sessionInfo) {
119-
$sessionInfoJson = ConvertTo-Json -InputObject $sessionInfo -Compress
120-
Log "Writing session file with contents:"
121-
Log $sessionInfoJson
122-
$sessionInfoJson | Set-Content -Force -Path "$SessionDetailsPath" -ErrorAction Stop
123-
}
124120

125121
if ($host.Runspace.LanguageMode -eq 'ConstrainedLanguage') {
126122
WriteSessionFile @{
@@ -253,32 +249,11 @@ if ((Test-ModuleAvailable "PowerShellGet") -eq $false) {
253249
# TODO: WRITE ERROR
254250
}
255251

256-
# Check if the expected version of the PowerShell Editor Services
257-
# module is installed
258-
$parsedVersion = New-Object System.Version @($EditorServicesVersion)
259-
if ((Test-ModuleAvailable "PowerShellEditorServices" $parsedVersion) -eq $false) {
260-
if ($ConfirmInstall -and $isPS5orLater) {
261-
# TODO: Check for error and return failure if necessary
262-
LogSection "Install PowerShellEditorServices"
263-
Install-Module "PowerShellEditorServices" -RequiredVersion $parsedVersion -Confirm
264-
}
265-
else {
266-
# Indicate to the client that the PowerShellEditorServices module
267-
# needs to be installed
268-
Write-Output "needs_install"
269-
}
270-
}
271-
272252
try {
273253
LogSection "Start up PowerShellEditorServices"
274254
Log "Importing PowerShellEditorServices"
275255

276-
if ($isPS5orLater) {
277-
Import-Module PowerShellEditorServices -RequiredVersion $parsedVersion -ErrorAction Stop
278-
}
279-
else {
280-
Import-Module PowerShellEditorServices -Version $parsedVersion -ErrorAction Stop
281-
}
256+
Import-Module PowerShellEditorServices -ErrorAction Stop
282257

283258
# Locate available port numbers for services
284259
# There could be only one service on Stdio channel

modules.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"PSScriptAnalyzer":{
3+
"MinimumVersion":"1.6",
4+
"MaximumVersion":"1.99",
5+
"AllowPrerelease":false
6+
},
7+
"Plaster":{
8+
"MinimumVersion":"1.0",
9+
"MaximumVersion":"1.99",
10+
"AllowPrerelease":false
11+
}
12+
}

0 commit comments

Comments
 (0)