-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
1,255 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<# | ||
.SYNOPSIS | ||
Converts an absolute path to a relative path. | ||
.DESCRIPTION | ||
The ConvertTo-RelativePath command takes an absolute path and converts it | ||
to a relative path based on the current location. If the absolute path | ||
starts with the current location, the function removes the current location | ||
from the beginning of the path and inserts a '.' to indicate the relative path. | ||
.PARAMETER AbsolutePath | ||
Specifies the absolute path that needs to be converted to a relative path. | ||
.PARAMETER CurrentLocation | ||
Specifies the current location used as a reference for converting the absolute | ||
path to a relative path. If not specified, the function uses the current | ||
location obtained from Get-Location. | ||
.EXAMPLE | ||
ConvertTo-RelativePath -AbsolutePath '/source/Viscalyx.Common/source/Public/ConvertTo-RelativePath.ps1' -CurrentLocation "/source/Viscalyx.Common" | ||
Returns "./source/Public/ConvertTo-RelativePath.ps1", which is the | ||
relative path of the given absolute path based on the current location. | ||
.INPUTS | ||
[System.String] | ||
.OUTPUTS | ||
[System.String] | ||
#> | ||
function ConvertTo-RelativePath | ||
{ | ||
[CmdletBinding()] | ||
[OutputType([System.String])] | ||
param | ||
( | ||
[Parameter(Mandatory = $true, ValueFromPipeline = $true, Position = 0)] | ||
[System.String] | ||
$AbsolutePath, | ||
|
||
[Parameter(Position = 1)] | ||
[System.String] | ||
$CurrentLocation | ||
) | ||
|
||
begin | ||
{ | ||
if (-not $PSBoundParameters.ContainsKey('CurrentLocation')) | ||
{ | ||
$CurrentLocation = (Get-Location).Path | ||
} | ||
} | ||
|
||
process | ||
{ | ||
$relativePath = $AbsolutePath | ||
|
||
if ($relativePath.StartsWith($CurrentLocation)) | ||
{ | ||
$relativePath = $relativePath.Substring($CurrentLocation.Length).Insert(0, '.') | ||
} | ||
|
||
return $relativePath | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<# | ||
.SYNOPSIS | ||
Retrieves the version of a PowerShell module. | ||
.DESCRIPTION | ||
The Get-ModuleVersion command retrieves the version of a PowerShell module. | ||
It accepts a module name or a PSModuleInfo object as input and returns the | ||
module version as a string. | ||
.PARAMETER Module | ||
Specifies the module for which to retrieve the version. This can be either | ||
a module name or a PSModuleInfo object. | ||
.EXAMPLE | ||
Get-ModuleVersion -Module 'MyModule' | ||
Retrieves the version of the module named "MyModule". | ||
.EXAMPLE | ||
$moduleInfo = Get-Module -Name 'MyModule' | ||
Get-ModuleVersion -Module $moduleInfo | ||
Retrieves the version of the module specified by the PSModuleInfo object $moduleInfo. | ||
.INPUTS | ||
[System.Object] | ||
Accepts a module name or a PSModuleInfo object as input. | ||
.OUTPUTS | ||
[System.String] | ||
Returns the module version as a string. | ||
#> | ||
function Get-ModuleVersion | ||
{ | ||
[CmdletBinding()] | ||
param | ||
( | ||
[Parameter(Mandatory = $true, ValueFromPipeline = $true, Position = 0)] | ||
[System.Object] | ||
$Module | ||
) | ||
|
||
process | ||
{ | ||
$moduleInfo = $null | ||
$moduleVersion = $null | ||
|
||
if ($Module -is [System.String]) | ||
{ | ||
$moduleInfo = Get-Module -Name $Module -ErrorAction 'Stop' | ||
|
||
if (-not $moduleInfo) | ||
{ | ||
Write-Error -Message "Cannot find the module '$Module'. Make sure it is loaded into the session." | ||
} | ||
} | ||
elseif ($Module -is [System.Management.Automation.PSModuleInfo]) | ||
{ | ||
$moduleInfo = $Module | ||
} | ||
else | ||
{ | ||
Write-Error -Message "Invalid parameter type. The parameter 'Module' must be either a string or a PSModuleInfo object." | ||
} | ||
|
||
if ($moduleInfo) | ||
{ | ||
$moduleVersion = $moduleInfo.Version.ToString() | ||
|
||
$previewReleaseTag = $moduleInfo.PrivateData.PSData.Prerelease | ||
|
||
if ($previewReleaseTag) | ||
{ | ||
$moduleVersion += '-{0}' -f $previewReleaseTag | ||
} | ||
} | ||
|
||
return $moduleVersion | ||
} | ||
} |
Oops, something went wrong.