Skip to content

Commit a64c2e5

Browse files
authored
Added -PassThru Parameter for Compress-PSResource (#1702)
1 parent bf99f3a commit a64c2e5

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

src/code/CompressPSResource.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,13 @@ public sealed class CompressPSResource : PSCmdlet
3636
public string DestinationPath { get; set; }
3737

3838
/// <summary>
39-
/// Bypasses validating a resource module manifest before publishing.
39+
/// When specified, passes the full path of the nupkg through the pipeline.
40+
/// </summary>
41+
[Parameter(Mandatory = false, HelpMessage = "Pass the full path of the nupkg through the pipeline")]
42+
public SwitchParameter PassThru { get; set; }
43+
44+
/// <summary>
45+
/// Bypasses validating a resource module manifest before compressing.
4046
/// </summary>
4147
[Parameter]
4248
public SwitchParameter SkipModuleManifestValidate { get; set; }
@@ -61,6 +67,7 @@ protected override void BeginProcessing()
6167
this,
6268
Path,
6369
DestinationPath,
70+
PassThru,
6471
SkipModuleManifestValidate);
6572

6673
_publishHelper.CheckAllParameterPaths();

src/code/PublishHelper.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,20 @@ internal enum CallerCmdlet
6161
private string outputDir = string.Empty;
6262
internal bool ScriptError = false;
6363
internal bool ShouldProcess = true;
64+
internal bool PassThru = false;
6465

6566
#endregion
6667

6768
#region Constructors
6869

69-
internal PublishHelper(PSCmdlet cmdlet, string path, string destinationPath, bool skipModuleManifestValidate)
70+
internal PublishHelper(PSCmdlet cmdlet, string path, string destinationPath, bool passThru, bool skipModuleManifestValidate)
7071
{
7172
_callerCmdlet = CallerCmdlet.CompressPSResource;
7273
_cmdOperation = "Compress";
7374
_cmdletPassedIn = cmdlet;
7475
Path = path;
7576
DestinationPath = destinationPath;
77+
PassThru = passThru;
7678
SkipModuleManifestValidate = skipModuleManifestValidate;
7779
outputDir = System.IO.Path.Combine(System.IO.Path.GetTempPath(), Guid.NewGuid().ToString());
7880
outputNupkgDir = destinationPath;
@@ -562,6 +564,10 @@ private bool PackNupkg(string outputDir, string outputNupkgDir, string nuspecFil
562564

563565
if (success)
564566
{
567+
if (PassThru)
568+
{
569+
_cmdletPassedIn.WriteObject(System.IO.Path.Combine(outputNupkgDir, _pkgName + "." + _pkgVersion.ToNormalizedString() + ".nupkg"));
570+
}
565571
_cmdletPassedIn.WriteVerbose("Successfully packed the resource into a .nupkg");
566572
}
567573
else

test/PublishPSResourceTests/CompressPSResource.Tests.ps1

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,17 @@ Describe "Test Compress-PSResource" -tags 'CI' {
153153

154154
Test-Path -Path (Join-Path -Path $unzippedPath -ChildPath $testFile) | Should -Be $True
155155
}
156+
157+
It "Compress-PSResource -PassThru returns the path to the nupkg" {
158+
$version = "1.0.0"
159+
New-ModuleManifest -Path (Join-Path -Path $script:PublishModuleBase -ChildPath "$script:PublishModuleName.psd1") -ModuleVersion $version -Description "$script:PublishModuleName module"
160+
161+
$nupkgPath = Compress-PSResource -Path $script:PublishModuleBase -DestinationPath $script:repositoryPath -PassThru
162+
163+
$expectedPath = Join-Path -Path $script:repositoryPath -ChildPath "$script:PublishModuleName.$version.nupkg"
164+
$nupkgPath | Should -Be $expectedPath
165+
}
166+
156167
<# Test for Signing the nupkg. Signing doesn't work
157168
It "Compressed Module is able to be signed with a certificate" {
158169
$version = "1.0.0"

0 commit comments

Comments
 (0)