-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdev.ps1
86 lines (75 loc) · 2.18 KB
/
dev.ps1
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
# git clone PWSH to folder or pull latest changes
[CmdletBinding()]
param (
# clone the source code into the pwsh sub-folder of the folder
[Parameter()]
[string]$PWSHParentFolder,
# clone depth
[Parameter()]
[int]
$CloneDepth = 1
)
if(!(Get-Command git -ErrorAction Ignore)) {
write-error "git is not installed, please install"
return
}
# # install pwsh 7
# if ($PSVersionTable.PSVersion.Major -lt 7) {
# write-error "need to install powershell version great than 7"
# write-host "https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-windows"
# Write-host 'please install it and run this script again in the new powershell' -ForegroundColor Blue
# return
# }
if (Test-Path $PWSHParentFolder -PathType leaf) {
write-error "a file $PWSHParentFolder already exists, please remove it first or try a different folder"
return
}
if (!(Test-Path $PWSHParentFolder -PathType Container)) {
write-host "$PWSHParentFolder does not exist, create it..."
New-Item -ItemType Directory -Path $PWSHParentFolder -Force | Out-Null
}
$root = "$PWSHParentFolder\pwsh"
if (Test-Path $root -type Container) {
try {
Push-Location $root
$status = git status
$dirtyMsg = $status -match 'modified:|Untracked files:|Your branch is ahead of'
if ($dirtyMsg.length -gt 0) {
$decision = $Host.UI.PromptForChoice('Override Local Changes?', "You have local changes in $root?,`ndo you want to continue to hard reset local changes?", @('&Yes', '&No'), 0)
if ($decision -eq 0) {
git reset --hard
# Remove-Item -force -Recurse "$root"
}
else {
'please check local changes and rerun the command'
return
}
}
}
finally {
Pop-Location
}
}
try {
Push-Location $PWSHParentFolder
if (Get-ChildItem 'pwsh' -ErrorAction Ignore) {
Push-Location 'pwsh'
write-host "pull changes into $pwd"
git pull
Pop-Location
}
else {
git clone http://github.com/metasong/pwsh.git --depth $CloneDepth
}
. "$root/config.ps1"
if (gcm code -ErrorAction Ignore) {
code $root
code $PROFILE.CurrentUserAllHosts
}
}
catch {
write-error $_.Exception.Message
}
finally {
Pop-Location
}