|
| 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 | +} |
0 commit comments