Skip to content

Commit

Permalink
Publish-PSResource: Pack and Push Feature (#1682)
Browse files Browse the repository at this point in the history
  • Loading branch information
jshigetomi authored Aug 23, 2024
1 parent a2df53a commit e9e8ecb
Show file tree
Hide file tree
Showing 9 changed files with 1,521 additions and 1,049 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ srcOld/code/obj
out
test/**/obj
test/**/bin
.vs
.vscode
src/code/.vs
test/testFiles/testScripts/test.ps1
1 change: 1 addition & 0 deletions src/Microsoft.PowerShell.PSResourceGet.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
CLRVersion = '4.0.0'
FormatsToProcess = 'PSGet.Format.ps1xml'
CmdletsToExport = @(
'Compress-PSResource',
'Find-PSResource',
'Get-InstalledPSResource',
'Get-PSResourceRepository',
Expand Down
Binary file modified src/code/.vs/Microsoft.PowerShell.PSResourceGet/v17/.suo
Binary file not shown.
77 changes: 77 additions & 0 deletions src/code/CompressPSResource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Microsoft.PowerShell.PSResourceGet.UtilClasses;
using System.IO;
using System.Linq;
using System.Management.Automation;

namespace Microsoft.PowerShell.PSResourceGet.Cmdlets
{
/// <summary>
/// Compresses a module, script, or nupkg to a designated repository.
/// </summary>
[Cmdlet(VerbsData.Compress,
"PSResource",
SupportsShouldProcess = true)]
[Alias("cmres")]
public sealed class CompressPSResource : PSCmdlet
{
#region Parameters

/// <summary>
/// Specifies the path to the resource that you want to compress. This parameter accepts the path to the folder that contains the resource.
/// Specifies a path to one or more locations. Wildcards are permitted. The default location is the current directory (.).
/// </summary>
[Parameter(Mandatory = true, Position = 0, HelpMessage = "Path to the resource to be compressed.")]
[ValidateNotNullOrEmpty]
public string Path { get; set; }

/// <summary>
/// Specifies the path where the compressed resource (as a .nupkg file) should be saved.
/// This parameter allows you to save the package to a specified location on the local file system.
/// </summary>
[Parameter(Mandatory = true, Position = 1, HelpMessage = "Path to save the compressed resource.")]
[ValidateNotNullOrEmpty]
public string DestinationPath { get; set; }

/// <summary>
/// Bypasses validating a resource module manifest before publishing.
/// </summary>
[Parameter]
public SwitchParameter SkipModuleManifestValidate { get; set; }

#endregion

#region Members

private PublishHelper _publishHelper;

#endregion

#region Method Overrides

protected override void BeginProcessing()
{
// Create a respository store (the PSResourceRepository.xml file) if it does not already exist
// This is to create a better experience for those who have just installed v3 and want to get up and running quickly
RepositorySettings.CheckRepositoryStore();

_publishHelper = new PublishHelper(
this,
Path,
DestinationPath,
SkipModuleManifestValidate);

_publishHelper.CheckAllParameterPaths();
}

protected override void EndProcessing()
{
_publishHelper.PackResource();
}

#endregion

}
}
3 changes: 2 additions & 1 deletion src/code/PSResourceInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public enum ResourceType
{
None,
Module,
Script
Script,
Nupkg
}

public enum VersionType
Expand Down
Loading

0 comments on commit e9e8ecb

Please sign in to comment.