Skip to content

Commit e9e8ecb

Browse files
authored
Publish-PSResource: Pack and Push Feature (#1682)
1 parent a2df53a commit e9e8ecb

File tree

9 files changed

+1521
-1049
lines changed

9 files changed

+1521
-1049
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@ srcOld/code/obj
55
out
66
test/**/obj
77
test/**/bin
8+
.vs
9+
.vscode
10+
src/code/.vs
11+
test/testFiles/testScripts/test.ps1

src/Microsoft.PowerShell.PSResourceGet.psd1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
CLRVersion = '4.0.0'
1717
FormatsToProcess = 'PSGet.Format.ps1xml'
1818
CmdletsToExport = @(
19+
'Compress-PSResource',
1920
'Find-PSResource',
2021
'Get-InstalledPSResource',
2122
'Get-PSResourceRepository',
Binary file not shown.

src/code/CompressPSResource.cs

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using Microsoft.PowerShell.PSResourceGet.UtilClasses;
5+
using System.IO;
6+
using System.Linq;
7+
using System.Management.Automation;
8+
9+
namespace Microsoft.PowerShell.PSResourceGet.Cmdlets
10+
{
11+
/// <summary>
12+
/// Compresses a module, script, or nupkg to a designated repository.
13+
/// </summary>
14+
[Cmdlet(VerbsData.Compress,
15+
"PSResource",
16+
SupportsShouldProcess = true)]
17+
[Alias("cmres")]
18+
public sealed class CompressPSResource : PSCmdlet
19+
{
20+
#region Parameters
21+
22+
/// <summary>
23+
/// Specifies the path to the resource that you want to compress. This parameter accepts the path to the folder that contains the resource.
24+
/// Specifies a path to one or more locations. Wildcards are permitted. The default location is the current directory (.).
25+
/// </summary>
26+
[Parameter(Mandatory = true, Position = 0, HelpMessage = "Path to the resource to be compressed.")]
27+
[ValidateNotNullOrEmpty]
28+
public string Path { get; set; }
29+
30+
/// <summary>
31+
/// Specifies the path where the compressed resource (as a .nupkg file) should be saved.
32+
/// This parameter allows you to save the package to a specified location on the local file system.
33+
/// </summary>
34+
[Parameter(Mandatory = true, Position = 1, HelpMessage = "Path to save the compressed resource.")]
35+
[ValidateNotNullOrEmpty]
36+
public string DestinationPath { get; set; }
37+
38+
/// <summary>
39+
/// Bypasses validating a resource module manifest before publishing.
40+
/// </summary>
41+
[Parameter]
42+
public SwitchParameter SkipModuleManifestValidate { get; set; }
43+
44+
#endregion
45+
46+
#region Members
47+
48+
private PublishHelper _publishHelper;
49+
50+
#endregion
51+
52+
#region Method Overrides
53+
54+
protected override void BeginProcessing()
55+
{
56+
// Create a respository store (the PSResourceRepository.xml file) if it does not already exist
57+
// This is to create a better experience for those who have just installed v3 and want to get up and running quickly
58+
RepositorySettings.CheckRepositoryStore();
59+
60+
_publishHelper = new PublishHelper(
61+
this,
62+
Path,
63+
DestinationPath,
64+
SkipModuleManifestValidate);
65+
66+
_publishHelper.CheckAllParameterPaths();
67+
}
68+
69+
protected override void EndProcessing()
70+
{
71+
_publishHelper.PackResource();
72+
}
73+
74+
#endregion
75+
76+
}
77+
}

src/code/PSResourceInfo.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ public enum ResourceType
2121
{
2222
None,
2323
Module,
24-
Script
24+
Script,
25+
Nupkg
2526
}
2627

2728
public enum VersionType

0 commit comments

Comments
 (0)