Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cool suggestions #19

Open
couleurm opened this issue Nov 29, 2022 · 1 comment
Open

Cool suggestions #19

couleurm opened this issue Nov 29, 2022 · 1 comment

Comments

@couleurm
Copy link

couleurm commented Nov 29, 2022

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

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

@couleurm
Copy link
Author

Update: got ambitious about the two last points and made couleur-tweak-tips/Show-ModuleTree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant