Skip to content

Commit

Permalink
Gitignore update
Browse files Browse the repository at this point in the history
New script to add ValiDomains to Teams app package
  • Loading branch information
Mark Powney committed Mar 11, 2022
1 parent 1b37cfb commit 4de1f5b
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 1 deletion.
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -261,4 +261,9 @@ paket-files/

# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
*.pyc


# Project specific exclusions - ZIP files (so Teams apps aren't inadvertently included, and Temp folder).
Temp/
*.zip
83 changes: 83 additions & 0 deletions Scripts/2.0/Add-ValidDomainToTeamsApp.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<#
.SYNOPSIS
Add-ValidDomainToTeamsApp.ps1
.DESCRIPTION
Adds a valid domain to a custom Microsoft Teams app manifest file
.PARAMETER AppManifestPath
Path to the app manifest file to add the valid domain to
.PARAMETER ValidDomain
The domain to add as a ValidDomain to the Microsoft Teams app manifest file
.PARAMETER NoBackup
(switch) Don't take a backup of the app manifest file
.PARAMETER KeepTempFolder
(switch) Keep the temp folder where the script updates the manifest
#>

param(
[Parameter(Mandatory = $false)]
[string]$AppManifestPath = ".\Valo.Connect.app.zip",

[Parameter(Mandatory = $true)]
[string]$ValidDomain,

[Parameter(Mandatory = $false)]
[switch]$NoBackup,

[Parameter(Mandatory = $false)]
[switch]$KeepTempFolder

)

if ($true -ne $AppManifestPath.ToLower().EndsWith(".zip")) {
Write-Error "AppManifestPath doesn't have a .zip extension"
exit
}

$AppManifestFile = Get-Item $AppManifestPath -ErrorAction SilentlyContinue

if ($null -eq $AppManifestFile) {
Write-Error "Couldn't find file from AppManifestPath paramater: $AppManifestPath"
exit
}

$DestinationFolderName = $AppManifestFile.Name.Replace($AppManifestFile.Extension, "")
$DestinationPath = Join-Path -Path $AppManifestFile.Directory.FullName -ChildPath "Temp" -AdditionalChildPath $DestinationFolderName

Expand-Archive $AppManifestFile.FullName -DestinationPath $DestinationPath -Force

$ManifestPath = Join-Path -Path $DestinationPath -ChildPath "manifest.json"
if ($true -ne (Test-Path $ManifestPath)) {
Write-Error "Unable to find manifest.json in app manifest. Is $($AppManifestFile.Name) a valid Teams app?"
exit
}

$ManifestContentsJson = ConvertFrom-Json (Get-Content $ManifestPath -Raw)
if ($true -eq $ManifestContentsJson.validDomains.Contains($ValidDomain)) {
Write-Warning "Manifest file in $($AppManifestFile.Name) already contains validDomain $ValidDomain, no change required"
exit
}

$ManifestContentsJson.validDomains += $ValidDomain
New-Item -Path $DestinationPath -Name "manifest.json" -ItemType File -Value (ConvertTo-Json -InputObject $ManifestContentsJson -Depth 99) -Force | Out-Null

$BackupPath = Join-Path -Path $AppManifestFile.Directory.FullName -ChildPath "Temp" -AdditionalChildPath "Backup"
New-Item -Path $BackupPath -ItemType Directory -Force | Out-Null

if ($true -ne $NoBackup) {
$BackupFileDestination = Join-Path -Path $BackupPath -ChildPath $AppManifestFile.Name
Write-Output "Backing up $($AppManifestFile.Name) to $($BackupFileDestination.Replace($AppManifestFile.Directory.FullName, "."))"
Move-Item $AppManifestFile.FullName -Destination $BackupFileDestination -Force
}

Write-Output "Updating $($AppManifestFile.Name) with additional ValidDomain $ValidDomain"
Compress-Archive -DestinationPath $AppManifestFile.FullName -LiteralPath (Get-ChildItem $DestinationPath -Depth 1) -Force

if ($true -ne $KeepTempFolder) {
Remove-Item -Path $BackupPath -Recurse
}

0 comments on commit 4de1f5b

Please sign in to comment.