This repository has been archived on 2023-05-22. You can view files and clone it, but cannot push or open issues/pull-requests.
fvtt-shared-compendia/scripts/lib.ps1

68 lines
2.9 KiB
PowerShell
Raw Normal View History

2023-05-16 21:38:03 +00:00
function Get-Update {
param (
[Parameter(Mandatory=$true)]
[String]$user,
[Parameter(Mandatory=$true)]
[String]$source,
[Parameter(Mandatory=$true)]
[String]$destination,
[String]$tempFolder,
[String]$keyFile = "C:\Users\dmitr\.ssh\dmitry.kirdyashkin"
)
if (!(Test-Path -Path $destination)){
New-Item -Path $destination -ItemType Directory -Force
}
Write-Host -ForegroundColor Cyan "`nDownloading packages..."
scp -i "$($keyFile)" "$($user)@$($source)" "$($destination)"
}
Get-Update -user owner -source "192.168.1.200:/mnt/data/foundryvtt-v10/Data/modules/shared-compendia/packs/*" -destination "C:\Users\dmitr\Documents\Repos\local\fvtt-shared-compendia\src\packs"
function update-archive {
param (
#$exclude = @(".gitignore","export","audio","temp",".git","create-archive.ps1"),
$workFolder = "C:\Users\dmitr\Documents\Repos\local\fvtt-shared-compendia\src",
$moduleName = "shared-compendia",
$uploadPath = "https://nexus.kdiva.ru/repository/generic"
)
#изменение версии и пути скачивания
Write-Host -ForegroundColor Cyan "`nModifying module.json..."
$content = Get-Content "$workFolder\module.json" | ConvertFrom-Json
$oldVersion = $content.version
$oldIndex = $oldVersion.ToString().split(".")[2] -as [int]
$newIndex = ($oldIndex + 1).ToString()
$patch = $oldVersion.LastIndexOf(".")
$newVersion = $oldVersion.Substring(0, $patch) + "." + $newIndex
$content.version = $newVersion
$archiveName = "$moduleName-$newVersion.zip"
$content.download = "$uploadPath/$moduleName/$archiveName"
$content | ConvertTo-Json | Set-Content "$workFolder\module.json"
Write-Host "Version Changed $oldVersion -> $newVersion"
#создание архива
Write-Host -ForegroundColor Cyan "`nCreating archive..."
Get-ChildItem $workFolder\ -Recurse -Depth 0 |
Where-Object {$_.Name -notin $exclude} |
Compress-Archive -Force -DestinationPath "$workFolder\$archiveName"
# Copy-Item -Path "$workFolder\src\module.json" -Destination "$workFolder\module.json" -Force
#загрузка архива
Write-Host -ForegroundColor Cyan "`nUploading archive..."
curl.exe --user owner:5ehfv3fbj8 --upload-file $workFolder\$archiveName $uploadPath/$moduleName/$archiveName --upload-file $workFolder\module.json $uploadPath/$moduleName/module.json
#проверка и удаление архива
$response = Invoke-RestMethod -Method Get -Uri 'https://nexus.kdiva.ru/service/rest/v1/assets?repository=generic'
# $response = curl.exe --user owner:5ehfv3fbj8 -X GET 'https://nexus.kdiva.ru/repository/service/rest/v1/assets?repository=generic' | ConvertFrom-Json
if ($response.items.path -like "*$archiveName*"){
Write-Host -ForegroundColor Cyan "`nUploaded successfully`nDeleting local archive..."
Remove-Item -Path $workFolder/*.zip
}
else {
Write-Host -ForegroundColor Red "Archive not found"
}
}
update-archive