-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmu-spec-index.ps1
More file actions
63 lines (58 loc) · 2.28 KB
/
Copy pathmu-spec-index.ps1
File metadata and controls
63 lines (58 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<#
.SYNOPSIS
Generate spec-index.yaml: a machine-readable index of every specification
document (for human navigation and AI ingestion).
.DESCRIPTION
Scans the repository for Markdown documents that carry a Standard Header and
emits one YAML record per document: id, title, class, status, version, path.
.EXAMPLE
pwsh tools/mu-spec-index.ps1 > spec-index.yaml
#>
[CmdletBinding()]
param(
[string]$Root = (Split-Path -Parent $PSCommandPath)
)
$Root = Split-Path -Parent $Root
function Get-Field($lines, $name) {
foreach ($l in $lines) {
if ($l -match ('^\*\*' + [regex]::Escape($name) + ':\*\*\s*(.+?)\s*$')) { return $Matches[1].Trim() }
}
return ''
}
$docs = @()
Get-ChildItem -Path $Root -Recurse -Filter *.md |
Where-Object { $_.FullName -notmatch '\\\.git\\' } |
Sort-Object FullName | ForEach-Object {
$lines = Get-Content -LiteralPath $_.FullName -Encoding UTF8
$id = Get-Field $lines 'Document ID'
if (-not $id) { return }
$rel = $_.FullName.Substring($Root.Length).TrimStart('\','/') -replace '\\','/'
$docs += [pscustomobject]@{
id = $id
title = (Get-Field $lines 'Title')
class = (Get-Field $lines 'Document Class')
status = (Get-Field $lines 'Status')
version = (Get-Field $lines 'Version')
path = $rel
}
}
$docs = $docs | Sort-Object id
$sb = New-Object System.Text.StringBuilder
[void]$sb.AppendLine('# spec-index.yaml')
[void]$sb.AppendLine('# Auto-generated by the spec-index tool (mu-spec-index). Machine-readable index of the specification.')
[void]$sb.AppendLine('specification: Meta-Universe')
[void]$sb.AppendLine('version: "2.0"')
[void]$sb.AppendLine('status: "Working Draft"')
[void]$sb.AppendLine('license: Apache-2.0')
[void]$sb.AppendLine(('documentCount: {0}' -f $docs.Count))
[void]$sb.AppendLine('documents:')
foreach ($d in $docs) {
$t = $d.title -replace ([char]0x2014), '-' -replace ([char]0x2013), '-' -replace ([char]0x2019), "'" -replace '"', '\"'
[void]$sb.AppendLine((' - id: {0}' -f $d.id))
[void]$sb.AppendLine((' title: "{0}"' -f $t))
[void]$sb.AppendLine((' class: {0}' -f $d.class))
[void]$sb.AppendLine((' status: "{0}"' -f $d.status))
[void]$sb.AppendLine((' path: {0}' -f $d.path))
}
Write-Output $sb.ToString()
[Console]::Error.WriteLine("Indexed $($docs.Count) documents.")