-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstall.ps1
More file actions
108 lines (85 loc) · 3.59 KB
/
Copy pathInstall.ps1
File metadata and controls
108 lines (85 loc) · 3.59 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env pwsh
param(
[string]$version="5.3.0",
[switch]$updateModule,
[switch]$noInstallModule,
[switch]$publish,
[switch]$PublishPSGallery,
[string]$nuGetApiKey,
[string]$releaseNoteFile
)
#
# This script will install the modules to your PowerShell user module
# directory and configure your profile startup to load the environment
# configuration
#
$modules = @("Tririga-Manage", "Tririga-Manage-Rest")
# Set active path to script-location:
$path = $MyInvocation.MyCommand.Path
if (!$path) {$path = $psISE.CurrentFile.Fullpath}
if ($path) {$path = Split-Path $path -Parent}
Set-Location $path
# Check $Env:PSModulePath to see the default search locations
Function Update-ModuleManifestFilesForInstall() {
param(
[Parameter(Mandatory)]
[string]$moduleName
)
$functionNames = Get-ChildItem $moduleName -Recurse | Where-Object { $_.Name -match ".*\.psm1" } -PipelineVariable file | ForEach-Object {
$ast = [System.Management.Automation.Language.Parser]::ParseFile($file.FullName, [ref] $null, [ref] $null)
if ($ast.EndBlock.Statements.Name) {
$ast.EndBlock.Statements.Name
}
}
$functionNames = $functionNames | Where-Object { $_.Contains("-") }
Write-Output "[$moduleName] Export functions: $functionNames"
$modulePath = (Resolve-Path "$moduleName\$moduleName.psd1").Path
$Params = @{
Path = $modulePath
FunctionsToExport = $functionNames
ModuleVersion = $version
}
if($releaseNoteFile) {
$Params["ReleaseNotes"] = (Get-Content $releaseNoteFile)
}
Update-ModuleManifest @Params
}
if($updateModule) {
Write-Output "==> Update Module definition files"
$modules | ForEach-Object { Update-ModuleManifestFilesForInstall $_ }
}
$profileDir = Split-Path $Profile -Parent
$moduleDir = Join-Path $profileDir "Modules"
if (!$noInstallModule) {
Write-Output "==> Install Modules to $moduleDir"
New-Item -Type Directory -Path $moduleDir -Force | Out-Null
$modules | ForEach-Object { Copy-Item -Recurse -Force -Path $_ -Destination $moduleDir; Write-Output "Installed module $_" }
Write-Output "==> Update Profile at $Profile"
$environmentsFile = Join-Path $profileDir "environments.psd1"
If (!(Test-Path -Path "$Profile") -or !(Select-String -Path "$Profile" -pattern "TririgaEnvironments"))
{
if (!(Test-Path -Path $environmentsFile)) {
Copy-Item environments.sample.psd1 $environmentsFile
Write-Output "A sample environments file has been placed at $environmentsFile. Edit to customize"
}
Write-Output "Installing this script to your PowerShell profile $Profile"
"`$TririgaEnvironments = (Import-PowerShellDataFile `"$environmentsFile`")" | Out-file "$Profile" -append
"`$DBeaverBin=`"$($env:UserProfile)\AppData\Local\DBeaver\dbeaver.exe`"" | Out-file "$Profile" -append
} else {
echo "Profile already configured"
}
}
if ($publish) {
if(!$nuGetApiKey) {
Write-Error '-NugetApiKey is required when -Publish switch is set'
exit 1
}
$modules | ForEach-Object { Publish-Module -Name $_\$_.psd1 -Repository Gitea -NuGetApiKey $nuGetApiKey; Write-Output "Published module $_" }
}
if ($publishPSgallery) {
if(!$nuGetApiKey) {
Write-Error '-NugetApiKey is required when -Publish switch is set'
exit 1
}
$modules | ForEach-Object { Publish-Module -Name $_\$_.psd1 -NuGetApiKey $nuGetApiKey; Write-Output "Published module $_" }
}