Skip to content

Commit d24e8a8

Browse files
author
James Brundage
committed
feat: MarkX can be a [PSModuleInfo] ( Fixes #107 )
1 parent b0443a7 commit d24e8a8

2 files changed

Lines changed: 50 additions & 5 deletions

File tree

‎MarkX.ps1‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,12 @@
5252
5353
All we need to do is add `MarkX` to the `.pstypenames` of an object.
5454
55-
When we provide a `[IO.FileInfo]` to MarkX, it is still a `[IO.FileInfo]`.
56-
When we provide a `[ScriptBlock]` to MarkX, it is still a `[ScriptBlock]`.
57-
When we provide a `[Management.Automation.CommandInfo]` to MarkX, it is still a `[Mangement.Automation.CommandInfo]`.
55+
This allows the object to maintain it's underlying capabilties.
56+
57+
* A `[IO.FileInfo]` is still a `[IO.FileInfo]`.
58+
* A `[IO.DirectoryInfo]` is a still a `[IO.DirectoryInfo]`.
59+
* A `[ScriptBlock]` is still a `[ScriptBlock]`.
60+
* A `[Management.Automation.CommandInfo]` is still a `[Mangement.Automation.CommandInfo]`.
5861
#>
5962
[Alias('Markdown','Get-Markdown')]
6063
param()
@@ -76,7 +79,8 @@ $markXProtoType = [PSCustomObject]@{PSTypename='MarkX'}
7679

7780
:nextInput foreach ($in in $AllInput) {
7881
if (
79-
$in -is [Management.Automation.CommandInfo]
82+
$in -is [Management.Automation.CommandInfo] -or
83+
$in -is [Management.Automation.PSModuleInfo]
8084
) {
8185
$inputObjects += $in
8286
continue nextInput
@@ -151,7 +155,8 @@ for ($inputNumber = 0; $inputNumber -lt $inputObjects.Count; $inputNumber++) {
151155
if (
152156
$inputObject -is [IO.DirectoryInfo] -or
153157
$inputObject -is [IO.FileInfo] -or
154-
$inputObject -is [Management.Automation.CommandInfo] -or
158+
$inputObject -is [Management.Automation.CommandInfo] -or
159+
$inputObject -is [Management.Automation.PSModuleInfo] -or
155160
$inputObject -is [ScriptBlock]
156161
) {
157162
$inputObject.pstypenames.insert(0,'MarkX')

‎Types/MarkX/Sync.ps1‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,53 @@ $markXProtoType = [PSCustomObject]@{PSTypeName='MarkX'}
1313

1414
$allMarkdown = @(:nextInput foreach ($md in $this.Input) {
1515
if ($md -isnot [string]) {
16+
if ($md -is [PSModuleInfo]) {
17+
# Since we have already decorated this type,
18+
# we need to get the underlying module path with reflection
19+
$modulePath = $md.GetType().GetProperty("Path").GetValue($md)
20+
if (-not $this.Header) {
21+
$this.Header = [Ordered]@{
22+
title = $md.name
23+
description = $md.description
24+
author = $md.author
25+
copyright = $md.copyright
26+
companyName = $md.companyName
27+
version = $md.version
28+
guid = $md.guid
29+
licenseUri = $md.licenseUri
30+
releaseNotes = $md.releaseNotes
31+
projectUri = $md.projectUri
32+
privateData = $md.privateData
33+
}
34+
}
35+
36+
@(
37+
"# $($md.name) @ $($md.version)"
38+
[Environment]::newline
39+
"## $($md.description)"
40+
41+
if ($md.privateData.PSData.PSIntro) {
42+
[Environment]::newline
43+
$md.PrivateData.PSData.PSIntro
44+
}
45+
elseif ($md.privateData.PSIntro) {
46+
[Environment]::newline
47+
$md.PrivateData.PSIntro
48+
}
49+
50+
)
51+
52+
$md = ($modulePath | Split-Path) -as [IO.DirectoryInfo]
53+
}
54+
1655
if ($md -is [IO.DirectoryInfo]) {
1756
$this |
1857
Add-Member NoteProperty '#Path' $md.Fullname -Force
1958
$this.Site = "$($md.FullName)"
2059
$this.Site.includes = $this.Include
2160
continue nextInput
2261
}
62+
2363
# If the markdown was a file
2464
if ($md -is [IO.FileInfo] -and
2565
# and it had a markdown extension

0 commit comments

Comments
 (0)