Skip to content

Commit fd2854d

Browse files
Merge pull request #61 from StartAutomating/PipeScriptImprovements
Pipe script improvements
2 parents 13a59d6 + e65ccb3 commit fd2854d

14 files changed

+548
-6
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## 0.0.2
2+
* New Transpilers:
3+
* .>ValidatePlatform (#58)
4+
* .>ValidatePropertyName (#59)
5+
* .>Inline.ObjectiveC (#60)
6+
* Transpiler Fixes
7+
* .>VBN now supports -Position (#57)
8+
* GitHub Action Bugfix (#55)
9+
---
10+
## 0.0.1
11+
Initial Commit.

Github/Actions/PipeScriptAction.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ if ($PipeScript) {
110110
Out-Host
111111
}
112112

113-
$PipeScriptTook = [Datetime]::Now - $PipeScriptScriptStart
113+
$PipeScriptTook = [Datetime]::Now - $PipeScriptStart
114114
"::set-output name=PipeScriptRuntime::$($PipeScriptScriptTook.TotalMilliseconds)" | Out-Host
115115

116116
$BuildPipeScriptStart = [DateTime]::Now

PipeScript.HelpOut.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ if ($PipeScriptLoaded) {
1111
"::error:: PipeScript not loaded" |Out-Host
1212
}
1313

14-
Save-MarkdownHelp -Module PipeScript -ReplaceScriptName '\.psx\.ps1$' -SkipCommandType Alias -PassThru -IncludeTopic *.help.txt -IncludeExtension @()
14+
Save-MarkdownHelp -Module PipeScript -ReplaceScriptName '\.psx\.ps1$' -ReplaceScriptNameWith '-Transpiler' -SkipCommandType Alias -PassThru -IncludeTopic *.help.txt -IncludeExtension @() -ScriptPath '\.psx\.ps1$'
1515

1616
Pop-Location

PipeScript.psd1

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@{
2-
ModuleVersion = '0.0.1'
2+
ModuleVersion = '0.0.2'
33
Description = 'An Extensible Transpiler for PowerShell (and anything else)'
44
RootModule = 'PipeScript.psm1'
55
PowerShellVersion = '4.0'
@@ -16,6 +16,19 @@
1616
LicenseURI = 'https://github.com/StartAutomating/PipeScript/blob/main/LICENSE'
1717

1818
Tags = 'PipeScript','PowerShell', 'Transpilation', 'Compiler'
19+
ReleaseNotes = @'
20+
## 0.0.2
21+
* New Transpilers:
22+
* .>ValidatePlatform (#58)
23+
* .>ValidatePropertyName (#59)
24+
* .>Inline.ObjectiveC (#60)
25+
* Transpiler Fixes
26+
* .>VBN now supports -Position (#57)
27+
* GitHub Action Bugfix (#55)
28+
---
29+
## 0.0.1
30+
Initial Commit.
31+
'@
1932
}
2033
}
2134
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<#
2+
.SYNOPSIS
3+
Objective C PipeScript Transpiler.
4+
.DESCRIPTION
5+
Transpiles Objective C/C++ with Inline PipeScript into Objective C/C++.
6+
7+
Multiline comments with /*{}*/ will be treated as blocks of PipeScript.
8+
9+
Multiline comments can be preceeded or followed by 'empty' syntax, which will be ignored.
10+
11+
This for Inline PipeScript to be used with operators, and still be valid C/C++ syntax.
12+
13+
The Objective C Inline Transpiler will consider the following syntax to be empty:
14+
15+
* ```null```
16+
* ```nil```
17+
* ```""```
18+
* ```''```
19+
#>
20+
[ValidateScript({
21+
$cmdInfo = $_
22+
if ($cmdInfo.Source -match '\.(?>m|mm)$') {
23+
return $true
24+
}
25+
return $false
26+
})]
27+
param(
28+
# The command information. This will include the path to the file.
29+
[Parameter(Mandatory,ValueFromPipeline)]
30+
$CommandInfo
31+
)
32+
33+
begin {
34+
# We start off by declaring a number of regular expressions:
35+
$startComment = '/\*' # * Start Comments ```\*```
36+
$endComment = '\*/' # * End Comments ```/*```
37+
$Whitespace = '[\s\n\r]{0,}'
38+
# * IgnoredContext ```String.empty```, ```null```, blank strings and characters
39+
$IgnoredContext = "(?<ignore>(?>$("null", "nil", '""', "''" -join '|'))\s{0,}){0,1}"
40+
# * StartRegex ```$IgnoredContext + $StartComment + '{' + $Whitespace```
41+
$startRegex = "(?<PSStart>${IgnoredContext}${startComment}\{$Whitespace)"
42+
# * EndRegex ```$whitespace + '}' + $EndComment + $ignoredContext```
43+
$endRegex = "(?<PSEnd>$Whitespace\}${endComment}\s{0,}${IgnoredContext})"
44+
45+
$sourcePattern = [Regex]::New("(?>$(
46+
$startRegex, $endRegex -join ([Environment]::NewLine + '|' + [Environment]::NewLine)
47+
))", "IgnoreCase, IgnorePatternWhitespace", "00:00:05")
48+
}
49+
50+
process {
51+
$fileInfo = $commandInfo.Source -as [IO.FileInfo]
52+
$fileText = [IO.File]::ReadAllText($fileInfo.Fullname)
53+
54+
.>PipeScript.Inline -SourceFile $CommandInfo.Source -SourceText $fileText -SourcePattern $sourcePattern
55+
}

Transpilers/Parameters/VBN.psx.ps1

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ $Mandatory,
1515

1616
[Alias('VFP')]
1717
[switch]
18-
$ValueFromPipeline
18+
$ValueFromPipeline,
19+
20+
# The position of the parameter.
21+
[int]
22+
$Position
1923
)
2024

2125
$paramOptions = @(
@@ -24,7 +28,7 @@ $paramOptions = @(
2428
}
2529
if ($ParameterSet) {
2630
"ParameterSetName='$($ParameterSet.Replace("'","''"))'"
27-
}
31+
}
2832
"ValueFromPipelineByPropertyName"
2933
if ($ValueFromPipeline) {
3034
"ValueFromPipeline"
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<#
2+
.SYNOPSIS
3+
Validates the Platform
4+
.DESCRIPTION
5+
Validates the Platform.
6+
7+
When used within Parameters, this adds a ```[ValidateScript({})]``` to ensure that the platform is correct.
8+
9+
When used on a ```[Management.Automation.Language.VariableExpressionAst]``` will apply a
10+
```[ValidateScript({})]``` to that variable, which will prevent assignemnt to the variable if not on the platform.
11+
.EXAMPLE
12+
{
13+
param(
14+
[ValidatePlatform("Windows")]
15+
[switch]
16+
$UseWMI
17+
)
18+
} | .>PipeScript
19+
#>
20+
[CmdletBinding(DefaultParameterSetName='Parameter')]
21+
param(
22+
# The name of one or more platforms. These will be interpreted as wildcards.
23+
[Parameter(Mandatory,Position=0)]
24+
[string[]]
25+
$Platform,
26+
27+
[Parameter(ValueFromPipeline,ParameterSetName='VariableExpressionAST')]
28+
[Management.Automation.Language.VariableExpressionAST]
29+
$VariableAST
30+
)
31+
32+
$Platform = @($Platform -replace 'Windows', 'Win*')
33+
34+
$checkPlatform = @"
35+
`$platformList = '$($Platform -join "','")'
36+
"@ + {
37+
$platformOK = ($platFormList -like 'Win*' -and $(
38+
$winPlat = @($platFormList -like 'Win*')[0]
39+
(-not $psVersionTable.Platform) -or $psVersionTable.Platform -like $winPlat
40+
)) -or $(
41+
foreach ($platform in $platformList) {
42+
if ($psVersionTable.Platform -like $platform) {
43+
$true;break
44+
}
45+
}
46+
)
47+
}
48+
49+
if ($PSCmdlet.ParameterSetName -eq 'Parameter') {
50+
51+
[ScriptBlock]::Create(@"
52+
[ValidateScript({
53+
`$ok = `$false
54+
$checkPlatform
55+
`$ok = `$platformOK
56+
if (-not `$ok) {
57+
throw "Incorrect Platform: '`$(`$psVersionTable.Platform)'. Must be like '$($Platform -join "','")'."
58+
}
59+
})]
60+
$(
61+
if ($psCmdlet.ParameterSetName -eq 'Parameter') {
62+
'param()'
63+
} else {
64+
'$' + $VariableAST.variablePath.ToString()
65+
}
66+
)
67+
"@)
68+
69+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<#
2+
.SYNOPSIS
3+
Validates Property Names
4+
.DESCRIPTION
5+
Validates that an object has one or more property names.
6+
.Example
7+
{
8+
param(
9+
[ValidatePropertyName(PropertyName='a','b')]
10+
$InputObject
11+
)
12+
} | .>PipeScript
13+
.EXAMPLE
14+
[PSCustomObject]@{a='a';b='b'} |
15+
.> {
16+
param(
17+
[ValidatePropertyName(PropertyName='a','b')]
18+
[vfp]
19+
$InputObject
20+
)
21+
22+
$InputObject
23+
}
24+
.EXAMPLE
25+
@{a='a'} |
26+
.> {
27+
param(
28+
[ValidatePropertyName(PropertyName='a','b')]
29+
[vfp]
30+
$InputObject
31+
)
32+
33+
$InputObject
34+
}
35+
#>
36+
[CmdletBinding(DefaultParameterSetName='Parameter')]
37+
[Alias('ValidatePropertyNames')]
38+
param(
39+
# The property names being validated.
40+
[Parameter(Mandatory,Position=0)]
41+
[string[]]
42+
$PropertyName,
43+
44+
# A variable expression.
45+
# If this is provided, will apply a ```[ValidateScript({})]``` attribute to the variable, constraining future values.
46+
[Parameter(ValueFromPipeline,ParameterSetName='VariableExpressionAST')]
47+
[Management.Automation.Language.VariableExpressionAST]
48+
$VariableAST
49+
)
50+
51+
process {
52+
$checkPropertyNames =
53+
{
54+
$foundProperties = @(
55+
foreach ($propName in $PropertyNames) {
56+
if ($inObject -is [Collections.IDictionary]) {
57+
$inObject.Contains($propName)
58+
} elseif ($inObject.psobject) {
59+
$null -ne $inObject.psobject.properties[$propName]
60+
} else {
61+
$false
62+
}
63+
}
64+
)
65+
$missingProperties =
66+
@(
67+
for ($propertyIndex = 0; $propertyIndex -lt $propertyNames.Length; $propertyIndex++) {
68+
if (-not $foundProperties[$propertyIndex]) {
69+
$PropertyNames[$propertyIndex]
70+
}
71+
})
72+
}
73+
74+
75+
[ScriptBlock]::Create(@"
76+
[ValidateScript({
77+
`$propertyNames = '$($PropertyName -join "','")'
78+
`$inObject = `$_
79+
$checkPropertyNames
80+
if (`$MissingProperties) {
81+
throw "Missing Properties: `$(`$missingProperties -join ',')"
82+
}
83+
return `$true
84+
})]
85+
$(
86+
if ($psCmdlet.ParameterSetName -eq 'Parameter') {
87+
'param()'
88+
} else {
89+
'$' + $VariableAST.variablePath.ToString()
90+
}
91+
)
92+
"@)
93+
94+
}

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ runs:
178178
Out-Host
179179
}
180180
181-
$PipeScriptTook = [Datetime]::Now - $PipeScriptScriptStart
181+
$PipeScriptTook = [Datetime]::Now - $PipeScriptStart
182182
"::set-output name=PipeScriptRuntime::$($PipeScriptScriptTook.TotalMilliseconds)" | Out-Host
183183
184184
$BuildPipeScriptStart = [DateTime]::Now

docs/Decorate-Transpiler.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Decorate.psx.ps1 [-TypeName] <string[]> [-PassThru] [-Clear] [<CommonParameters>]
2+
Decorate.psx.ps1 [-TypeName] <string[]> -VariableAst <VariableExpressionAst> [-PassThru] [-Clear] [<CommonParameters>]
3+
4+

0 commit comments

Comments
 (0)