fix(sublimehelpers): file / dir existence

- Ensure User direcotry exists in packages directory
 - Ensure 'Package Control.sublime-settings' exists
 - Ensure 'Preferences.sublime-settings' exists
This commit is contained in:
Iristyle
2013-03-22 10:23:52 -04:00
parent 5643c8d0db
commit 5c500f24ab

View File

@@ -12,7 +12,9 @@ function Get-SublimePackagesPath
function Get-SublimeUserPath function Get-SublimeUserPath
{ {
Join-Path (Get-SublimePackagesPath) 'User' $path = Join-Path (Get-SublimePackagesPath) 'User'
if (!(Test-Path $path)) { New-Item $path -Type Directory }
return $path
} }
function Merge-PackageControlSettings function Merge-PackageControlSettings
@@ -26,6 +28,10 @@ function Merge-PackageControlSettings
$root = Get-SublimeUserPath $root = Get-SublimeUserPath
$existingPath = Join-Path $root 'Package Control.sublime-settings' $existingPath = Join-Path $root 'Package Control.sublime-settings'
if (!(Test-Path $existingPath))
{
'{}' | Out-File -FilePath $existingPath -Encoding ASCII
}
$existingText = [IO.File]::ReadAllText($existingPath) -replace '(?m)^\s*//.*$', '' $existingText = [IO.File]::ReadAllText($existingPath) -replace '(?m)^\s*//.*$', ''
if ([string]::IsNullOrEmpty($existingText)) { $existingText = '{}' } if ([string]::IsNullOrEmpty($existingText)) { $existingText = '{}' }
@@ -60,6 +66,11 @@ function Merge-Preferences
$root = Get-SublimeUserPath $root = Get-SublimeUserPath
$existingPath = Join-Path $root 'Preferences.sublime-settings' $existingPath = Join-Path $root 'Preferences.sublime-settings'
if (!(Test-Path $existingPath))
{
'{}' | Out-File -FilePath $existingPath -Encoding ASCII
}
$existingText = [IO.File]::ReadAllText($existingPath) -replace '(?m)^\s*//.*$', '' $existingText = [IO.File]::ReadAllText($existingPath) -replace '(?m)^\s*//.*$', ''
if ([string]::IsNullOrEmpty($existingText)) { $existingText = '{}' } if ([string]::IsNullOrEmpty($existingText)) { $existingText = '{}' }