-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPublish.ps1
51 lines (43 loc) · 1.8 KB
/
Publish.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
# Script should be executed manually by developer
$ModuleName = 'psaptgetupdate'
# check running folder
if (!(Test-Path "..\$ModuleName\$ModuleName.psd1")) {
throw "We are not in correct folder"
} else {
"Checking module $(Resolve-Path "..\$ModuleName\$ModuleName.psd1")"
}
# test manifest
try {
$Module = Test-ModuleManifest "$ModuleName.psd1" -ea Stop
"Module $ModuleName.psd1 is OK"
} catch {
throw 'Module manifest not in proper format'
}
# test if remote is not the same
if (Find-Module -Name $ModuleName -RequiredVersion ($Module.Version) -Repository PSGallery -ea 0) {
throw 'Module with same version already exists'
} else {
"No module with version $($Module.Version) found online"
}
# get nuget key from somewhere?
if ($NugetKey) {
"NugetKey found"
} else {
throw 'Please define $NugetKey variable'
}
# copy entire folder to temp location
if ($IsLinux -or $IsMacOS) {$Destination = '/tmp'}
else {$Destination = $Env:TEMP}
$Destination2 = Join-Path $Destination $ModuleName
"Copying to $Destination2"
if (Test-Path $Destination2) {Remove-Item $Destination2 -Recurse -Force}
Copy-Item -Path . -Destination $Destination -Recurse # it creates folder $ModuleName
# remove not needed files (starting with dot and from .gitignore)
"Removing not needed files"
[string[]]$Exclude = (Get-Content '.gitignore')
Get-ChildItem -Path $Destination2 -Recurse -Force | where Name -Match '^\.' | Remove-Item -Recurse -Force
Get-ChildItem -Path $Destination2 -Include $Exclude -Recurse -Force | Remove-Item -Recurse -Force
# publish
Read-Host "All prerequisites check. Press Enter to Publish module or Ctrl+C to abort"
Publish-Module -Path $Destination2 -Repository PSGallery -NuGetApiKey $NugetKey -Verbose
"Module $ModuleName published to PowerShell Gallery"