Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
bae1ed4
Updating Explicit Transpiler: Returning modified [ScriptBlock] (#102)
Jul 2, 2022
fedc977
Updating Explicit Transpiler: Returning modified [ScriptBlock] (#102)
Jul 2, 2022
288a04b
Adding ModuleExports.psx.ps1 (#104)
Jul 3, 2022
ef53765
Updating PipeScript.ps1.psm1 to use ModuleExports (#104)
Jul 3, 2022
765779e
Merge branch 'PipeScriptFunAndFixes' of https://github.com/StartAutom…
Jul 3, 2022
182c73f
Merge branch 'PipeScriptFunAndFixes' of https://github.com/StartAutom…
Jul 3, 2022
791d051
Updating PipeScript.ps1.psm1 (alignment of ModuleExports) (#104)
Jul 3, 2022
eb3ae51
Updating PipeScript.ps1.psm1 (alignment of ModuleExports) (#104)
Jul 3, 2022
9c0f957
Updating [include] transpiler (avoiding unrelated files) (#96)
Jul 3, 2022
e9e62ec
Adding Aliases Transpiler (#106)
Jul 3, 2022
865b539
Adding ModuleRelationship Transpiler (#105)
Jul 3, 2022
27099cb
Updating PipeScript module source (using #105, #106)
Jul 3, 2022
8e7af5a
Updating PipeScript module source (using #105, #106)
Jul 3, 2022
fc7ce42
Updating PipeScript module source (using #105, #106)
Jul 3, 2022
4230b66
Updating PipeScript module source (typofix) (using #105, #106)
Jul 3, 2022
da99d40
Updating PipeScript module source (typofix) (using #105, #106)
Jul 3, 2022
fe28761
Adding support for Dotting (#107)
Jul 4, 2022
8473ad1
Merge branch 'PipeScriptFunAndFixes' of https://github.com/StartAutom…
Jul 4, 2022
0ec1153
Merge branch 'PipeScriptFunAndFixes' of https://github.com/StartAutom…
Jul 4, 2022
22d829e
More Dotting Examples (#107)
Jul 4, 2022
66844b2
More Dotting Examples (#107)
Jul 4, 2022
2d4801b
Updating Module Version [0.0.7] and CHANGELOG
Jul 4, 2022
6a670aa
Merge branch 'main' into PipeScriptFunAndFixes
StartAutomating Jul 4, 2022
76ecbe7
Merge branch 'main' into PipeScriptFunAndFixes
Jul 4, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
## 0.0.7:
* Syntax Improvements:
* Support for Dot Notation (#107)
* New Transpilers:
* .>ModuleRelationships (#105)
* .>ModuleExports (#104)
* .>Aliases (#106)
* Fixes:
* Invoke-PipeScript improved error behavior (#103)
* Explicit Transpiler returns modified ScriptBlock (#102)
* .psm1 alias export fix (#100)
* Include improvements (#96)
---

## 0.0.6:
* New Transpilers:
* ValidateScriptBlock
Expand Down
23 changes: 9 additions & 14 deletions PipeScript.ps1.psm1
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
[Include('*-*')]$psScriptRoot

$aliasNames = @()
foreach ($transpilerCmd in Get-Transpiler) {
$aliasNames += ".>$($transpilerCmd.DisplayName)"
Set-Alias ".>$($transpilerCmd.DisplayName)" Use-PipeScript
$aliasNames += ".<$($transpilerCmd.DisplayName)>"
Set-Alias ".<$($transpilerCmd.DisplayName)>" Use-PipeScript
}
$transpilerNames = Get-Transpiler | Select-Object -ExpandProperty DisplayName
$aliasList +=
[SmartAlias(Command='Use-PipeScript',Prefix='.>',PassThru)]$transpilerNames

$aliasList +=
[SmartAlias(Command='Use-PipeScript',Prefix='.<',Suffix='>',PassThru)]$transpilerNames

$MyModule = $MyInvocation.MyCommand.ScriptBlock.Module
foreach ($cmd in $ExecutionContext.SessionState.InvokeCommand.GetCommands('*','Function', $true)) {
if ($cmd.ScriptBlock.Module -ne $MyModule) { continue }
if ($cmd.ScriptBlock.Attributes.AliasNames) {
$aliasNames += $cmd.ScriptBlock.Attributes.AliasNames
}
}
$aliasList +=
[GetExports("Alias")]$MyModule

Export-ModuleMember -Function * -Alias $aliasNames
Export-ModuleMember -Function * -Alias $aliasList
16 changes: 15 additions & 1 deletion PipeScript.psd1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@{
ModuleVersion = '0.0.6'
ModuleVersion = '0.0.7'
Description = 'An Extensible Transpiler for PowerShell (and anything else)'
RootModule = 'PipeScript.psm1'
PowerShellVersion = '4.0'
Expand All @@ -17,6 +17,20 @@

Tags = 'PipeScript','PowerShell', 'Transpilation', 'Compiler'
ReleaseNotes = @'
## 0.0.7:
* Syntax Improvements:
* Support for Dot Notation (#107)
* New Transpilers:
* .>ModuleRelationships (#105)
* .>ModuleExports (#104)
* .>Aliases (#106)
* Fixes:
* Invoke-PipeScript improved error behavior (#103)
* Explicit Transpiler returns modified ScriptBlock (#102)
* .psm1 alias export fix (#100)
* Include improvements (#96)
---

## 0.0.6:
* New Transpilers:
* ValidateScriptBlock
Expand Down
56 changes: 41 additions & 15 deletions PipeScript.psm1
Original file line number Diff line number Diff line change
@@ -1,23 +1,49 @@
foreach ($file in (Get-ChildItem -Path "$psScriptRoot" -Filter "*-*" -Recurse)) {
if ($file.Extension -ne '.ps1') { continue } # Skip if the extension is not .ps1
if ($file.Name -match '\.ps1\.ps1$') { continue } # Skip if the file is a source generator.
if ($file.Name -match '\.[^\.]\.ps1$') { continue } # Skip if the file is an unrelated file.
. $file.FullName
}

$aliasNames = @()
foreach ($transpilerCmd in Get-Transpiler) {
$aliasNames += ".>$($transpilerCmd.DisplayName)"
Set-Alias ".>$($transpilerCmd.DisplayName)" Use-PipeScript
$aliasNames += ".<$($transpilerCmd.DisplayName)>"
Set-Alias ".<$($transpilerCmd.DisplayName)>" Use-PipeScript
}
$transpilerNames = Get-Transpiler | Select-Object -ExpandProperty DisplayName
$aliasList +=

@(foreach ($alias in @($transpilerNames)) {
Set-Alias ".>$alias" "Use-PipeScript" -PassThru:$True
})


$aliasList +=

@(foreach ($alias in @($transpilerNames)) {
Set-Alias ".<$alias>" "Use-PipeScript" -PassThru:$True
})


$MyModule = $MyInvocation.MyCommand.ScriptBlock.Module
foreach ($cmd in $ExecutionContext.SessionState.InvokeCommand.GetCommands('*','Function', $true)) {
if ($cmd.ScriptBlock.Module -ne $MyModule) { continue }
if ($cmd.ScriptBlock.Attributes.AliasNames) {
$aliasNames += $cmd.ScriptBlock.Attributes.AliasNames
}
}
$aliasList +=

@(
if ($MyModule -isnot [Management.Automation.PSModuleInfo]) {
Write-Error "'$MyModule' must be a [Management.Automation.PSModuleInfo]"
} elseif ($MyModule.ExportedCommands.Count) {
foreach ($cmd in $MyModule.ExportedCommands.Values) {
if ($cmd.CommandType -in 'Alias') {
$cmd
}
}
} else {
foreach ($cmd in $ExecutionContext.SessionState.InvokeCommand.GetCommands('*', 'Function,Cmdlet', $true)) {
if ($cmd.Module -ne $MyModule) { continue }
if ('Alias' -contains 'Alias' -and $cmd.ScriptBlock.Attributes.AliasNames) {
foreach ($aliasName in $cmd.ScriptBlock.Attributes.AliasNames) {
$ExecutionContext.SessionState.InvokeCommand.GetCommand($aliasName, 'Alias')
}
}
if ('Alias' -contains $cmd.CommandType) {
$cmd
}
}
})


Export-ModuleMember -Function * -Alias $aliasNames
Export-ModuleMember -Function * -Alias $aliasList
3 changes: 2 additions & 1 deletion Transpilers/Explicit.psx.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ process {
$astReplacements[$pipeline] = [ScriptBlock]::Create("`$null = $pipeline")
}
}
$astReplacements

Update-PipeScript -ScriptBlock $ScriptBlock -AstReplacement $astReplacements
# @{AstReplacement=$astReplacements}
}
7 changes: 3 additions & 4 deletions Transpilers/Include.psx.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
} | .>PipeScript
.EXAMPLE
{
[Include('*-*.ps1')]$psScriptRoot
[Include('*-*.ps1')]$psScriptRoot
} | .>PipeScript
#>
param(
Expand Down Expand Up @@ -62,8 +62,7 @@ function IncludeFileContents {
"'@" + @'
-split "[\r\n]{1,2}" -replace "^@''", "@'" -replace "^''@", "'@" -join [Environment]::NewLine
'@
)

)
}
}
}
Expand Down Expand Up @@ -131,7 +130,7 @@ if ($psCmdlet.ParameterSetName -eq 'ScriptBlock' -or
[ScriptBlock]::Create(@"
foreach (`$file in (Get-ChildItem -Path "$($VariableAst)" -Filter "$FilePath" -Recurse)) {
if (`$file.Extension -ne '.ps1') { continue } # Skip if the extension is not .ps1
if (`$file.Name -match '\.ps1\.ps1$') { continue } # Skip if the file is a source generator.
if (`$file.Name -match '\.[^\.]\.ps1$') { continue } # Skip if the file is an unrelated file.
. `$file.FullName
}
"@)
Expand Down
65 changes: 65 additions & 0 deletions Transpilers/Modules/ModuleExports.psx.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<#
.Synopsis
Gets Module Exports
.Description
Gets Exported Commands from a module.
.EXAMPLE
.> {
$PipeScriptModule = Get-Module PipeScript
$exports = [ModuleExports()]$PipeScriptModule
$exports
}
#>
[CmdletBinding(DefaultParameterSetName='None',PositionalBinding=$false)]
[ValidateScript({
$val = $_
if (
($val.Parent -is [Management.Automation.Language.AttributedExpressionAst]) -and
($val.Parent.Attribute.TypeName.Name -in 'ModuleExport', 'GetExport', 'GetExports', 'ListExports', 'ModuleExport', 'GetModuleExport', 'GetModuleExports')
) {
return $true
}
return $false
})]
[Alias('GetExport','GetExports', 'ListExport','ListExports','ModuleExport','GetModuleExport', 'GetModuleExports')]
param(
# The command type
[Parameter(Position=0)]
[Management.Automation.CommandTypes[]]
$CommandType = @('Alias','Function','Cmdlet'),

# A VariableExpression. This variable must contain a module.
[Parameter(Mandatory,ValueFromPipeline,ParameterSetName='VariableExpressionAST')]
[Management.Automation.Language.VariableExpressionAST]
$VariableAST
)

process {

$var = $VariableAST.Extent.ToString()
[scriptblock]::Create($(
{
@(
if ($var -isnot [Management.Automation.PSModuleInfo]) {
Write-Error "'$var' must be a [Management.Automation.PSModuleInfo]"
} elseif ($var.ExportedCommands.Count) {
foreach ($cmd in $var.ExportedCommands.Values) {
if ($cmd.CommandType -in $CommandType) {
$cmd
}
}
} else {
foreach ($cmd in $ExecutionContext.SessionState.InvokeCommand.GetCommands('*', 'Function,Cmdlet', $true)) {
if ($cmd.Module -ne $var) { continue }
if ($CommandType -contains 'Alias' -and $cmd.ScriptBlock.Attributes.AliasNames) {
foreach ($aliasName in $cmd.ScriptBlock.Attributes.AliasNames) {
$ExecutionContext.SessionState.InvokeCommand.GetCommand($aliasName, 'Alias')
}
}
if ($CommandType -contains $cmd.CommandType) {
$cmd
}
}
})
} -replace '\$var', "$var" -replace '\$CommandType', "'$($CommandType -join "','")'"))
}
84 changes: 84 additions & 0 deletions Transpilers/Modules/ModuleRelationship.psx.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@

<#
.SYNOPSIS
Gets Module Relationships
.DESCRIPTION
Gets Modules that are related to a given module.

Modules can be related to each other by a few mechanisms:

* A Module Can Include another Module's Name in it's ```.PrivateData.PSData.Tags```
* A Module Can include data for another module it it's ```.PrivataData.```
.EXAMPLE
.> {
$Module = Get-Module PipeScript
[ModuleRelationships()]$Module
}
#>
[ValidateScript({
$val = $_
if (
($val.Parent -is [Management.Automation.Language.AttributedExpressionAst]) -and
($val.Parent.Attribute.TypeName.Name -in 'RelatedModules', 'RelatedModule', 'ModuleRelationships')
) {
return $true
}
return $false
})]
[Alias('RelatedModules', 'RelatedModule','ModuleRelationships')]
param(
# A VariableExpression. This variable must contain a module or name of module.
[Parameter(Mandatory,ValueFromPipeline,ParameterSetName='VariableExpressionAST')]
[Management.Automation.Language.VariableExpressionAST]
$VariableAST
)


process {

[scriptblock]::Create($({

@(

$MyModuleName, $myModule =
if ($targetModule -is [string]) {
$targetModule, (Get-Module $targetModule)
} elseif ($targetModule -is [Management.Automation.PSModuleInfo]) {
$targetModule.Name, $targetModule
} else {
Write-Error "$targetModule must be a [string] or [Management.Automation.PSModuleInfo]"
}


#region Search for Module Relationships
if ($myModule -and $MyModuleName) {
foreach ($loadedModule in Get-Module) { # Walk over all modules.
if ( # If the module has PrivateData keyed to this module
$loadedModule.PrivateData.$myModuleName
) {
# Determine the root of the module with private data.
$relationshipData = $loadedModule.PrivateData.$myModuleName
[PSCustomObject][Ordered]@{
PSTypeName = 'Module.Relationship'
Module = $myModule
RelatedModule = $loadedModule
PrivateData = $loadedModule.PrivateData.$myModuleName
}
}
elseif ($loadedModule.PrivateData.PSData.Tags -contains $myModuleName) {
[PSCustomObject][Ordered]@{
PSTypeName = 'Module.Relationship'
Module = $myModule
RelatedModule = $loadedModule
PrivateData = @{}
}
}
}
}
#endregion Search for Module Relationships

)

} -replace '\$TargetModule', "$VariableAST"))

}
Loading