-
Notifications
You must be signed in to change notification settings - Fork 0
/
Install.psake.ps1
97 lines (84 loc) · 3.11 KB
/
Install.psake.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
87
88
89
90
91
92
93
94
95
96
#Install.psake.ps1
###############################################################################
# Dot source the user's customized properties and extension tasks.
###############################################################################
. $PSScriptRoot\Install.settings.ps1
Task default -Depends Install,Update
Task Install -Depends RegisterPSRepository -Precondition { $Mode -eq 'Install'} {
#Suppose : PowershellGet à jour
#On précise le repository car Pester est également sur Nuget
$PSGallery.Modules |ForEach-Object {
Write-Host "PSGallery : Install module $_"
PowershellGet\Install-Module -Name $_ -Repository PSGallery -Scope $InstallationScope -SkipPublisherCheck -AllowClobber
}
$MyGet.Modules |ForEach-Object {
Write-Host "MyGet :Install module $_"
PowershellGet\Install-Module -Name $_ -Repository OttoMatt -Scope $InstallationScope -AllowClobber
}
}
Task RegisterPSRepository {
Foreach ($Repository in $Repositories)
{
$Name=$Repository.Name
try{
$RepositoryNames.Add($Name) > $Null
Get-PSRepository $Name -EA Stop >$null
}catch {
if ($_.CategoryInfo.Category -ne 'ObjectNotFound')
{ throw $_ }
else
{
$Parameters=@{
Name=$Name
SourceLocation=$Repository.SourceLocation
PublishLocation=$Repository.PublishLocation
ScriptSourceLocation= "$($Repository.SourceLocation)\"
ScriptPublishLocation=$Repository.SourceLocation
InstallationPolicy='Trusted'
}
Write-Output "Register repository '$($Repository.Name)'"
Register-PSRepository @Parameters
}
}
}
}
Task Update -Precondition { $Mode -eq 'Update'} {
$sbUpdateOrInstallModule={
$ModuleName=$_
try {
Write-Host "Update module $ModuleName"
PowershellGet\Update-Module -name $ModuleName
}
catch [Microsoft.PowerShell.Commands.WriteErrorException]{
if ($_.FullyQualifiedErrorId -match ('^ModuleNotInstalledOnThisMachine'))
{
Write-Host "`tInstall module $ModuleName"
PowershellGet\Install-Module -Name $ModuleName -Repository $CurrentRepository -Scope $InstallationScope
}
else
{ throw $_ }
}
}
$sbUpdateOrInstallScript={
$ScriptName=$_
try {
Write-Host "Update script $ScriptName"
PowershellGet\Update-Script -name $ScriptName
}
catch [Microsoft.PowerShell.Commands.WriteErrorException]{
if ($_.FullyQualifiedErrorId -match ('^ScriptNotInstalledOnThisMachine'))
{
Write-Host "`tInstall script $ScriptName"
PowershellGet\Install-Script -Name $ScriptName -Repository $CurrentRepository -Scope $InstallationScope
}
else
{ throw $_ }
}
}
$CurrentRepository='PSGallery'
$PSGallery.Modules|Foreach-Object $sbUpdateOrInstallModule
$PSGallery.Scripts|Foreach-Object $sbUpdateOrInstallScript
$CurrentRepository='OttoMatt'
$MyGet.Modules|Foreach-Object $sbUpdateOrInstallModule
$MyGet.Scripts|Foreach-Object $sbUpdateOrInstallScript
}