Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Badgerati/PSClass
PowerShell module to help determine class dependencies, and the order that you need to import them
https://github.com/Badgerati/PSClass
class cyclic dependency import order powershell
Last synced: 1 day ago
JSON representation
PowerShell module to help determine class dependencies, and the order that you need to import them
- Host: GitHub
- URL: https://github.com/Badgerati/PSClass
- Owner: Badgerati
- License: mit
- Created: 2019-09-30T21:55:23.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2019-10-02T18:32:53.000Z (about 5 years ago)
- Last Synced: 2024-10-12T21:06:33.945Z (26 days ago)
- Topics: class, cyclic, dependency, import, order, powershell
- Language: PowerShell
- Size: 8.79 KB
- Stars: 3
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# PSClass
This is a PowerShell module to help determine class dependencies, and also to determine the order that you need to import classes into your module.
## Install
You can install PSClass from the PowerShell Gallery
```powershell
Install-Module PSClass
```## Usage
All classes/enums need to be within a `/Classes` directory, and references to custom classes referenced as `[ClassA]`. Class names should also match the name of the PowerShell file - so a `ClassA` *must* be within a `ClassA.ps1` file.
For example, if you have some class `ClassA` and some other class `ClassB`, the PSClass will see `[ClassB]::Method()` and mark that it should be imported before `ClassA` automatically:
```powershell
class ClassA
{
static [void] SomeMethod()
{
[ClassB]::Method()
}
}
```Here, PSClass will know that `ClassB` needs to be imported before `ClassA`.
PSClass will see any `[...]` lines and use them to determine the order that classes/enums are required to be imported - as well as detecting cyclic dependencies.
> Classes/enums can be within sub-directories within the `/Classes` directory.
## Functions
### Get-PSClassOrder
```powershell
Get-PSClassOrder [-Path ]
```When run, this function will look for the `/Classes` folder at the `-Path` specified (default is the current path).
It will then return an array of the class/enum paths in the precise order that they should be imported:
```powershell
Get-PSClassOrder | ForEach-Object { . $_ }
```### Show-PSClassGraph
```powershell
Show-PSClassgraph [-Path ] [-Namespace ]
```Will return the full dependency graph of the classes/enums, or just the dependencies of the namespace specified. The namespace is the path to a class (with no extension), and the slashes are replaced for dots - such as `Tools.Helpers` for a class called `Helpers` at `/Classes/Tools/Helpers.ps1`.
### Test-PSClassCyclic
```powershell
Test-PSClassCyclic [-Path ] [-Namespace ]
```Will test for cyclic dependencies on a classes/enums. The namespace is the path to a class (with no extension), and the slashes are replaced for dots - such as `Tools.Helpers` for a class called `Helpers` at `/Classes/Tools/Helpers.ps1`.