stephanevg / psclassutils Goto Github PK
View Code? Open in Web Editor NEWA set of utilities to work with Powershell Classes
Home Page: http://powershelldistrict.com/how-to-generate-a-uml-diagram-using-powershell/
A set of utilities to work with Powershell Classes
Home Page: http://powershelldistrict.com/how-to-generate-a-uml-diagram-using-powershell/
The issue seems to come from the 'Resolve-PAth' cmdlet, as it points it to --> C:\Windows\system32\Tests\woop.psm1' instead of the real path (in .\Tests\woop.psm folder of the module)
> Get-CUClassProperty -Path .\Tests\woop.psm1
Resolve-Path : Cannot find path 'C:\Windows\system32\Tests\woop.psm1' because it does not exist.
At C:\Users\taavast3\OneDrive\Repo\Projects\OpenSource\PSClassUtils\PSClassUtils\Functions\Public\Get-CUClass.ps1:72 char:56
+ ... $ClassParams.Path = (Get-Item (Resolve-Path $Path).Path). ...
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:\Windows\system32\Tests\woop.psm1:String) [Resolve-Path], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.ResolvePathCommand
In order to give some guidance to users that would open an issue to report a bug / and / or that would like to request a feature, we would like to offer them a predefined page, which simple questions, to:
Standardise the way issues are filled.
Offer a way to the end users to correctly express them self.
Avoid that developers ask more info, by ensure all the information needed is already in the issue when first created.
Example was submitted by dough finke in this PR:
#8
title
since the introduction of excludes, It is possible for example to add only a few classes in a specific export which would represent a thing of my class models.
Often, I want to give them another name then the one of the file where I got it from. Therefor I would like to introduce the possibility to add the output name.
I am bit unsure of how we should call this parameter.
Here are a few Suggestions:
-Name | -FileName | -OutputFileName
Please advise
Quand tu fais dans tes tests Pester un (Get-Command Install-CUDiagramPrerequisites).Parameters.keys -contains "proxy" le résultat est toujours vrai quelque soit la valeur que tu mets à la place de proxy.
Pour être certain qu'il test bien la présence du bon paramètre il faut ajouter | Should Be $true
cela donne
(Get-Command Install-CUDiagramPrerequisites).Parameters.keys -contains "proxy" | Should Be $true
et la effectivement si tu mets autre chose que proxy tu recois une erreur
I would like to add the possiblity to get class information of classes located in files.
For this, adding -Path parameter seems to be the best solution.
The parameter should be added to the following functions:
The -Path parameter should be allowed to receive only
either .ps1
or .psm1
files, any other types should be ignored.
As suggested by @LxLeChat we could make -Path accept pipelineinput, and set an alias on it. It will allow us to avoid an extra complicated design choise, and handle folder input.
It will also make the cmdlet more user friendly, as one could use it like this:
Get-ChildItem -Path C:\MyFolderWithClasses\ -Recurse | Get-CuXXX
Also, what should not be forgoten, is that currently, the Get-CUXXX
cmdlets have only one parameter -ClassName
and it should be kept.
When no -Path is passed, the -ClassName should look into the current loaded classes (current existing code).
When -ClassName
& -Path
are together, -ClassName
should filter the file out, that has a class having the name $ClassName
This functionality has already been implmemented in
Write-CUClassDiagram
as in the following snippet:
$PathObject = Get-Item $Path
if ($PathObject -is [System.IO.DirectoryInfo]) {
$ExportFileName = "Diagram" + "." + $OutputFormat
$FolderPath = $Path
if ($Recurse) {
$AllItems = Get-ChildItem -path "$($Path)\*" -Include "*.ps1", "*.psm1" -Recurse
} else {
$AllItems = Get-ChildItem -path "$($Path)\*" -Include "*.ps1", "*.psm1"
}
#$Path = $null
}
elseif ($PathObject -is [System.IO.FileInfo]) {
[System.IO.FileInfo]$File = (Resolve-Path -Path $Path).Path
$ExportFileName = $File.BaseName + "." + $OutputFormat
$AllItems = $File
}
else {
throw 'Path provided was not a file or folder'
}
and we could reuse this to save some time.
(A switch would be even better ;))
i would imagine that the return type should be extended as well. I could see something similar to this:
Source | ClassName | Object |
---|---|---|
[System.IO.FileInfo] | TheNameOfTheClass |
The object request |
C:\Files\Myclass.ps1 | CustomUser | [CUClass] |
Once we agree on the design, I will create individual issues per function, so work could be done by severals persons in parallel.
`
Fixing #10 Raised another side effect:
splines='ortho' allows to specifiy that the edges have a straight line style, instead of a curved one:
when setting:
$Graph = Graph -ScriptBlock {
(No attributes are added)
we have the correct result (but with 'curved' lines)
$Graph = Graph -Attributes @{splines='ortho'} -ScriptBlock {
Attributes @{splines='ortho'}
is added
Generates the following graph:
The issue, is that without splines=ortho the graph looks really messy when there are a lot of edges involved.
This works:
Write-CUClassDiagram -FolderPath C:\Users\plop\OneDrive\Scripting\Repository\Projects\OpenSource\PowershellClassUtils\Classes\
this throws an System Error:
Write-CUClassDiagram -FolderPath .\Classes
Export-PSGraph : System error.
At C:\Users\plop\OneDrive\Scripting\Repository\Projects\OpenSource\PowershellClassUtils\Functions\public\Write-CUClassDiagram.ps1:293 char:24
+ ... = $Graph | Export-PSGraph -DestinationPath $FullExportPath -OutputF ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Write-Error], ParseException
+ FullyQualifiedErrorId : System.Management.Automation.ParseException,Export-PSGraph
Add a wiki section:
IIt would be great to have the informations coming from #15 to the page, so that people have an easy to go help system.
You can fork it from here.
https://github.com/Stephanevg/PSClassUtils/wiki
Simply add a filter on the gci forcing it retrieve only psm1 or ps1 files.
Other other types should be ignored.
Static methods / properties should be underlined in the diagram.
See example here --> https://dfinke.github.io/powershell,%20design%20patterns/2018/04/13/PowerShell-And-Design-Patterns.html
I would like to update the following functions to not only show 'only loaded' classes, but also get the same class information from a class located in a file.
The following functions should be enhanced:
These are the technical details I think this could work at best:
Add Parameter: -Path
I think the best and easiest way for that, would be to add a call to Get-CUAST in each of these functions, and add some filtering.
This could also mean, that by extension, Get-CUAST might need some need options - Will see.
Add the possiblity to exclude an array of classes from beeing drawned to the png file.
Add examples of your ClassDiagrams, and show the world, how cool your Classes are.
Edit
All issues related to Linux support are tracked here --> https://github.com/Stephanevg/PSClassUtils/projects/5
Hi all,
I think it is about time we takle the cross platformness of this module.
I belive we dont have anything that is blocking us from running this module on Linux / MacOSx, but I can't say for sure. I know that @tigerfansga has been using the module on Linux, but unsure on how sucessfully he was (You perhaps have some info to share with us?)
It would be great if someone could try this module out on a linux and/or macos box.
Perhaps, we could also add a Pester test or two, which would test if the module works on Windows, Linux and MacOSx.
Perhaps this means changing the CI? I am open for the discussion. @bateskevin Any insights on this one?
While scanning this file:
The following class:
from this file:
https://github.com/Stephanevg/PSHTML/blob/master/Code/Classes/001.pshtml.utilities.configuration.ps1
contains only static methods, but in the diagram, are not showed as static.
We have reached a level of complexity which makes maintaining (addind a parameter or so) to write-CUClassDiagram
pretty difficult.
I would like to open a discussion on how we could simplify this.
Paths we should consider:
Consider creating an abastract syntax tree visulisation for scripts:
Ideally, I would imagine a command having the following syntax:
Write-CUAbastractSyntaxTree -Path * -ExportPath
-Path
: should be capable of handeling FileInfo, FolderInfo, and strings as inputs (just like Write-CUClassDiagram),
-ExportPath
: Should default to the current directory.
If no name is specified, it should be 'ScriptName.AbastractSyntaxTree.png'
By default, it should create one image per script file (to avoid a clustered image).
some information on AST:
https://geekeefy.wordpress.com/2017/06/07/powershell-tokenization-and-abstract-syntax-tree/
PS C:\Users\taavast3> Write-CUClassDiagram -Path C:\MyHomeRepos\PSHTML\PSHTML\Classes\Public\Chart.ps1 -Show
The module PSGraph is a prerequisite for this script to work. Please Install PSGraph first using Install-Module PSGraph
At C:\MyHomeRepos\PSClassUtils\PSClassUtils\Functions\Public\Write-CUClassDiagram.ps1:113 char:13
+ throw 'The module PSGraph is a prerequisite for this scri ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (The module PSGr...-Module PSGraph:String) [], RuntimeException
+ FullyQualifiedErrorId : The module PSGraph is a prerequisite for this script to work. Please Install PSGraph first using Install-Module PSGraph
I want to add the Switch -FolderPath
It should get all the Classes located in the various scripts, and generate a diagram from the complete solution
currently, the following functions return a specifc, dilated, information from the AST.
** Edit **
After dfiscussions, we thought it would be interesting to add the following parameters as well:
Also, we want to extend the ASTDocument to return the Name of the class
I think it could be itnerested, to offer the possibility to instead return the specific types (properietary of the modules) that we could return the RAW AST object back.
Do you think this could be something usefull?
I am planning to refactor the complete code of Write-CUClassDiagram in order to seperate some of the bits, and isolate them for easier testability.
More details will follow.
Make it available to people behind a proxy.
This should not be that complicated, as the ASTDocument returns the following object:
The Enum property, contains an array of 'ClassEnums' (Which is defined here)
In the readme.md maybe you should change the install part from:
Find-Module PSClassUtils | Install-Module PSClassUtils
to:
Find-Module PSClassUtils | Install-Module
else an error is thrown !
having parameter $Path and $FolderPath is cumbersome for the end user.
Perhaps it make sense to add a little bit of logic, and get rid of the FolderPath
parameter.
Function Write-CUClassDiagram {
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true,ParameterSetName='File')]
[ValidateScript({
test-Path $_
})]
[String]
$Path,
[Parameter(Mandatory=$true,ParameterSetName='Folder')]
[ValidateScript({
test-Path $_
})]
[String]
$FolderPath,
[Parameter(Mandatory=$False,ParameterSetName='Folder')]
[Switch]
$Recurse,
This might have side effects on:
there is an issue with the 'edge' cmdlet of PSGraph. This one only accept 'exect' case sensitivy.
The example below will NOT display properly
Class Parent {
}
Class Child1 : parent {
}
The following work (Look closley at the Case sensitivty of 'Parent' in Child1:
Class Parent {
}
Class Child1 : Parent {
}
I opened a ticket to try and made 'edge' case insensitive.
Analyze if we could simplify how we generate the command to Out-PSGraph using the Command Pattern
For the ones that are unfamiliar with the pattern, I recommend watching these videos:
-> https://www.youtube.com/watch?v=7Pj5kAhVBlg
This one is a bit longer, but also very good.
-> https://www.youtube.com/watch?v=9qA5kw8dcSU
Ideally I would like to discuss the design of a possible solution. Please send UML (ish) diagrams via photo or so.
Add examples of your ClassDiagrams, and show the world, how cool your Classes are.
All commandlets have Comment based help + examples
It would be great to have help extracted into individual markdown pages (using PlatyPS for example).
It would be interesting if we could choose on which scope we want to install the prerequisites modules
It would be nice to have the possibility to select 'ONLY' the classes we would like to have in the export.
Filtering on the script file name doesn't help in all cases, as some files have more than one class in it.
Write-CUClassDiagram -Include "*Asset","Setting*" -Show
It should return classes (and enums) that have Either 'Asset' or 'Setting' in their name.
'Include' might be the wrong wording. The idea is to be able to 'select' the ones we want to output.
Perhaps a '-FilterScript' could be a path to dig?
I have a draft of this on a local branch. I'll push a first version soon.
It seems that with version 2.3.0, the -Show broke.
> Write-CUClassDiagram -Path C:\Users\taavast3\OneDrive\Repo\Projects\OpenSource\PSHTML\Code\Classes\001.pshtml.utilities.configuration.ps1 -Show
Directory: C:\Users\taavast3\OneDrive\Repo\Projects\OpenSource\PSHTML\Code\Classes
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 1/25/2019 2:00 PM 125319 001.pshtml.utilities.configuration.png
It doesn't open the file
Add a function that utilises the existing classes to generate basic Pester tests for Powershell classes.
I genreated tests to test if the properties have the correct type for example.
Add support to filter on specific Method.
This filter should work either with -Path, or with -Raw
Hello Stephane,
Maybe we can add a simple property to the ASTDocument class called "ClassName".
Depending on the direction you are willing to take regarding #47 this could be useful, because i see that Get-CUClassConstructor, Get-CUClassMethod, Get-CUClassProperty take "classname" as theirs primary argument.
Add examples of your ClassDiagrams, and show the world, how cool your Classes are.
Add pipeline support for the parameter -Path
In my class I use an ENUM "company" which is stored in a ps1 file.
In the file pester during the test "It '[User] - [Constructor]" he expects a parameter of the type COMPANY but he does not know this type since for the test he does not load my file with my ENUM
+ [COMPANY] $ Company
+ ~~~~~~~
Unable to find type [COMPANY]
I don't know if I'm clear :-)
Implement this --> #8
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.