pwsh-prelude
pwsh-prelude copied to clipboard
Cool suggestions
Hey, I'm looking for cool stuff to add/make to my ""module"" and I really like Prelude, might snag some of your useful functions :-)
Some ideas popped in my head that I'd see you me and you using/making, consider that a suggestion and/or a PR if I end up making it some of that stuff myself
Function dependency parser using AST
Extract a minimal amount of functions out of a module without breaking stuff to get a single function working (could support multiple in the future 🤷♂️)
You give it a function name you've got declared/imported, and files/directories/modules to search in, I've messed with AST to make it work like this:
$Block = {
Invoke-Pack @Thing
Invoke-Unpack @Stuff
}
$TL_FUNCTIONS = ('Invoke-Pack', 'Invoke-Unpack')
$AST = [System.Management.Automation.Language.Parser]::ParseInput($Block, [ref]$null, [ref]$null)
$DepMatches = $AST.FindAll({
param ($node)
$node.GetType().Name -eq 'CommandAst'
}, $true) | #It gets all cmdlets from the Abstract Syntax Tree
ForEach-Object {$_.CommandElements[0].Value} | # Returns their name
Where-Object { # Filters out only TweakList functions
$_ -In $TL_FUNCTIONS
} | Select-Object -Unique
return $DepMatches
I've made something like this that may work better, see Get-FunctionContent, you probably will want to use -ReturnNames to make it more convenient to use
Markdown tree-style display for your module
^ Each folders add a `t, each file is parsed to find the functions it contains with AST (or check which new functions exist compared to before dot sourcing it), then use Get-Help to get it's <# .SYNOPSIS #> to add as a description after the * $_.Name -
Example
- /Modules/
- /Public/
- File.ps1
- Func Invoke-Pack - Function that will serialize one or more files into a single XML file. Use Invoke-Unpack to restore files.
- Func Invoke-Unpack - cba getting it's synopsis, you get the point that'd be sick to automatically generate
- File.ps1
- /Public/
Example usecase: Generate that with CI in the part of a README, hyperlink everything with a permalink, and hyperlink Func to link to the
param(line
Replace wathever is between <--START_ID!--> and <--END_ID!--> flags in a README file
If you're using the function I explained last in your README with CI, you'd probably want to replace it in your README at a specific place, you could add a line that is a markdown comment that contains START_ and your $BLOCKNAME so you can have multiple replace blocks, so at every commit it's wiped fresh at the place you'd expect it to
Update: got ambitious about the two last points and made couleur-tweak-tips/Show-ModuleTree
@couleurm Wow. I am two years late to the party...feel free to use whatever you like. I am all about collaborating. I like your markdown tree idea (adding -Markdown flag would fit in well with the API IMO). Adding markdown output might actually make the tree function more useful (as a terminal display function, it is a little clunky and mostly inferior to other tools).
I like the README.md update idea too, but there is already a tool for something similar that I have used. The name escapes me presently...
In any case, you are probably way over all this. I just wanted to close the loop. Sorry for not noticing your comment sooner 😞