From 385ed6dff55570a884da1ae61f2f1a9263d026ab Mon Sep 17 00:00:00 2001 From: Iristyle Date: Mon, 16 Sep 2013 12:11:50 -0400 Subject: [PATCH] feat(ST2.PackageControl): 2.0.1-beta pre-release - fixes issues with many packages being installed and package control completely wigging out - fixed bug that prevented "Package Control.sublime-package" from being overwritten - made Merge-PackageControlSettings fancier to handle named values --- .../SublimeText2.PackageControl.nuspec | 3 +- .../tools/ChocolateyInstall.ps1 | 7 +++- .../tools/Package Control.sublime-settings | 3 ++ core/SublimeHelpers.ps1 | 40 ++++++++++++++----- 4 files changed, 42 insertions(+), 11 deletions(-) create mode 100644 SublimeText2.PackageControl/tools/Package Control.sublime-settings diff --git a/SublimeText2.PackageControl/SublimeText2.PackageControl.nuspec b/SublimeText2.PackageControl/SublimeText2.PackageControl.nuspec index 5ad457f..46613ca 100644 --- a/SublimeText2.PackageControl/SublimeText2.PackageControl.nuspec +++ b/SublimeText2.PackageControl/SublimeText2.PackageControl.nuspec @@ -3,7 +3,7 @@ SublimeText2.PackageControl Sublime Text 2 Package Control - 1.6.3 + 2.0.1-beta1 Will Bond Ethan J Brown A full-featured package manager that helps discovering, installing, updating and removing packages for Sublime Text 2. It features an automatic upgrader and supports GitHub, BitBucket and a full channel/repository system. @@ -25,6 +25,7 @@ + diff --git a/SublimeText2.PackageControl/tools/ChocolateyInstall.ps1 b/SublimeText2.PackageControl/tools/ChocolateyInstall.ps1 index f14b834..ff6aab5 100644 --- a/SublimeText2.PackageControl/tools/ChocolateyInstall.ps1 +++ b/SublimeText2.PackageControl/tools/ChocolateyInstall.ps1 @@ -9,8 +9,13 @@ try { $current = Get-CurrentDirectory . (Join-Path $current 'SublimeHelpers.ps1') + . (Join-Path $current 'JsonHelpers.ps1') - Install-SublimePackageControl + # TODO: come up with a better way to do this install / set this setting + # that will work based on the semver in this packages .nuspec file + Install-SublimePackageControl -PreRelease + $packageControl = Join-Path $current 'Package Control.sublime-settings' + Merge-PackageControlSettings -FilePath $packageControl Write-ChocolateySuccess $package } catch { diff --git a/SublimeText2.PackageControl/tools/Package Control.sublime-settings b/SublimeText2.PackageControl/tools/Package Control.sublime-settings new file mode 100644 index 0000000..835b2d9 --- /dev/null +++ b/SublimeText2.PackageControl/tools/Package Control.sublime-settings @@ -0,0 +1,3 @@ +{ + "install_prereleases": true +} diff --git a/core/SublimeHelpers.ps1 b/core/SublimeHelpers.ps1 index 7d3c596..d66c284 100644 --- a/core/SublimeHelpers.ps1 +++ b/core/SublimeHelpers.ps1 @@ -93,7 +93,11 @@ function Install-SublimePackageControl [Parameter(Mandatory = $false)] [ValidateRange(2,3)] [int] - $Version = 2 + $Version = 2, + + [Parameter(Mandatory = $false)] + [Switch] + $PreRelease = $false ) # install package control @@ -107,12 +111,15 @@ function Install-SublimePackageControl 2 { $packageControl = Join-Path $packagesPath 'Package Control.sublime-package' - if (!(Test-Path $packageControl)) + if (Test-Path $packageControl) { Remove-item $packageControl } + + # http://wbond.net/sublime_packages/package_control/installation + $packageUrl = 'http://sublime.wbond.net/Package%20Control.sublime-package' + if ($PreRelease) { - # http://wbond.net/sublime_packages/package_control/installation - $packageUrl = 'http://sublime.wbond.net/Package%20Control.sublime-package' - Get-ChocolateyWebFile -url $packageUrl -fileFullPath $packageControl + $packageUrl = 'https://sublime.wbond.net/prerelease/Package%20Control.sublime-package' } + Get-ChocolateyWebFile -url $packageUrl -fileFullPath $packageControl } 3 { @@ -151,16 +158,31 @@ function Merge-PackageControlSettings $new = ConvertFrom-Json ([IO.File]::ReadAllText($FilePath)) - # simple arrays - 'installed_packages', 'repositories' | + $simpleArrays = @('installed_packages', 'repositories', 'channels', + 'auto_upgrade_ignore', 'git_update_command', 'hg_update_command', + 'dirs_to_ignore', 'files_to_ignore', 'files_to_include', + 'files_to_ignore_binary', 'files_to_include_binary' ) + $simpleArrays | ? { $new.$_ -ne $null } | % { Merge-JsonArray -Name $_ -Destination $existing -Array $new.$_ } - # maps - 'package_name_map' | + $maps = @('package_name_map') + $maps | ? { $new.$_ -ne $null } | % { Merge-JsonSimpleMap -Name $_ -Destination $existing -SimpleMap $new.$_ } + $arrayOfMaps = @('certs') + $arrayOfMaps | + ? { $new.$_ -ne $null } | + % { Merge-JsonArrayOfSimpleMap -Name $_ -Destination $existing -Array $new.$_ } + + $excluded = $simpleArrays + $maps + $arrayOfMaps + $new.PSObject.Properties | + ? { $excluded -inotcontains $_.Name } | + % { + Merge-JsonNamedValue -Name $_.Name -Destination $existing -Value $_.Value + } + $json = $existing | ConvertTo-Json -Depth 10 | ConvertFrom-UnicodeEscaped Write-Verbose "Updated settings: `n`n$json`n" [IO.File]::WriteAllText($existingPath, $json, [System.Text.Encoding]::ASCII)