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

80 lines
2.9 KiB
PowerShell

function Get-Update {
param (
[Parameter(Mandatory=$true)]
[String]$moduleName
)
$keyFile = "C:\Users\dmitr\.ssh\dmitry.kirdyashkin"
$localFolder = "C:\Users\dmitr\Documents\Repos\local\fvtt-shared-compendia"
$source = "192.168.1.200:/mnt/data/foundryvtt-v10/Data/modules/$moduleName/packs"
$destination = "$($localFolder)\$($moduleName)\packs"
$manifest = Get-Content $localFolder\$moduleName\module.json -Raw | `
ConvertFrom-Json
$dbName = $manifest | `
select-Object -ExpandProperty packs | `
Select-Object path | `
Split-Path -Leaf
if (!(Test-Path -Path $destination)){
New-Item -Path $destination -ItemType Directory -Force
}
Write-Host -ForegroundColor Cyan "`nDownloading packages..."
foreach ($db in $dbName) {
try {
scp -i "$($keyFile)" "owner@$($source)/$($db)" "$($destination)/$($db)"
}
catch {
exit
}
}
}
# Get-Update -module sc-characters
function New-Archive {
param (
[Parameter(Mandatory=$true)]
[String]$moduleName
)
$localFolder = "C:\Users\dmitr\Documents\Repos\local\fvtt-shared-compendia"
# $moduleName = "sc-characters"
$uploadPath = "https://nexus.kdiva.ru/repository/generic/shared-compendia/$($moduleName)"
$manifest = Get-Content $localFolder\$moduleName\module.json -Raw | `
ConvertFrom-Json
#изменение версии и пути скачивания
Write-Host -ForegroundColor Cyan "`nModifying module.json..."
#увеличение версии
[version]$version=$manifest.version
$newVersion = ([version]::New($version.Major,$version.Minor,$version.Build+1)).ToString()
# установка версии
$manifest.version = $newVersion
#установка имени архива
$archiveName = "$moduleName-$newVersion.zip"
$manifest.download = "$uploadPath/$archiveName"
#изменение module.json
$manifest | ConvertTo-Json | Set-Content "$localFolder\$moduleName\module.json"
#создание архива
Write-Host -ForegroundColor Cyan "`nCreating archive..."
Get-ChildItem $localFolder\$moduleName -Recurse -Depth 0 |
Where-Object {$_.Name -notin $exclude} |
Compress-Archive -Force -DestinationPath "$localFolder\$moduleName\$archiveName"
#загрузка архива
Write-Host -ForegroundColor Cyan "`nUploading archive..."
curl.exe --user owner:5ehfv3fbj8 --upload-file $localFolder\$moduleName\$archiveName $uploadPath/$archiveName --upload-file $localFolder\$moduleName\module.json $uploadPath/module.json
#проверка и удаление архива
$response = Invoke-RestMethod -Method Get -Uri 'https://nexus.kdiva.ru/service/rest/v1/assets?repository=generic'
if ($response.items.path -like "*$archiveName*"){
Write-Host -ForegroundColor Cyan "`nUploaded successfully`nDeleting local archive..."
Remove-Item -Path $localFolder/$moduleName/*.zip
}
else {
Write-Host -ForegroundColor Red "Archive not found"
}
}