Skip to content

Commit

Permalink
2023-11-16 22:43:39
Browse files Browse the repository at this point in the history
  • Loading branch information
uidHUB committed Nov 16, 2023
1 parent 7a8b0c9 commit 0a2462e
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 134 deletions.
5 changes: 1 addition & 4 deletions PkgStore.Kernel.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@
GUID = '58655ac6-8750-4397-a15f-29f9e18e257d'
Author = 'Kitsune Solar'
CompanyName = 'iHub.TO'
Copyright = '(c) 2023 Kitsune Solar. All rights reserved.'
Copyright = '(c) 2023 Library Online. All rights reserved.'
Description = 'A kernel for PowerShell modules from Package Store.'
PowerShellVersion = '7.2'
FunctionsToExport = @(
'Write-Msg', 'Test-Module', 'Test-Data', 'New-Data', 'Copy-Data', 'Move-Data', 'Remove-Data'
)
PrivateData = @{
PSData = @{
Tags = @('pwsh', 'kernel')
Expand Down
147 changes: 17 additions & 130 deletions PkgStore.Kernel.psm1
Original file line number Diff line number Diff line change
@@ -1,136 +1,23 @@
<#PSScriptInfo
.VERSION 0.1.0
.GUID 58655ac6-8750-4397-a15f-29f9e18e257d
.AUTHOR Kitsune Solar
.AUTHOREMAIL [email protected]
.COMPANYNAME iHub.TO
.COPYRIGHT 2023 Kitsune Solar. All rights reserved.
.LICENSEURI https://github.com/pkgstore/pwsh-kernel/blob/main/LICENSE
.PROJECTURI
#>

function Write-Msg() {
<#
.SYNOPSIS
.DESCRIPTION
#>

param (
[Alias('T')][string]$Type,
[Alias('M')][string]$Message,
[Alias('A')][string]$Action = 'Continue'
)

switch ($Type) {
'HL' { Write-Host "${NL}--- ${Message}".ToUpper() -ForegroundColor Blue }
'I' { Write-Information -MessageData "${Message}" -InformationAction "${Action}" }
'W' { Write-Warning -Message "${Message}" -WarningAction "${Action}" }
'E' { Write-Error -Message "${Message}" -ErrorAction "${Action}" }
default { Write-Host "${Message}" }
}
}

function Test-Module() {
<#
.SYNOPSIS
.DESCRIPTION
#>

Param(
[Parameter(Mandatory)][Alias('N')][string[]]$Names
)

$Names | ForEach-Object {
if (-not (Get-Module -ListAvailable -Name "${_}")) {
Write-Error -Message "Module '${_}' not installed!" -ErrorAction 'Stop'
}
$Aliases = @()
$PrivateFunctions = (Get-ChildItem -Path (Join-Path $PSScriptRoot 'Private') -Include '*.ps1' -File -Recurse)
$PublicFunctions = (Get-ChildItem -Path (Join-Path $PSScriptRoot 'Public') -Include '*.ps1' -File -Recurse)

(@($PrivateFunctions) + @($PublicFunctions)) | ForEach-Object {
try {
Write-Verbose "Loading '$($_.FullName)'."
. $_.FullName
} catch {
Write-Warning $_.Exception.Message
}
}

function Test-Data() {
<#
.SYNOPSIS
.DESCRIPTION
#>

param (
[Alias('T')][string]$Type,
[Alias('P')][string]$Path
)
@($PublicFunctions) | ForEach-Object {
$Alias = (Get-Alias -Definition $_.BaseName -ErrorAction 'SilentlyContinue')

switch ($Type) {
'D' { $Type = 'Container' }
'F' { $Type = 'Leaf' }
if ($Alias) {
$Aliases += $Alias
Export-ModuleMember -Function $_.BaseName -Alias $Alias
} else {
Export-ModuleMember -Function $_.BaseName
}

Test-Path -LiteralPath "${Path}" -PathType "${Type}"
}

function New-Data() {
<#
.SYNOPSIS
.DESCRIPTION
#>

param (
[Alias('T')][string]$Type,
[Alias('P')][string]$Path,
[Alias('N')][string]$Name,
[Alias('A')][string]$Action = 'SilentlyContinue'
)

switch ($Type) {
'D' { $Type = 'Directory' }
'F' { $Type = 'File' }
}

New-Item -Path "${Path}" -Name "${Name}" -ItemType "${Type}" -ErrorAction "${Action}"
}

function Copy-Data() {
<#
.SYNOPSIS
.DESCRIPTION
#>

param (
[Alias('S')][string]$Src,
[Alias('D')][string]$Dst
)

Copy-Item -LiteralPath "${Src}" -Destination "${Dst}" -Force
}

function Move-Data() {
<#
.SYNOPSIS
.DESCRIPTION
#>

param (
[Alias('S')][string]$Src,
[Alias('D')][string]$Dst
)

Move-Item -LiteralPath "${Src}" -Destination "${Dst}" -Force
}

function Remove-Data() {
<#
.SYNOPSIS
.DESCRIPTION
#>

param (
[Alias('P')][string]$Path
)

Remove-Item -LiteralPath "${Path}" -Force
}
14 changes: 14 additions & 0 deletions Public/Copy-Data.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function Copy-Data() {
<#
.SYNOPSIS
.DESCRIPTION
#>

param (
[Alias('S')][string]$Src,
[Alias('D')][string]$Dst
)

Copy-Item -LiteralPath "${Src}" -Destination "${Dst}" -Force
}
14 changes: 14 additions & 0 deletions Public/Move-Data.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function Move-Data() {
<#
.SYNOPSIS
.DESCRIPTION
#>

param (
[Alias('S')][string]$Src,
[Alias('D')][string]$Dst
)

Move-Item -LiteralPath "${Src}" -Destination "${Dst}" -Force
}
21 changes: 21 additions & 0 deletions Public/New-Data.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
function New-Data() {
<#
.SYNOPSIS
.DESCRIPTION
#>

param (
[Alias('T')][string]$Type,
[Alias('P')][string]$Path,
[Alias('N')][string]$Name,
[Alias('A')][string]$Action = 'SilentlyContinue'
)

switch ($Type) {
'D' { $Type = 'Directory' }
'F' { $Type = 'File' }
}

New-Item -Path "${Path}" -Name "${Name}" -ItemType "${Type}" -ErrorAction "${Action}"
}
13 changes: 13 additions & 0 deletions Public/Remove-Data.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function Remove-Data() {
<#
.SYNOPSIS
.DESCRIPTION
#>

param (
[Alias('P')][string]$Path
)

Remove-Item -LiteralPath "${Path}" -Force
}
19 changes: 19 additions & 0 deletions Public/Test-Data.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
function Test-Data() {
<#
.SYNOPSIS
.DESCRIPTION
#>

param (
[Alias('T')][string]$Type,
[Alias('P')][string]$Path
)

switch ($Type) {
'D' { $Type = 'Container' }
'F' { $Type = 'Leaf' }
}

Test-Path -LiteralPath "${Path}" -PathType "${Type}"
}
17 changes: 17 additions & 0 deletions Public/Test-Module.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function Test-Module() {
<#
.SYNOPSIS
.DESCRIPTION
#>

Param(
[Parameter(Mandatory)][Alias('N')][string[]]$Names
)

$Names | ForEach-Object {
if (-not (Get-Module -ListAvailable -Name "${_}")) {
Write-Error -Message "Module '${_}' not installed!" -ErrorAction 'Stop'
}
}
}
21 changes: 21 additions & 0 deletions Public/Write-Msg.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
function Write-Msg() {
<#
.SYNOPSIS
.DESCRIPTION
#>

param (
[Alias('T')][string]$Type,
[Alias('M')][string]$Message,
[Alias('A')][string]$Action = 'Continue'
)

switch ($Type) {
'HL' { Write-Host "${NL}--- ${Message}".ToUpper() -ForegroundColor Blue }
'I' { Write-Information -MessageData "${Message}" -InformationAction "${Action}" }
'W' { Write-Warning -Message "${Message}" -WarningAction "${Action}" }
'E' { Write-Error -Message "${Message}" -ErrorAction "${Action}" }
default { Write-Host "${Message}" }
}
}

0 comments on commit 0a2462e

Please sign in to comment.