Skip to content

Commit d816ad5

Browse files
author
Luis Orta
committed
Need the filters too.
1 parent 9ca9731 commit d816ad5

File tree

3 files changed

+126
-12
lines changed

3 files changed

+126
-12
lines changed

archive.zip

25.2 KB
Binary file not shown.

filters.ps1

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# Filters are PowerShell functions designed to quickly process pipeline input.
2+
3+
# This file contains filters that are useful throughout the build.
4+
5+
#region PowerShell Specific Filters
6+
filter RequireModule {
7+
<#
8+
.SYNOPSIS
9+
Installs a module if it is not already loaded.
10+
.DESCRIPTION
11+
Installs a PowerShell module if it is not already loaded.
12+
#>
13+
$requirementName = $_
14+
if ($requirementName -is [Management.Automation.ExternalScriptInfo]) {
15+
$requirementName.ScriptBlock.Ast.ScriptRequirements.RequiredModules.Name |
16+
RequireModule
17+
return
18+
}
19+
if (! $requirementName) {
20+
return
21+
}
22+
$alreadyLoaded = Import-Module -Name $requirementName -PassThru -ErrorAction Ignore -Global
23+
# If they're not already loaded, we'll install them.
24+
if (-not $alreadyLoaded) {
25+
Install-Module -AllowClobber -Force -Name $requirementName -Scope CurrentUser
26+
$alreadyLoaded = Import-Module -Name $requirementName -PassThru -ErrorAction Ignore -Global
27+
if ($file.FullName) {
28+
Write-Host "Installed $($alreadyLoaded.Name) for $($file.FullName)"
29+
}
30+
} elseif ($file.FullName) {
31+
Write-Host "Already loaded $($alreadyLoaded.Name) for $($file.FullName)"
32+
}
33+
}
34+
#endregion PowerShell Specific Filters
35+
36+
#region Special Filters
37+
filter content {$Content}
38+
39+
filter now {[DateTime]::Now}
40+
41+
filter utc_now {[DateTime]::UtcNow}
42+
43+
filter today {[DateTime]::Today}
44+
45+
filter yaml_header_pattern {
46+
[Regex]::new('
47+
(?<Markdown_YAMLHeader>
48+
(?m)\A\-{3,} # At least 3 dashes mark the start of the YAML header
49+
(?<YAML>(?:.|\s){0,}?(?=\z|\-{3,} # And anything until at least three dashes is the content
50+
))\-{3,} # Include the dashes in the match, so that the pointer is correct.
51+
)
52+
','IgnoreCase, IgnorePatternWhitespace')
53+
}
54+
55+
filter yaml_header {
56+
$in = $_
57+
if ($in -is [IO.FileInfo]) {
58+
$in | Get-Content -Raw | yaml_header
59+
return
60+
}
61+
foreach ($match in (yaml_header_pattern).Matches("$in")) {
62+
$match.Groups['YAML'].Value | from_yaml
63+
}
64+
}
65+
66+
filter from_yaml {
67+
$in = $_
68+
"YaYaml" | RequireModule
69+
$in | ConvertFrom-Yaml
70+
}
71+
72+
filter to_yaml {
73+
$in = $_
74+
"YaYaml" | RequireModule
75+
$in | ConvertTo-Yaml
76+
}
77+
78+
filter to_json {
79+
$in = $_
80+
$in | ConvertTo-Json -Depth 10
81+
}
82+
83+
filter strip_yaml_header {
84+
$in = $_
85+
if ($in -is [IO.FileInfo]) {
86+
$in | Get-Content -Raw | strip_yaml_header
87+
return
88+
}
89+
$in -replace (yaml_header_pattern)
90+
}
91+
92+
filter from_markdown {
93+
$in = $_
94+
if ($in -is [IO.FileInfo]) {
95+
$in | Get-Content -Raw | from_markdown
96+
return
97+
}
98+
@(
99+
$in |
100+
strip_yaml_header |
101+
ConvertFrom-Markdown |
102+
Select-Object -ExpandProperty Html
103+
) -replace 'disabled="disabled"'
104+
}
105+
106+
#endregion Special Filters
107+
108+
#region Custom Filters
109+
<#
110+
Put any function or filter you want here.
111+
112+
(if you want to add more filters inline but don't want to modify any of the other filters)
113+
#>
114+
#endregion Custom Filters

lastBuild.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
{
2-
"LastBuildTime": "2025-05-24T12:58:45.5921646-07:00",
2+
"LastBuildTime": "2025-05-24T13:08:21.5174506-07:00",
33
"BuildDuration": {
4-
"Ticks": 7927284,
4+
"Ticks": 1709809,
55
"Days": 0,
66
"Hours": 0,
7-
"Milliseconds": 792,
8-
"Microseconds": 728,
9-
"Nanoseconds": 400,
7+
"Milliseconds": 170,
8+
"Microseconds": 980,
9+
"Nanoseconds": 900,
1010
"Minutes": 0,
1111
"Seconds": 0,
12-
"TotalDays": 9.175097222222222E-06,
13-
"TotalHours": 0.00022020233333333334,
14-
"TotalMilliseconds": 792.7284,
15-
"TotalMicroseconds": 792728.4,
16-
"TotalNanoseconds": 792728400.0,
17-
"TotalMinutes": 0.01321214,
18-
"TotalSeconds": 0.7927284
12+
"TotalDays": 1.9789456018518517E-06,
13+
"TotalHours": 4.749469444444444E-05,
14+
"TotalMilliseconds": 170.9809,
15+
"TotalMicroseconds": 170980.9,
16+
"TotalNanoseconds": 170980900.0,
17+
"TotalMinutes": 0.0028496816666666665,
18+
"TotalSeconds": 0.1709809
1919
},
2020
"Message": "On Demand"
2121
}

0 commit comments

Comments
 (0)