Skip to content

Commit 0b68029

Browse files
author
James Brundage
committed
Adding Inline TypeScript Support (#46)
1 parent b47e552 commit 0b68029

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<#
2+
.SYNOPSIS
3+
XML Inline PipeScript Transpiler.
4+
.DESCRIPTION
5+
Transpiles XML with Inline PipeScript into XML.
6+
7+
Multiline comments blocks like this ```<!--{}-->``` will be treated as blocks of PipeScript.
8+
#>
9+
[ValidateScript({
10+
$cmdInfo = $_
11+
if ($cmdInfo.Source -match '\.(?>xml|xaml)$') {
12+
return $true
13+
}
14+
return $false
15+
})]
16+
param(
17+
# The command information. This will include the path to the file.
18+
[Parameter(Mandatory,ValueFromPipeline)]
19+
$CommandInfo
20+
)
21+
22+
begin {
23+
# We start off by declaring a number of regular expressions:
24+
$startComment = '<\!--' # * Start Comments ```<!--```
25+
$endComment = '-->' # * End Comments ```-->```
26+
$Whitespace = '[\s\n\r]{0,}'
27+
# * StartRegex ```$StartComment + '{' + $Whitespace```
28+
$startRegex = "(?<PSStart>${startComment}\{$Whitespace)"
29+
# * EndRegex ```$whitespace + '}' + $EndComment```
30+
$endRegex = "(?<PSEnd>$Whitespace\}${endComment}\s{0,})"
31+
32+
$sourcePattern = [Regex]::New("(?>$(
33+
$startRegex, $endRegex -join ([Environment]::NewLine + '|' + [Environment]::NewLine)
34+
))", "IgnoreCase, IgnorePatternWhitespace", "00:00:05")
35+
}
36+
37+
process {
38+
39+
$fileInfo = $commandInfo.Source -as [IO.FileInfo]
40+
$fileText = [IO.File]::ReadAllText($fileInfo.Fullname)
41+
42+
.>PipeScript.Inline -SourceFile $CommandInfo.Source -SourceText $fileText -SourcePattern $sourcePattern
43+
}

0 commit comments

Comments
 (0)