-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpackage-dotnet.ps1
More file actions
37 lines (35 loc) · 1.95 KB
/
Copy pathpackage-dotnet.ps1
File metadata and controls
37 lines (35 loc) · 1.95 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
#Requires -Version 7.0
[CmdletBinding()]
param(
[string]$OutputPath = (Join-Path $PSScriptRoot 'artifacts/epp-dotnet-source.zip')
)
$ErrorActionPreference = 'Stop'
$source = Join-Path $PSScriptRoot 'dotnet'
$archive = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($OutputPath)
if (Test-Path -LiteralPath $archive) { throw "Output already exists: $archive. Choose another -OutputPath." }
$temporary = Join-Path ([IO.Path]::GetTempPath()) ('epp-dotnet-' + [guid]::NewGuid().ToString('N'))
$stage = Join-Path $temporary 'app'
try {
New-Item -ItemType Directory -Path $stage -Force | Out-Null
foreach ($name in @('host.json', 'dotnet.csproj', 'Program.cs')) {
Copy-Item -LiteralPath (Join-Path $source $name) -Destination $stage
}
foreach ($folder in @('Functions', 'Src')) {
foreach ($file in Get-ChildItem -LiteralPath (Join-Path $source $folder) -Recurse -File -Filter '*.cs') {
$relative = [IO.Path]::GetRelativePath($source, $file.FullName)
if ($relative -match '(^|[\\/])(tests?|bin|obj)([\\/]|$)') { continue }
$destination = Join-Path $stage $relative
New-Item -ItemType Directory -Path (Split-Path $destination) -Force | Out-Null
Copy-Item -LiteralPath $file.FullName -Destination $destination
}
}
if (-not (Test-Path -LiteralPath (Join-Path $stage 'Functions/SendOtp.cs'))) { throw 'Missing .NET function source.' }
$zip = Join-Path $temporary 'app.zip'
[IO.Compression.ZipFile]::CreateFromDirectory($stage, $zip)
New-Item -ItemType Directory -Path (Split-Path $archive) -Force | Out-Null
[IO.File]::Move($zip, $archive)
Write-Host '.NET source ZIP created. Build/publish the extracted project before deployment; not ready for direct run-from-package.'
Get-Item -LiteralPath $archive | Select-Object FullName, Length
} finally {
if (Test-Path -LiteralPath $temporary) { Remove-Item -LiteralPath $temporary -Recurse -Force }
}