Skip to content

Commit

Permalink
Merge pull request #68 from Stephanevg/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Stephanevg authored Dec 13, 2018
2 parents 2914476 + 238ec9e commit 9569915
Show file tree
Hide file tree
Showing 54 changed files with 2,725 additions and 696 deletions.
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

PSClassUtils/Functions/Private/Out-CUPSGraph.1.ps1
Tests/woop.ps1
Tests/test_graph.ps1
PSClassUtils/Classes/Private/00_CUClassParameter.psm1
Tests/plop.ps1
Tests/wap.psm1
.vscode/launch.json
PSClassUtils/Functions/Private/Out-CUPSGraph.ps1
Tests/woop.png
PSClassUtils/Functions/Private/Out-CUPSGraph.ps1
8 changes: 4 additions & 4 deletions CI/02_Install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Register-PackageSource -Name Chocolatey -ProviderName Chocolatey -Location http:
Find-Package graphviz -Source "http://chocolatey.org/api/v2/" | Install-Package -ForceBootstrap -Force;
Start-Sleep -Seconds 2;

Install-PackageProvider -Name NuGet -Force;
Install-Module -Name PSGraph -Force -verbose;
Install-Module -Name PSScriptAnalyzer -Force;
Install-Module -Name Pester -Force -verbose;
Install-PackageProvider -Name NuGet -Force -Scope "CurrentUser";
Install-Module -Name PSGraph -Force -verbose -Scope "CurrentUser";
Install-Module -Name PSScriptAnalyzer -Force -Scope "CurrentUser";
Install-Module -Name Pester -Force -verbose -Scope "CurrentUser";
22 changes: 18 additions & 4 deletions CI/03_Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,32 @@ if ($res.FailedCount -eq 0 -and $res.successcount -ne 0) {
}

if ($Localversion -le $GalleryVersion) {
Write-host "[$($env:APPVEYOR_REPO_BRANCH)] PsClassUtils version $($localversion) is identical with the one on the gallery. No upload done."
write-host "[$($env:APPVEYOR_REPO_BRANCH)] Module not deployed to the psgallery" -foregroundcolor Yellow;
Write-host "[$($env:APPVEYOR_REPO_BRANCH)][$($ModuleName)] $($moduleName) version $($localversion) is identical with the one on the gallery. No upload done."
write-host "[$($env:APPVEYOR_REPO_BRANCH)][$($ModuleName)] Module not deployed to the psgallery" -foregroundcolor Yellow;
}
Else {

If($env:APPVEYOR_REPO_COMMIT_MESSAGE -match '^push psgallery.*$'){

try{

publish-module -Name $ModuleName -NuGetApiKey $Env:PSgalleryKey -ErrorAction stop;
write-host "[$($env:APPVEYOR_REPO_BRANCH)][$($ModuleName)][$($LocalVersion)] Module successfully deployed to the psgallery" -foregroundcolor green;
}Catch{
write-host "[$($env:APPVEYOR_REPO_BRANCH)][$($ModuleName)][$($LocalVersion)] An error occured while publishing the module to the gallery" -foregroundcolor red;
write-host "[$($env:APPVEYOR_REPO_BRANCH)][$($ModuleName)][$($LocalVersion)] $_" -foregroundcolor red;
}
}else{
write-host "[$($env:APPVEYOR_REPO_BRANCH)][$($LocalVersion)] All checks passed, but module not deployed to the gallery. " -foregroundcolor green;
}

publish-module -Name $ModuleName -NuGetApiKey $Env:PSgalleryKey;
write-host "[$($env:APPVEYOR_REPO_BRANCH)] Module deployed to the psgallery" -foregroundcolor green;
}
}Else{
Write-host "[$($env:APPVEYOR_REPO_BRANCH)] Awesome, nothing to do more. If you want to upload to the gallery, please merge from dev into master"
Write-host "[$($env:APPVEYOR_REPO_BRANCH)][$($ModuleName)] Awesome, nothing to do more. If you want to upload to the gallery, please merge from dev into master: use 'push gallery' in commit message to master to publish the module."
}
}
else {
Write-host "[$($env:APPVEYOR_REPO_BRANCH)] Failed tests: $($res.failedcount) - Successfull tests: $($res.successcount)" -ForegroundColor Red
Write-host "[$($env:APPVEYOR_REPO_BRANCH)][$($ModuleName)] Failed tests: $($res.failedcount) - Successfull tests: $($res.successcount)" -ForegroundColor Red
}
20 changes: 20 additions & 0 deletions PSClassUtils/Classes/Private/00_CUClassParameter.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Class CUClassParameter {
[String]$Name
[String]$Type
hidden $Raw

CUClassParameter([String]$Name,[String]$Type){

$this.Name = $Name
$This.Type = $Type

}

CUClassParameter([String]$Name,[String]$Type,$Raw){

$this.Name = $Name
$This.Type = $Type
$this.Raw = $Raw

}
}
34 changes: 34 additions & 0 deletions PSClassUtils/Classes/Private/01_CUClassProperty.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Class CUClassProperty {
[String]$ClassName
[String]$Name
[String]$Type
[string]$Visibility
Hidden $Raw

CUClassProperty([String]$ClassName,[String]$Name,[String]$Type){

$this.ClassName = $ClassName
$this.Name = $Name
$this.Type = $Type

}

CUClassProperty([String]$ClassName,[String]$Name,[String]$Type,[String]$Visibility){

$this.ClassName = $ClassName
$this.Name = $Name
$this.Type = $Type
$this.Visibility = $Visibility

}

CUClassProperty([String]$ClassName,[String]$Name,[String]$Type,[String]$Visibility,$Raw){

$this.ClassName = $ClassName
$this.Name = $Name
$this.Type = $Type
$this.Visibility = $Visibility
$this.Raw = $Raw

}
}
25 changes: 25 additions & 0 deletions PSClassUtils/Classes/Private/02_CUClassMethod.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Class CUClassMethod {
[String]$ClassName
[String]$Name
[String]$ReturnType
[CUClassParameter[]]$Parameter
hidden $Raw
#hidden $Extent

CUClassMethod([String]$ClassName,[String]$Name,[String]$ReturnType,[CUClassParameter[]]$Parameter){
$this.ClassName = $ClassName
$this.Name = $Name
$This.ReturnType = $ReturnType
$This.Parameter = $Parameter
}

CUClassMethod([String]$ClassName,[String]$Name,[String]$ReturnType,[CUClassParameter[]]$Parameter,$Raw){
$this.ClassName = $ClassName
$this.Name = $Name
$This.ReturnType = $ReturnType
$This.Parameter = $Parameter
$This.Raw = $Raw
#$This.Extent = $Raw.Extent.Text
}

}
22 changes: 22 additions & 0 deletions PSClassUtils/Classes/Private/03_CUClassConstructor.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Class CUClassConstructor {
[String]$ClassName
[String]$Name
[CUClassParameter[]]$Parameter
hidden $Raw
#hidden $Extent

CUClassConstructor([String]$ClassName,[String]$Name,[CUClassParameter[]]$Parameter){
$this.ClassName = $ClassName
$this.Name = $Name
$This.Parameter = $Parameter
}

CUClassConstructor([String]$ClassName,[String]$Name,[CUClassParameter[]]$Parameter,$Raw){
$this.ClassName = $ClassName
$this.Name = $Name
$This.Parameter = $Parameter
$This.Raw = $Raw
#$This.Extent = $Raw.Extent.Text
}

}
22 changes: 22 additions & 0 deletions PSClassUtils/Classes/Private/04_1_ASTDocument.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Class ASTDocument {
[System.Management.Automation.Language.StatementAst[]]$Classes
[System.Management.Automation.Language.StatementAst[]]$Enums
$Source
$ClassName
Hidden $Raw

ASTDocument ([System.Management.Automation.Language.StatementAst[]]$Classes,[System.Management.Automation.Language.StatementAst[]]$Enums,$Source){
$This.Classes = $Classes
$This.Enums = $Enums
$This.Source = $Source
$This.ClassName = $Classes.Name
}

ASTDocument([System.Management.Automation.Language.StatementAst[]]$Classes,[System.Management.Automation.Language.StatementAst[]]$Enums,$Source,[System.Management.Automation.Language.ScriptBlockAst]$RawAST){
$This.Classes = $Classes
$This.Enums = $Enums
$This.Source = $Source
$This.ClassName = $Classes.Name
$This.Raw = $RawAST
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
Class ClassEnum {

[String]
$Name

[String[]]
$Member
[String]$Name
[String[]]$Member

ClassEnum([String]$Name,[String[]]$Member){
$this.Name = $Name
Expand Down
161 changes: 161 additions & 0 deletions PSClassUtils/Classes/Private/06_CUClass.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
Class CUClass {
[String]$Name
[CUClassProperty[]]$Property
[CUClassConstructor[]]$Constructor
[CUClassMethod[]]$Method
[Bool]$IsInherited = $False
[String]$ParentClassName
[System.IO.FileInfo]$Path
Hidden $Raw
#Hidden $Ast

CUClass($AST){

#$this.Raw = $RawAST
$this.Raw = $AST
$This.SetPropertiesFromAST()

}

CUClass ($Name,$Property,$Constructor,$Method){

$This.Name = $Name
$This.Property = $Property
$This.Constructor = $Constructor
$This.Method = $Method

}

CUClass ($Name,$Property,$Constructor,$Method,$AST){

$This.Name = $Name
$This.Property = $Property
$This.Constructor = $Constructor
$This.Method = $Method
$This.Raw = $AST

}


## Set Name, and call Other Set
[void] SetPropertiesFromAST(){

$This.Name = $This.Raw.Name
$This.Path = [System.IO.FileInfo]::new($This.Raw.Extent.File)
$This.SetConstructorFromAST()
$This.SetPropertyFromAST()
$This.SetMethodFromAST()

## Inheritence Check
If ( $This.Raw.BaseTypes ) {
$This.IsInherited = $True
$This.ParentClassName = $This.Raw.BaseTypes.TypeName.Name
}

}

## Find Constructors for the current Class
[void] SetConstructorFromAST(){

$Constructors = $null
$Constructors = $This.Raw.Members | Where-Object {$_.IsConstructor -eq $True}

Foreach ( $Constructor in $Constructors ) {

$Parameters = $null
$Parameters = $Constructor.Parameters
[CUClassParameter[]]$Paras = @()

If ( $Parameters ) {

Foreach ( $Parameter in $Parameters ) {

$Type = $null
# couldn't find another place where the returntype was located.
# If you know a better place, please update this! I'll pay you beer.
$Type = $Parameter.Extent.Text.Split("$")[0]
$Paras += [CUClassParameter]::New($Parameter.Name.VariablePath.UserPath, $Type)

}

}

$This.Constructor += [CUClassConstructor]::New($This.name,$Constructor.Name, $Paras,$Constructor)
}

}

## Find Methods for the current Class
[void] SetMethodFromAST(){

$Methods = $null
$Methods = $This.Raw.Members | Where-Object {$_.IsConstructor -eq $False}

Foreach ( $Method in $Methods ) {

$Parameters = $null
$Parameters = $Method.Parameters
[CUClassParameter[]]$Paras = @()

If ( $Parameters ) {

Foreach ( $Parameter in $Parameters ) {

$Type = $null
# couldn't find another place where the returntype was located.
# If you know a better place, please update this! I'll pay you beer.
$Type = $Parameter.Extent.Text.Split("$")[0]
$Paras += [CUClassParameter]::New($Parameter.Name.VariablePath.UserPath, $Type)

}

}

$This.Method += [CUClassMethod]::New($This.Name,$Method.Name, $Method.ReturnType, $Paras,$Method)
}

}

## Find Properties for the current Class
[void] SetPropertyFromAST(){

$Properties = $This.Raw.Members | Where-Object {$_ -is [System.Management.Automation.Language.PropertyMemberAst]}

If ($Properties) {

Foreach ( $Pro in $Properties ) {

If ( $Pro.IsHidden ) {
$Visibility = "Hidden"
} Else {
$visibility = "public"
}

$This.Property += [CUClassProperty]::New($This.Name,$pro.Name, $pro.PropertyType.TypeName.Name, $Visibility,$Pro)
}
}

}

## Return the content of Constructor
[CUClassConstructor[]]GetCUClassConstructor(){

return $This.Constructor

}

## Return the content of Method
[CUClassMethod[]]GetCUClassMethod(){

return $This.Method

}

## Return the content of Property
[CUClassProperty[]]GetCUClassProperty(){

return $This.Property

}

}
Loading

0 comments on commit 9569915

Please sign in to comment.