Skip to content

Commit b7e1d69

Browse files
committed
Merge pull request #50 from my-personal-forks/scripts
tidy up script
2 parents 9ef02bd + 82af551 commit b7e1d69

File tree

1 file changed

+35
-14
lines changed

1 file changed

+35
-14
lines changed

bin/Build-Folder.ps1

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,54 @@
1+
<#
2+
.SYNOPSIS
3+
Builds a version of the Sublime Text PowerShell package and deploys it
4+
locally to Data/Packages/PowerShell.
5+
6+
.DESCRIPTION
7+
Builds a version of the Sublime Text PowerShell package and deploys it
8+
locally to Data/Packages/PowerShell.
9+
#>
10+
[CmdletBinding()]
111
param([switch]$Release)
212

313
$script:thisDir = split-path $MyInvocation.MyCommand.Path -parent
414

515
. (join-path $script:thisDir "Config.ps1")
6-
716
if(!$?){
8-
write-error "Could not read config."
9-
exit 1
17+
write-error "Could not read configuration file."
18+
exit 1
1019
}
1120

12-
# copy to local folder
21+
$installedPackages = (GetConfigValue 'global-win' 'installed-packages')
22+
$packagesFolder = "$installedPackages/../Packages"
23+
$pathToPowerShellPackage = "$packagesFolder/PowerShell"
24+
25+
# Deploy package locally.
1326
push-location $thisDir
1427
push-location '..'
15-
$installedPackages = (GetConfigValue 'global-win' 'installed-packages')
16-
write-output "copying files..."
17-
# TODO: Perhaps we should delete the folder first.
18-
copy-item * -recurse -force -exclude ".git" "$installedPackages/../Packages/PowerShell"
28+
if (test-path $pathToPowerShellPackage) {
29+
write-verbose "Deleting old files..."
30+
remove-item "$pathToPowerShellPackage/*" -recurse -force
31+
}
32+
else {
33+
write-verbose "Creating target directory..."
34+
new-item -itemtype 'directory' $pathToPowerShellPackage
35+
}
36+
write-verbose "Copying files..."
37+
copy-item * -recurse -force -exclude ".git" $pathToPowerShellPackage
1938
pop-location
2039
pop-location
2140

22-
write-output "restarting editor... bye!"
23-
start-sleep -milliseconds 100
24-
get-process "sublime_text" | stop-process
41+
# Restart editor.
42+
write-verbose "Restarting editor..."
43+
get-process "sublime_text" -erroraction 'silentlycontinue' | `
44+
stop-process -erroraction 'silentlycontinue'
45+
2546
start-sleep -milliseconds 250
26-
# sss
47+
2748
$editor = (GetConfigValue 'global-win' 'editor')
2849
if(!$?){
29-
write-error "Could not locate editor command."
30-
exit 1
50+
write-error "Could not locate editor command."
51+
exit 1
3152
}
3253

3354
&$editor

0 commit comments

Comments
 (0)