-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.ps1
49 lines (37 loc) · 1.72 KB
/
build.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
param(
[Parameter(Mandatory = $true)]
[string]$Version
)
$baseDir = ".\templates\"
$outputDir = ".\output"
if(Test-Path -Path $outputDir) {
Remove-Item -Path $outputDir -Recurse
}
$releaseDirectory = New-Item -ItemType Directory -Path ".\" -Name $outputDir
$metadataInfo = @()
$templates = Get-ChildItem -Path $baseDir
foreach($template in $templates) {
$templateMetadataFile = Join-Path $template.FullName "template.json"
if(-not(Test-Path -Path $templateMetadataFile)) {
Write-Output "Skipping template $($template.Name) due to missing metadata file."
continue
}
$templateMetadata = Get-Content -Path $templateMetadataFile | ConvertFrom-Json
$metadataTable = @{}
$templateMetadata.psobject.Properties | ForEach-Object { $metadataTable[$_.Name] = $_.Value }
$metadataTable["directory"] = $template.Name
$metadataTable["package"] = "$($template.Name).zip"
$files = Get-ChildItem -Path $template.FullName -Exclude "template.json"
$outputFile = Join-Path -Path $releaseDirectory -ChildPath $metadataTable["package"]
Compress-Archive -Path $files -DestinationPath $outputFile -CompressionLevel Optimal -Force
#$templateDirectory = New-Item -ItemType Directory -Path $releaseDirectory.FullName -Name $metadataTable["directory"]
#Copy-Item -Path $files -Destination $templateDirectory
#Compress-Archive -Path "$($templateDirectory.FullName)" -DestinationPath $outputFile -CompressionLevel Optimal -Force
#Remove-Item -Path $templateDirectory -Recurse
$metadataInfo += $metadataTable
}
$metadata = @{
"version" = $Version
"templates" = $metadataInfo
}
ConvertTo-Json $metadata | Out-File -FilePath (Join-Path $releaseDirectory.FullName "templates.json")