forked from microsoft/python-sample-vscode-flask-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMySolution.ps1
More file actions
64 lines (57 loc) · 2.48 KB
/
MySolution.ps1
File metadata and controls
64 lines (57 loc) · 2.48 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
$path = Join-Path $PSScriptRoot ".."
$replaceObjectIds = @{
"50130" = 80130
"50133" = 80133
"50101" = 80101
"50100" = 80100
"50149" = 80149
}
$replaceValues = @{
"00000000-0000-0000-0000-000000000001" = [Guid]::NewGuid().ToString()
"00000000-0000-0000-0000-000000000002" = [Guid]::NewGuid().ToString()
"00000000-0000-0000-0000-000000000003" = [Guid]::NewGuid().ToString()
"HelloWorld" = "MyApp"
"Default Publisher" = "My Name"
"Default App Name" = "My App"
"Default Base App Name" = "My Base App"
"Default Test App Name" = "My Test App"
"2.0.0.0" = "1.0.0.0"
"https://businesscentralapps.azureedge.net/helloworld/latest/apps.zip" = ""
} + $replaceObjectIds
function ReplaceProperty { Param ($object, $property)
if ($object.PSObject.Properties.name -eq $property) {
$str = "$($object."$property")"
if ($replaceValues.ContainsKey($str)) {
Write-Host "- change $property from $str to $($replaceValues[$str]) "
$object."$property" = $replaceValues[$str]
}
}
}
function ReplaceObject { Param($object)
"id", "appId", "name", "publisher", "version", "previousApps", "appSourceCopMandatoryAffixes", "appSourceCopSupportedCountries","from","to" | ForEach-Object {
ReplaceProperty -object $object -property $_
}
}
Get-ChildItem -Path $path | Where-Object { $_.psIsContainer -and $_.Name -notlike ".*" } | Get-ChildItem -Recurse -filter "app.json" | ForEach-Object {
$appJsonFile = $_.FullName
$appJson = Get-Content $appJsonFile | ConvertFrom-Json
Write-Host -ForegroundColor Yellow $appJsonFile
ReplaceObject -object $appJson
Write-Host "Check idRanges"
$appJson.idRanges | ForEach-Object { ReplaceObject($_) }
Write-Host "Check Dependencies"
$appJson.dependencies | ForEach-Object { ReplaceObject($_) }
$appJson | ConvertTo-Json -Depth 10 | Set-Content $appJsonFile
}
Get-ChildItem -Path $path | Where-Object { $_.psIsContainer -and $_.Name -notlike ".*" } | Get-ChildItem -Recurse -filter "*.al" | ForEach-Object {
$source = Get-Content $_.FullName
$replaceObjectIds.Keys | % {
$source = $source.Replace("$_", $replaceObjectIds."$_")
}
Set-Content -Path $_.FullName -Value $source
}
$settingsFile = Join-Path $PSScriptRoot "settings.json"
$settings = Get-Content $settingsFile | ConvertFrom-Json
Write-Host -ForegroundColor Yellow $settingsFile
ReplaceObject -object $settings
$settings | ConvertTo-Json -Depth 10 | Set-Content $settingsFile