1
1
[CmdletBinding ()]
2
2
param (
3
3
[Parameter (Mandatory = $true )]
4
- [string ]$IndividualZipStagingPath ,
4
+ [string ]$SourceRoot ,
5
5
6
6
[Parameter (Mandatory = $true )]
7
- [string ]$WrapperZipStagingPath ,
7
+ [string ]$TargetPath ,
8
8
9
- [Parameter (Mandatory = $true )]
10
- [string ]$ZipPath )
9
+ [switch ]$Individually )
11
10
12
11
$ErrorActionPreference = ' Stop'
13
12
Add-Type - Assembly ' System.IO.Compression.FileSystem'
14
- Get-ChildItem - LiteralPath $IndividualZipStagingPath |
15
- ForEach-Object {
16
- $sourceDir = $_.FullName
17
- $targetDir = [System.IO.Path ]::Combine($WrapperZipStagingPath , $_.Name )
18
- Write-Host " Compressing $ ( $_.Name ) "
19
- [System.IO.Compression.ZipFile ]::CreateFromDirectory($sourceDir , " $targetDir \task.zip" )
13
+ if ($Individually ) {
14
+ # Create the target root directory.
15
+ if (! (Test-Path - LiteralPath $TargetPath - PathType Container)) {
16
+ $null = New-Item - Path $TargetPath - ItemType Directory
17
+ }
18
+
19
+ # Create each task zip.
20
+ Get-ChildItem - LiteralPath $SourceRoot |
21
+ ForEach-Object {
22
+ $sourceDir = $_.FullName
23
+ $targetDir = [System.IO.Path ]::Combine($TargetPath , $_.Name )
24
+ Write-Host " Compressing $ ( $_.Name ) "
25
+ $null = New-Item - Path $targetDir - ItemType Directory
26
+ [System.IO.Compression.ZipFile ]::CreateFromDirectory($sourceDir , " $targetDir \task.zip" )
27
+ }
28
+ } else {
29
+ # Create the target directory.
30
+ $targetDir = [System.IO.Path ]::GetDirectoryName($TargetPath )
31
+ if (! (Test-Path - LiteralPath $targetDir - PathType Container)) {
32
+ $null = New-Item - Path $targetDir - ItemType Directory
20
33
}
21
34
22
- Write-Host " Creating $ ( [ System.IO.Path ]::GetFileName( $ZipPath ) ) "
23
- $null = New-Item - Path ( [System.IO.Path ]::GetDirectoryName( $ZipPath )) - ItemType Directory
24
- [ System.IO.Compression.ZipFile ]::CreateFromDirectory( $WrapperZipStagingPath , $ZipPath )
35
+ # Create the zip.
36
+ [System.IO.Compression.ZipFile ]::CreateFromDirectory( $SourceRoot , $TargetPath )
37
+ }
0 commit comments