forked from Zerg00s/FlowPowerAppsMigrator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConvertPackage.ps1
More file actions
89 lines (74 loc) · 4.43 KB
/
ConvertPackage.ps1
File metadata and controls
89 lines (74 loc) · 4.43 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
Add-Type -AssemblyName System.IO.Compression.FileSystem
$CurrentPath = (Get-Location).Path + "\"
# Clean previously generated packages
Get-ChildItem $CurrentPath -Filter "Converted*" -Recurse | Remove-Item
$packages = Get-ChildItem -Path .\src -Filter "*.zip"
$resources = Import-Csv -Path .\resourceMapping.csv
for ($k = 0; $k -lt $packages.count; $k++) {
$package = $packages[$k]
$DestinationFolder = $CurrentPath + "dist\" + $package.BaseName
Remove-Item $DestinationFolder -Force -Recurse -ErrorAction SilentlyContinue
[System.IO.Compression.ZipFile]::ExtractToDirectory($package.FullName, $DestinationFolder)
$files = Get-ChildItem $DestinationFolder -Recurse -File -Include ('*.json', '*.xml')
$files | ForEach-Object {
for ($i = 0; $i -lt $resources.Count; $i++) {
Write-Host Converting $resources[$i].resource "... "
if ($resources[$i].newId) {
(Get-Content -LiteralPath $_.FullName) -replace $resources[$i].oldId, $resources[$i].newId | Set-Content -LiteralPath $_.FullName
Write-host " [Success] " -ForegroundColor Green -NoNewline
Write-host $($resources[$i].resource) converted
}
else {
if ($resources[$i].resource -match ".aspx" -eq $false) {
Write-host "` [Warning] " -ForegroundColor Yellow -NoNewline
Write-host SharePoint List or a Library is missing in the destination site collection. Make sure it exists if used: $($resources[$i].resource)
}
}
}
}
$solutionManifest = Get-ChildItem -Path $DestinationFolder -Filter "solution.xml"
if ($solutionManifest) {
Write-host $package.Name is a Solution Package -ForegroundColor Cyan
}
# Searching for an MSAPP file. These are zip-archives that need to be converted too:
$msappPackages = Get-ChildItem $DestinationFolder -Recurse -File -Filter "*.msapp*"
if ($null -ne $msappPackages -and $msappPackages.Count -ne 0) {
for ($y = 0; $y -lt $msappPackages.count; $y++) {
$msAppPackage = $msappPackages[$y];
$msAppPackageDestinationFolder = $msappPackage.Directory.FullName + "\" + $msAppPackage.BaseName
[System.IO.Compression.ZipFile]::ExtractToDirectory($msAppPackage.FullName , $msAppPackageDestinationFolder)
$files = Get-ChildItem $msAppPackageDestinationFolder -Recurse -File -Filter "*.json*"
$files | ForEach-Object {
for ($i = 0; $i -lt $resources.Count; $i++) {
if ([System.String]::IsNullOrEmpty($resources[$i].newId) -eq $false) {
(Get-Content -LiteralPath $_.FullName) -replace $resources[$i].oldId, $resources[$i].newId | Set-Content -LiteralPath $_.FullName
}
else {
if ($resources[$i].resource -match ".aspx" -eq $false) {
Write-host "` [Warning] " -ForegroundColor Yellow -NoNewline
Write-host SharePoint List or a Library is missing in the destination site collection. Make sure it exists if used: $($resources[$i].resource)
}
}
}
}
Write-host "App sub-package found:" $msAppPackage
Remove-Item $msAppPackage.FullName -Force
Push-Location $msAppPackageDestinationFolder
[System.IO.Compression.ZipFile]::CreateFromDirectory($msAppPackageDestinationFolder, $msAppPackage.FullName, [System.IO.Compression.CompressionLevel]::Optimal, $false)
Pop-Location
Remove-Item $msAppPackageDestinationFolder -Force -Recurse -ErrorAction SilentlyContinue
}
}
Remove-Item $($CurrentPath + "dist\Converted_" + $package.BaseName + ".zip") -Force -Recurse -ErrorAction SilentlyContinue
Push-Location $($DestinationFolder)
if ($solutionManifest) {
tar -a -c -f $("..\Converted_" + $package.BaseName + ".zip") *
}
else {
[System.IO.Compression.ZipFile]::CreateFromDirectory($DestinationFolder, $CurrentPath + "dist\Converted_" + $package.BaseName + ".zip", [System.IO.Compression.CompressionLevel]::Optimal, $false)
}
Pop-Location
Remove-Item $DestinationFolder -Force -Recurse -ErrorAction SilentlyContinue
}
Write-Host All Apps were converted -ForegroundColor Green
Invoke-Item .\dist