Skip to content

Commit 86d5fba

Browse files
author
James Brundage
committed
feat: WebSocket module scaffolding ( Fixes #1 )
1 parent d41bf53 commit 86d5fba

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

Diff for: WebSocket.psd1

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
@{
2+
ModuleVersion = '0.1'
3+
RootModule = 'WebSocket.psm1'
4+
Guid = '75c70c8b-e5eb-4a60-982e-a19110a1185d'
5+
Author = 'James Brundage'
6+
CompanyName = 'StartAutomating'
7+
Copyright = '2024 StartAutomating'
8+
Description = 'Work with WebSockets in PowerShell'
9+
PrivateData = @{
10+
PSData = @{
11+
Tags = @('WebSocket', 'WebSockets', 'Networking', 'Web')
12+
ProjectURI = 'https://github.com/PowerShellWeb/WebSocket'
13+
LicenseURI = 'https://github.com/PowerShellWeb/WebSocket/blob/main/LICENSE'
14+
}
15+
}
16+
}

Diff for: WebSocket.psm1

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
$commandsPath = Join-Path $PSScriptRoot Commands
2+
:ToIncludeFiles foreach ($file in (Get-ChildItem -Path "$commandsPath" -Filter "*-*" -Recurse)) {
3+
if ($file.Extension -ne '.ps1') { continue } # Skip if the extension is not .ps1
4+
foreach ($exclusion in '\.[^\.]+\.ps1$') {
5+
if (-not $exclusion) { continue }
6+
if ($file.Name -match $exclusion) {
7+
continue ToIncludeFiles # Skip excluded files
8+
}
9+
}
10+
. $file.FullName
11+
}
12+
13+
$myModule = $MyInvocation.MyCommand.ScriptBlock.Module
14+
$ExecutionContext.SessionState.PSVariable.Set($myModule.Name, $myModule)
15+
$myModule.pstypenames.insert(0, $myModule.Name)
16+
17+
New-PSDrive -Name $MyModule.Name -PSProvider FileSystem -Scope Global -Root $PSScriptRoot -ErrorAction Ignore
18+
19+
if ($home) {
20+
$MyModuleProfileDirectory = Join-Path ([Environment]::GetFolderPath("LocalApplicationData")) $MyModule.Name
21+
if (-not (Test-Path $MyModuleProfileDirectory)) {
22+
$null = New-Item -ItemType Directory -Path $MyModuleProfileDirectory -Force
23+
}
24+
New-PSDrive -Name "My$($MyModule.Name)" -PSProvider FileSystem -Scope Global -Root $MyModuleProfileDirectory -ErrorAction Ignore
25+
}
26+
27+
# Set a script variable of this, set to the module
28+
# (so all scripts in this scope default to the correct `$this`)
29+
$script:this = $myModule
30+
31+
#region Custom
32+
#endregion Custom
33+
34+
Export-ModuleMember -Alias * -Function * -Variable $myModule.Name
35+
36+

0 commit comments

Comments
 (0)