File tree Expand file tree Collapse file tree 1 file changed +54
-0
lines changed
Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Original file line number Diff line number Diff line change 1+ <#
2+ . SYNOPSIS
3+ TOML Inline PipeScript Transpiler.
4+ . DESCRIPTION
5+ Transpiles TOML with Inline PipeScript into TOML.
6+
7+ Because TOML does not support comment blocks, PipeScript can be written inline inside of specialized Multiline string
8+
9+ PipeScript can be included in a TOML string that starts and ends with ```{}```, for example ```"""{}"""```
10+ . Example
11+ .> {
12+ $tomlContent = @'
13+ [seed]
14+ RandomNumber = """{Get-Random}"""
15+ '@
16+ [OutputFile('.\RandomExample.ps1.toml')]$tomlContent
17+ }
18+
19+ .> .\RandomExample.ps1.toml
20+ #>
21+ [ValidateScript ({
22+ $cmdInfo = $_
23+ if ($cmdInfo.Source -match ' \.toml$' ) {
24+ return $true
25+ }
26+ return $false
27+ })]
28+ param (
29+ # The command information. This will include the path to the file.
30+ [Parameter (Mandatory , ValueFromPipeline )]
31+ $CommandInfo
32+ )
33+
34+ begin {
35+ # We start off by declaring a number of regular expressions:
36+
37+ $startComment = ' (?>"""\{)'
38+ $endComment = ' (?>\}""")'
39+
40+ $startRegex = " (?<PSStart>${startComment} )"
41+ $endRegex = " (?<PSEnd>${endComment} )"
42+
43+ $sourcePattern = [Regex ]::New(" (?>$ (
44+ $startRegex , $endRegex -join ([Environment ]::NewLine + ' |' + [Environment ]::NewLine)
45+ ) )" , " IgnoreCase, IgnorePatternWhitespace" , " 00:00:05" )
46+ }
47+
48+ process {
49+
50+ $fileInfo = $commandInfo.Source -as [IO.FileInfo ]
51+ $fileText = [IO.File ]::ReadAllText($fileInfo.Fullname )
52+
53+ .> PipeScript.Inline - SourceFile $CommandInfo.Source - SourceText $fileText - SourcePattern $sourcePattern
54+ }
You can’t perform that action at this time.
0 commit comments