PowerShellProTools.psm1
function Invoke-Package { param([Microsoft.PowerShell.EditorServices.Extensions.EditorContext]$context) $outputPath = Split-Path -Path $context.CurrentFile.Path -Parent $outputPath = (Join-Path -Path $outputPath -ChildPath "Output").ToString() Merge-Script -Config @{ Root = $context.CurrentFile.Path OutputPath = $outputPath Package = @{ Enabled = $true Obfuscate = $true } Bundle = @{ Enabled = $true Modules = $true NestedModules = $true RequiredAssemblies = $true } } -Verbose } function Invoke-Bundle { param([Microsoft.PowerShell.EditorServices.Extensions.EditorContext]$context) $outputPath = Split-Path -Path $context.CurrentFile.Path -Parent $outputPath = (Join-Path -Path $outputPath -ChildPath "Output").ToString() Merge-Script -Config @{ Root = $context.CurrentFile.Path OutputPath = $outputPath Bundle = @{ Enabled = $true Modules = $true NestedModules = $true RequiredAssemblies = $true } } -Verbose } function Invoke-ConvertToPowerShell { param([Microsoft.PowerShell.EditorServices.Extensions.EditorContext]$context) $text = $context.CurrentFile.GetText() $code = ConvertTo-PowerShell -CSharpCode $text $code | Out-File $context.CurrentFile.Path } function Invoke-ConvertToCSharp { param([Microsoft.PowerShell.EditorServices.Extensions.EditorContext]$context) $text = $context.CurrentFile.GetText() $code = ConvertTo-CSharp -PowerShellScript $text $code | Out-File $context.CurrentFile.Path } function New-VsCodeCommands { Register-EditorCommand ` -Name "PowerShellProTools.PackageScriptAsExe" ` -DisplayName "Package script as executable" ` -Function Invoke-Package Register-EditorCommand ` -Name "PowerShellProTools.BundleScript" ` -DisplayName "Bundle script" ` -Function Invoke-Bundle Register-EditorCommand ` -Name "PowerShellProTools.ConvertToPowerShell" ` -DisplayName "Convert to PowerShell" ` -Function Invoke-ConvertToPowerShell Register-EditorCommand ` -Name "PowerShellProTools.ConvertToCSharp" ` -DisplayName "Convert to C#" ` -Function Invoke-ConvertToCSharp } if ($host.Name -eq 'Visual Studio Code Host'){ New-VsCodeCommands } |