Skip to content

Commit 97312e2

Browse files
Merge pull request #151 from StartAutomating/PipeScriptUpdates
Pipe script updates
2 parents bd12523 + 3fcb028 commit 97312e2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1629
-60
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
## 0.0.13:
2+
* New / Improved Keywords
3+
* assert keyword (Support for pipelines) (#143)
4+
* new keyword (Support for ::Create method) (#148)
5+
* until keyword (#146)
6+
* Syntax Improvements
7+
* Support for === (#123) (thanks @dfinke)
8+
* New Inline PipeScript support:
9+
* Now Supporting Inline PipeScript in YAML (#147)
10+
* General Improvements:
11+
* Extending AST Types (#145)
12+
* Adding tests for keywords
13+
---
14+
15+
116
## 0.0.12:
217
* Adding assert keyword (#143)
318
* Fixing new keyword for blank constructors (#142 )

Formatting/YAML.format.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Write-FormatView -Typename YAML -Action {
2+
Format-YAML -inputObject $_
3+
}

PipeScript.ezout.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ $destinationRoot = $myRoot
1919
if ($formatting) {
2020
$myFormatFile = Join-Path $destinationRoot "$myModuleName.format.ps1xml"
2121
$formatting | Out-FormatData -Module $MyModuleName | Set-Content $myFormatFile -Encoding UTF8
22+
Get-Item $myFormatFile
2223
}
2324

2425
$types = @(
@@ -33,5 +34,6 @@ $types = @(
3334
if ($types) {
3435
$myTypesFile = Join-Path $destinationRoot "$myModuleName.types.ps1xml"
3536
$types | Out-TypeData | Set-Content $myTypesFile -Encoding UTF8
37+
Get-Item $myTypesFile
3638
}
3739
Pop-Location

PipeScript.format.ps1xml

Lines changed: 226 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-16"?>
2-
<!-- Generated with EZOut 1.8.6: Install-Module EZOut or https://github.com/StartAutomating/EZOut -->
2+
<!-- Generated with EZOut 1.8.7: Install-Module EZOut or https://github.com/StartAutomating/EZOut -->
33
<Configuration>
44
<ViewDefinitions>
55
<View>
@@ -262,6 +262,52 @@
262262
</TableRowEntries>
263263
</TableControl>
264264
</View>
265+
<View>
266+
<Name>YAML</Name>
267+
<ViewSelectedBy>
268+
<TypeName>YAML</TypeName>
269+
</ViewSelectedBy>
270+
<CustomControl>
271+
<CustomEntries>
272+
<CustomEntry>
273+
<CustomItem>
274+
<ExpressionBinding>
275+
<ScriptBlock>$moduleName = 'PipeScript'
276+
277+
do {
278+
$lm = Get-Module -Name $moduleName -ErrorAction Ignore
279+
if (-not $lm) { continue }
280+
if ($lm.FormatPartsLoaded) { break }
281+
$wholeScript = @(foreach ($formatFilePath in $lm.exportedFormatFiles) {
282+
foreach ($partNodeName in Select-Xml -LiteralPath $formatFilePath -XPath "/Configuration/Controls/Control/Name[starts-with(., '$')]") {
283+
$ParentNode = $partNodeName.Node.ParentNode
284+
"$($ParentNode.Name)={
285+
$($ParentNode.CustomControl.CustomEntries.CustomEntry.CustomItem.ExpressionBinding.ScriptBlock)}"
286+
}
287+
}) -join [Environment]::NewLine
288+
New-Module -Name "${ModuleName}.format.ps1xml" -ScriptBlock ([ScriptBlock]::Create(($wholeScript + ';Export-ModuleMember -Variable *'))) |
289+
Import-Module -Global
290+
$onRemove = [ScriptBlock]::Create("Remove-Module '${ModuleName}.format.ps1xml'")
291+
292+
if (-not $lm.OnRemove) {
293+
$lm.OnRemove = $onRemove
294+
} else {
295+
$lm.OnRemove = [ScriptBlock]::Create($onRemove.ToString() + '' + [Environment]::NewLine + $lm.OnRemove)
296+
}
297+
$lm | Add-Member NoteProperty FormatPartsLoaded $true -Force
298+
299+
} while ($false)
300+
301+
302+
303+
&amp; ${PipeScript_Format-YAML} -inputObject $_
304+
</ScriptBlock>
305+
</ExpressionBinding>
306+
</CustomItem>
307+
</CustomEntry>
308+
</CustomEntries>
309+
</CustomControl>
310+
</View>
265311
</ViewDefinitions>
266312
<Controls>
267313
<Control>
@@ -1258,5 +1304,184 @@ $BackgroundColor
12581304
</CustomEntries>
12591305
</CustomControl>
12601306
</Control>
1307+
<Control>
1308+
<Name>${PipeScript_Format-YAML}</Name>
1309+
<CustomControl>
1310+
<CustomEntries>
1311+
<CustomEntry>
1312+
<CustomItem>
1313+
<ExpressionBinding>
1314+
<ScriptBlock>
1315+
&lt;#
1316+
.SYNOPSIS
1317+
Formats objects as YAML
1318+
.DESCRIPTION
1319+
Formats an object as YAML.
1320+
.EXAMPLE
1321+
Format-Yaml -InputObject @("a", "b", "c")
1322+
.EXAMPLE
1323+
@{a="b";c="d";e=@{f=@('g')}} | Format-Yaml
1324+
#&gt;
1325+
[Management.Automation.Cmdlet("Format","Object")]
1326+
[ValidateScript({return $true})]
1327+
param(
1328+
# The InputObject.
1329+
[Parameter(ValueFromPipeline)]
1330+
[PSObject]
1331+
$inputObject,
1332+
1333+
# If set, will make a YAML header by adding a YAML Document tag above and below output.
1334+
[Alias('YAMLDocument')]
1335+
[switch]
1336+
$YamlHeader
1337+
)
1338+
1339+
begin {
1340+
$toYaml = {
1341+
param(
1342+
[Parameter(ValueFromPipeline,Position=0)]$Object,
1343+
[Object]$Parent,
1344+
[Object]$GrandParent,
1345+
[int]$Indent = 0)
1346+
1347+
begin { $n = 0; $mySelf = $myInvocation.MyCommand.ScriptBlock }
1348+
process {
1349+
$n++
1350+
if ($Object -eq $null) { return }
1351+
1352+
if ($Parent -and $Parent -is [Collections.IList]) {
1353+
if ($Parent.IndexOf($Object) -gt 0) { ' ' * $Indent }
1354+
'- '
1355+
}
1356+
1357+
#region Primitives
1358+
if ( $Object -is [string] ) { # If it's a string
1359+
if ($object -match '\n') { # see if it's a multline string.
1360+
"|" # If it is, emit the multiline indicator
1361+
$indent +=2
1362+
foreach ($l in $object -split '(?&gt;\r\n|\n)') { # and emit each line indented
1363+
[Environment]::NewLine
1364+
' ' * $indent
1365+
$l
1366+
}
1367+
$indent -=2
1368+
} elseif ("$object".Contains('*')) {
1369+
"'$($Object -replace "'","''")'"
1370+
} else {
1371+
$object
1372+
}
1373+
1374+
if ($Parent -is [Collections.IList]) { # If the parent object was a list
1375+
[Environment]::NewLine # emit a newline.
1376+
}
1377+
return # Once the string has been emitted, return.
1378+
}
1379+
if ( [int], [float], [bool] -contains $Object.GetType() ) { # If it is an [int] or [float] or [bool]
1380+
"$Object".ToLower() # Emit it in lowercase.
1381+
if ($Parent -is [Collections.IList]) {
1382+
[Environment]::NewLine
1383+
}
1384+
return
1385+
}
1386+
#endregion Primitives
1387+
1388+
#region KVP
1389+
if ( $Object -is [Collections.DictionaryEntry] -or $object -is [Management.Automation.PSPropertyInfo]) {
1390+
if ($Parent -isnot [Collections.IList] -and
1391+
($GrandParent -isnot [Collections.IList] -or $n -gt 1)) {
1392+
[Environment]::NewLine + (" " * $Indent)
1393+
}
1394+
if ($object.Key -and $Object.Key -is [string]) {
1395+
$Object.Key +": "
1396+
} elseif ($object.Name -and $object.Name -is [string]) {
1397+
$Object.Name +": "
1398+
}
1399+
}
1400+
1401+
if ( $Object -is [Collections.DictionaryEntry] -or $Object -is [Management.Automation.PSPropertyInfo]) {
1402+
&amp; $mySelf -Object $Object.Value -Parent $Object -GrandParent $parent -Indent $Indent
1403+
return
1404+
}
1405+
#endregion KVP
1406+
1407+
1408+
#region Nested
1409+
if ($parent -and ($Object -is [Collections.IDictionary] -or $Object -is [PSObject])) {
1410+
$Indent += 2
1411+
}
1412+
elseif ($object -is [Collections.IList]) {
1413+
$allPrimitive = 1
1414+
foreach ($Obj in $Object) {
1415+
$allPrimitive = $allPrimitive -band (
1416+
$Obj -is [string] -or
1417+
$obj -is [int] -or
1418+
$obj -is [float] -or
1419+
$obj -is [bool]
1420+
)
1421+
}
1422+
if ($parent -and -not $allPrimitive) {
1423+
$Indent += 2
1424+
}
1425+
}
1426+
1427+
1428+
if ( $Object -is [Collections.IDictionary] ) {
1429+
$Object.GetEnumerator() |
1430+
&amp; $mySelf -Parent $Object -GrandParent $Parent -Indent $Indent
1431+
} elseif ($Object -is [Collections.IList]) {
1432+
1433+
[Environment]::NewLine + (' ' * $Indent)
1434+
1435+
$Object |
1436+
&amp; $mySelf -Parent $Object -GrandParent $Parent -Indent $Indent
1437+
1438+
} elseif ($Object.PSObject.Properties) {
1439+
$Object.psobject.properties |
1440+
&amp; $mySelf -Parent $Object -GrandParent $Parent -Indent $Indent
1441+
}
1442+
1443+
if ($Object -is [Collections.IDictionary] -or $Object -is [PSCustomObject] -or $Object -is [Collections.IList]) {
1444+
if ($Parent -is [Collections.IList]) { [Environment]::NewLine }
1445+
$Indent -= 2;
1446+
}
1447+
#endregion Nested
1448+
}
1449+
}
1450+
$inputWasNotPiped = $PSBoundParameters.InputObject -as [bool]
1451+
$allInputObjects = @()
1452+
}
1453+
1454+
process {
1455+
if ($inputWasNotPiped) {
1456+
'' + $(if ($YamlHeader) { '---' + [Environment]::NewLine }) + (
1457+
(&amp; $toYaml -object $inputObject) -join '' -replace
1458+
"$([Environment]::NewLine * 2)", [Environment]::NewLine
1459+
) + $(if ($YamlHeader) { [Environment]::NewLine + '---'})
1460+
} else {
1461+
$allInputObjects += $inputObject
1462+
}
1463+
}
1464+
1465+
end {
1466+
if (-not $allInputObjects) { return }
1467+
if ($allInputObjects.Length -eq 1) {
1468+
'' + $(if ($YamlHeader) { '---' + [Environment]::NewLine}) + (
1469+
(&amp; $toYaml -object $inputObject) -join '' -replace
1470+
"$([Environment]::NewLine * 2)", [Environment]::NewLine
1471+
) + $(if ($YamlHeader) { [Environment]::NewLine + '---'})
1472+
} else {
1473+
'' + $(if ($YamlHeader) { '---' + [Environment]::NewLine}) + (
1474+
(&amp; $toYaml -object $allInputObjects) -join '' -replace
1475+
"$([Environment]::NewLine * 2)", [Environment]::NewLine
1476+
) + $(if ($YamlHeader) { [Environment]::NewLine + '---'})
1477+
}
1478+
}
1479+
</ScriptBlock>
1480+
</ExpressionBinding>
1481+
</CustomItem>
1482+
</CustomEntry>
1483+
</CustomEntries>
1484+
</CustomControl>
1485+
</Control>
12611486
</Controls>
12621487
</Configuration>

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.12'
2+
ModuleVersion = '0.0.13'
33
Description = 'An Extensible Transpiler for PowerShell (and anything else)'
44
RootModule = 'PipeScript.psm1'
55
PowerShellVersion = '4.0'
@@ -19,6 +19,19 @@
1919
BuildModule = @('EZOut','Piecemeal','PipeScript','HelpOut', 'PSDevOps')
2020
Tags = 'PipeScript','PowerShell', 'Transpilation', 'Compiler'
2121
ReleaseNotes = @'
22+
## 0.0.13:
23+
* New / Improved Keywords
24+
* assert keyword (Support for pipelines) (#143)
25+
* new keyword (Support for ::Create method) (#148)
26+
* until keyword (#146)
27+
* Syntax Improvements
28+
* Support for === (#123) (thanks @dfinke)
29+
* New Inline PipeScript support:
30+
* Now Supporting Inline PipeScript in YAML (#147)
31+
* General Improvements:
32+
* Extending AST Types (#145)
33+
---
34+
2235
## 0.0.12:
2336
* Adding assert keyword (#143)
2437
* Fixing new keyword for blank constructors (#142 )

0 commit comments

Comments
 (0)