11param (
2- [string ]
3- $Repository = ' PSGallery'
2+ [string ]
3+ $Repository = ' PSGallery' ,
4+
5+ [string ]
6+ $AppRg ,
7+
8+ [string ]
9+ $AppName
410)
511$workingDirectory = Split-Path $PSScriptRoot
12+ $config = Import-PowerShellDataFile - Path " $PSScriptRoot \build.config.psd1"
613
714# Prepare output path and copy function folder
815Remove-Item - Path " $workingDirectory /publish" - Recurse - Force - ErrorAction Ignore
@@ -12,12 +19,46 @@ Copy-Item -Path "$workingDirectory/function/*" -Destination $buildFolder.FullNam
1219# Process Dependencies
1320$requiredModules = (Import-PowerShellDataFile - Path " $workingDirectory /þnameþ/þnameþ.psd1" ).RequiredModules
1421foreach ($module in $requiredModules ) {
15- Save-Module - Name $module - Path " $ ( $buildFolder.FullName ) /modules" - Force - Repository $Repository
22+ Save-Module - Name $module - Path " $ ( $buildFolder.FullName ) /modules" - Force - Repository $Repository
1623}
1724
1825# Process Function Module
1926Copy-Item - Path " $workingDirectory /þnameþ" - Destination " $ ( $buildFolder.FullName ) /modules" - Force - Recurse
27+ $commands = Get-ChildItem - Path " $ ( $buildFolder.FullName ) /modules/þnameþ/Functions" - Recurse - Filter * .ps1 | ForEach-Object BaseName
28+ Update-ModuleManifest - Path " $ ( $buildFolder.FullName ) /modules/þnameþ/þnameþ.psd1" - FunctionsToExport $commands
29+
30+ # Generate Http Trigger
31+ $httpCode = Get-Content - Path " $PSScriptRoot \functionHttp\run.ps1" | Join-String " `n "
32+ $httpConfig = Get-Content - Path " $PSScriptRoot \functionHttp\function.json" | Join-String " `n "
33+ foreach ($command in Get-ChildItem - Path " $workingDirectory \þnameþ\functions\httpTrigger" - Recurse - File - Filter * .ps1) {
34+ $authLevel = $config.HttpTrigger.AuthLevel
35+ if ($config.HttpTrigger.AuthLevelOverride .$ ($command.BaseName )) {
36+ $authLevel = $config.HttpTrigger.AuthLevelOverride .$ ($command.BaseName )
37+ }
38+ $endpointFolder = New-Item - Path $buildFolder.FullName - Name $command.BaseName - ItemType Directory
39+ $httpCode -replace ' %COMMAND%' , $command.BaseName | Set-Content - Path " $ ( $endpointFolder.FullName ) \run.ps1"
40+ $httpConfig -replace ' %AUTHLEVEL%' , $authLevel | Set-Content - Path " $ ( $endpointFolder.FullName ) \function.json"
41+ }
42+
43+ # Generate Timer Trigger
44+ $timerCode = Get-Content - Path " $PSScriptRoot \functionTimer\run.ps1" | Join-String " `n "
45+ $timerConfig = Get-Content - Path " $PSScriptRoot \functionTimer\function.json" | Join-String " `n "
46+ foreach ($command in Get-ChildItem - Path " $workingDirectory \þnameþ\functions\timerTrigger" - Recurse - File - Filter * .ps1) {
47+ $schedule = $config.TimerTrigger.Schedule
48+ if ($config.TimerTrigger.ScheduleOverride .$ ($command.BaseName )) {
49+ $schedule = $config.TimerTrigger.ScheduleOverride .$ ($command.BaseName )
50+ }
51+ $endpointFolder = New-Item - Path $buildFolder.FullName - Name $command.BaseName - ItemType Directory
52+ $timerCode -replace ' %COMMAND%' , $command.BaseName | Set-Content - Path " $ ( $endpointFolder.FullName ) \run.ps1"
53+ $timerConfig -replace ' %SCHEDULE%' , $schedule | Set-Content - Path " $ ( $endpointFolder.FullName ) \function.json"
54+ }
2055
2156# Package & Cleanup
57+ Remove-Item - Path " $workingDirectory /Function.zip" - Recurse - Force - ErrorAction Ignore
2258Compress-Archive - Path " $ ( $buildFolder.FullName ) /*" - DestinationPath " $workingDirectory /Function.zip"
23- Remove-Item - Path $buildFolder.FullName - Recurse - Force - ErrorAction Ignore
59+ Remove-Item - Path $buildFolder.FullName - Recurse - Force - ErrorAction Ignore
60+
61+ if ($AppRg -and $AppName ) {
62+ Write-Host " Publishing Function App to $AppRg /$AppName "
63+ Publish-AzWebApp - ResourceGroupName $AppRG - Name $AppName - ArchivePath " $workingDirectory /Function.zip" - Confirm:$false - Force
64+ }
0 commit comments