Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function Add-ContentFromItem {
function Add-ContentFromItem {
<#
.SYNOPSIS
Add the content of a folder or file to the root module file.
Expand All @@ -22,13 +22,10 @@
[Parameter(Mandatory)]
[string] $RootPath
)
# Get the path separator for the current OS
$pathSeparator = [System.IO.Path]::DirectorySeparatorChar
$separators = [char[]]@([System.IO.Path]::DirectorySeparatorChar, [System.IO.Path]::AltDirectorySeparatorChar)

$relativeFolderPath = $Path -replace $RootPath, ''
$relativeFolderPath = $relativeFolderPath -replace $file.Extension, ''
$relativeFolderPath = $relativeFolderPath.TrimStart($pathSeparator)
$relativeFolderPath = $relativeFolderPath -split $pathSeparator | ForEach-Object { "[$_]" }
$relativeFolderPath = [System.IO.Path]::GetRelativePath($RootPath, $Path)
$relativeFolderPath = $relativeFolderPath.Split($separators, [System.StringSplitOptions]::RemoveEmptyEntries) | ForEach-Object { "[$_]" }
$relativeFolderPath = $relativeFolderPath -join ' - '

Add-Content -Path $RootModuleFilePath -Force -Value @"
Expand All @@ -37,11 +34,11 @@ Write-Debug "[`$scriptName] - $relativeFolderPath - Processing folder"
"@

$files = $Path | Get-ChildItem -File -Force -Filter '*.ps1' | Sort-Object -Property FullName

foreach ($file in $files) {
$relativeFilePath = $file.FullName -replace $RootPath, ''
$relativeFilePath = $relativeFilePath -replace $file.Extension, ''
$relativeFilePath = $relativeFilePath.TrimStart($pathSeparator)
$relativeFilePath = $relativeFilePath -split $pathSeparator | ForEach-Object { "[$_]" }
$relativeFilePath = [System.IO.Path]::GetRelativePath($RootPath, $file.FullName)
$relativeFilePath = [System.IO.Path]::ChangeExtension($relativeFilePath, $null).TrimEnd('.')
$relativeFilePath = $relativeFilePath.Split($separators, [System.StringSplitOptions]::RemoveEmptyEntries) | ForEach-Object { "[$_]" }
$relativeFilePath = $relativeFilePath -join ' - '

Add-Content -Path $RootModuleFilePath -Force -Value @"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@
[System.IO.DirectoryInfo] $ModuleOutputFolder
)

# Get the path separator for the current OS
$pathSeparator = [System.IO.Path]::DirectorySeparatorChar
$separators = [char[]]@([System.IO.Path]::DirectorySeparatorChar, [System.IO.Path]::AltDirectorySeparatorChar)

Set-GitHubLogGroup 'Build root module' {
$rootModuleFile = New-Item -Path $ModuleOutputFolder -Name "$ModuleName.psm1" -Force
Expand Down Expand Up @@ -185,22 +184,21 @@ Write-Debug "[$scriptName] - [data] - Done"
)

foreach ($scriptFolder in $scriptFoldersToProcess) {
$scriptFolder = Join-Path -Path $ModuleOutputFolder -ChildPath $scriptFolder
if (-not (Test-Path -Path $scriptFolder)) {
$scriptFolderPath = Join-Path -Path $ModuleOutputFolder -ChildPath $scriptFolder
if (-not (Test-Path -Path $scriptFolderPath)) {
continue
}
Add-ContentFromItem -Path $scriptFolder -RootModuleFilePath $rootModuleFile -RootPath $ModuleOutputFolder
Remove-Item -Path $scriptFolder -Force -Recurse
Add-ContentFromItem -Path $scriptFolderPath -RootModuleFilePath $rootModuleFile -RootPath $ModuleOutputFolder
Remove-Item -Path $scriptFolderPath -Force -Recurse
}
#endregion - Add content from subfolders

#region - Add content from *.ps1 files on module root
$files = $ModuleOutputFolder | Get-ChildItem -File -Force -Filter '*.ps1' | Sort-Object -Property FullName
foreach ($file in $files) {
$relativePath = $file.FullName -replace $ModuleOutputFolder, ''
$relativePath = $relativePath -replace $file.Extension, ''
$relativePath = $relativePath.TrimStart($pathSeparator)
$relativePath = $relativePath -split $pathSeparator | ForEach-Object { "[$_]" }
$relativePath = [System.IO.Path]::GetRelativePath($ModuleOutputFolder, $file.FullName)
$relativePath = [System.IO.Path]::ChangeExtension($relativePath, $null).TrimEnd('.')
$relativePath = $relativePath.Split($separators, [System.StringSplitOptions]::RemoveEmptyEntries) | ForEach-Object { "[$_]" }
$relativePath = $relativePath -join ' - '

Add-Content -Path $rootModuleFile -Force -Value @"
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/Lint-Repository.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ jobs:
GITHUB_TOKEN: ${{ github.token }}
DEFAULT_WORKSPACE: ${{ fromJson(env.Settings).WorkingDirectory }}
FILTER_REGEX_INCLUDE: ${{ fromJson(env.Settings).WorkingDirectory }}
FILTER_REGEX_EXCLUDE: ${{ fromJson(env.Settings).WorkingDirectory }}/src/classes/public/.*\.ps1$
ENABLE_GITHUB_ACTIONS_STEP_SUMMARY: false
SAVE_SUPER_LINTER_SUMMARY: true

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/Linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
uses: super-linter/super-linter@4ce20838b8ab83717e78138c5b3a1407148e0918 # v8.7.0
env:
GITHUB_TOKEN: ${{ github.token }}
FILTER_REGEX_EXCLUDE: 'tests/src(TestRepo|WithManifestTestRepo)/src/classes/public/.*\.ps1$'
VALIDATE_BIOME_FORMAT: false
VALIDATE_GITHUB_ACTIONS: false
VALIDATE_JSCPD: false
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/Release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ on:
- synchronize
- labeled
paths:
- '.github/actions/**'
- '.github/workflows/**'
- '!.github/workflows/Release.yml'
- '!.github/workflows/Linter.yml'
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/Workflow-Test-Default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
workflow_dispatch:
pull_request:
paths:
- '.github/actions/**'
- '.github/workflows/**'
- '!.github/workflows/Release.yml'
- '!.github/workflows/Linter.yml'
Expand Down Expand Up @@ -43,4 +44,5 @@ jobs:
ImportantFilePatterns: |
^src/
^README\.md$
^\.github/actions/
^\.github/workflows/(?!Release\.yml$|Linter\.yml$)
2 changes: 2 additions & 0 deletions .github/workflows/Workflow-Test-WithManifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
workflow_dispatch:
pull_request:
paths:
- '.github/actions/**'
- '.github/workflows/**'
- '!.github/workflows/Release.yml'
- '!.github/workflows/Linter.yml'
Expand Down Expand Up @@ -43,4 +44,5 @@ jobs:
ImportantFilePatterns: |
^src/
^README\.md$
^\.github/actions/
^\.github/workflows/(?!Release\.yml$|Linter\.yml$)
11 changes: 11 additions & 0 deletions tests/srcTestRepo/src/classes/public/ActiveLoanRegister.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class ActiveLoanRegister {
[System.Collections.Generic.List[BookLoan]] $Loans

ActiveLoanRegister() {
$this.Loans = [System.Collections.Generic.List[BookLoan]]::new()
}

[void] AddLoan([BookLoan]$Loan) {
$this.Loans.Add($Loan)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class AlphaCirculationNode {
[string] $Id
[ZetaCirculationNode] $Next

AlphaCirculationNode([string]$Id, [ZetaCirculationNode]$Next) {
$this.Id = $Id
$this.Next = $Next
}
}
11 changes: 11 additions & 0 deletions tests/srcTestRepo/src/classes/public/AuthorIndex.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class AuthorIndex {
[string] $Name
[AuthorProfile[]] $Authors
[ZCatalog] $Catalog

AuthorIndex([string]$Name, [ZCatalog]$Catalog) {
$this.Name = $Name
$this.Catalog = $Catalog
$this.Authors = @()
}
}
9 changes: 9 additions & 0 deletions tests/srcTestRepo/src/classes/public/AuthorProfile.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class AuthorProfile {
[string] $Name
[Book[]] $PublishedBooks

AuthorProfile([string]$Name, [Book[]]$PublishedBooks) {
$this.Name = $Name
$this.PublishedBooks = $PublishedBooks
}
}
87 changes: 0 additions & 87 deletions tests/srcTestRepo/src/classes/public/Book.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -44,93 +44,6 @@
}
}

class BookList {
# Static property to hold the list of books
static [System.Collections.Generic.List[Book]] $Books
# Static method to initialize the list of books. Called in the other
# static methods to avoid needing to explicit initialize the value.
static [void] Initialize() { [BookList]::Initialize($false) }
static [bool] Initialize([bool]$force) {
if ([BookList]::Books.Count -gt 0 -and -not $force) {
return $false
}

[BookList]::Books = [System.Collections.Generic.List[Book]]::new()

return $true
}
# Ensure a book is valid for the list.
static [void] Validate([book]$Book) {
$Prefix = @(
'Book validation failed: Book must be defined with the Title,'
'Author, and PublishDate properties, but'
) -join ' '
if ($null -eq $Book) { throw "$Prefix was null" }
if ([string]::IsNullOrEmpty($Book.Title)) {
throw "$Prefix Title wasn't defined"
}
if ([string]::IsNullOrEmpty($Book.Author)) {
throw "$Prefix Author wasn't defined"
}
if ([datetime]::MinValue -eq $Book.PublishDate) {
throw "$Prefix PublishDate wasn't defined"
}
}
# Static methods to manage the list of books.
# Add a book if it's not already in the list.
static [void] Add([Book]$Book) {
[BookList]::Initialize()
[BookList]::Validate($Book)
if ([BookList]::Books.Contains($Book)) {
throw "Book '$Book' already in list"
}

$FindPredicate = {
param([Book]$b)

$b.Title -eq $Book.Title -and
$b.Author -eq $Book.Author -and
$b.PublishDate -eq $Book.PublishDate
}.GetNewClosure()
if ([BookList]::Books.Find($FindPredicate)) {
throw "Book '$Book' already in list"
}

[BookList]::Books.Add($Book)
}
# Clear the list of books.
static [void] Clear() {
[BookList]::Initialize()
[BookList]::Books.Clear()
}
# Find a specific book using a filtering scriptblock.
static [Book] Find([scriptblock]$Predicate) {
[BookList]::Initialize()
return [BookList]::Books.Find($Predicate)
}
# Find every book matching the filtering scriptblock.
static [Book[]] FindAll([scriptblock]$Predicate) {
[BookList]::Initialize()
return [BookList]::Books.FindAll($Predicate)
}
# Remove a specific book.
static [void] Remove([Book]$Book) {
[BookList]::Initialize()
[BookList]::Books.Remove($Book)
}
# Remove a book by property value.
static [void] RemoveBy([string]$Property, [string]$Value) {
[BookList]::Initialize()
$Index = [BookList]::Books.FindIndex({
param($b)
$b.$Property -eq $Value
}.GetNewClosure())
if ($Index -ge 0) {
[BookList]::Books.RemoveAt($Index)
}
}
}

enum Binding {
Hardcover
Paperback
Expand Down
11 changes: 11 additions & 0 deletions tests/srcTestRepo/src/classes/public/BookCopy.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class BookCopy {
[string] $InventoryId
[Book] $Book
[ShelfLocation] $Location

BookCopy([string]$InventoryId, [Book]$Book, [ShelfLocation]$Location) {
$this.InventoryId = $InventoryId
$this.Book = $Book
$this.Location = $Location
}
}
11 changes: 11 additions & 0 deletions tests/srcTestRepo/src/classes/public/BookInventory.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class BookInventory {
[string] $Name
[BookCopy[]] $Copies
[ZCatalog] $Catalog

BookInventory([string]$Name, [ZCatalog]$Catalog) {
$this.Name = $Name
$this.Catalog = $Catalog
$this.Copies = @()
}
}
57 changes: 57 additions & 0 deletions tests/srcTestRepo/src/classes/public/BookList.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
class BookList {
static [System.Collections.Generic.List[Book]] $Books

static [void] Initialize() { [BookList]::Initialize($false) }
static [bool] Initialize([bool]$force) {
if ([BookList]::Books.Count -gt 0 -and -not $force) {
return $false
}

[BookList]::Books = [System.Collections.Generic.List[Book]]::new()

return $true
}

static [void] Validate([Book]$Book) {
$Prefix = @(
'Book validation failed: Book must be defined with the Title,'
'Author, and PublishDate properties, but'
) -join ' '
if ($null -eq $Book) { throw "$Prefix was null" }
if ([string]::IsNullOrEmpty($Book.Title)) { throw "$Prefix Title wasn't defined" }
if ([string]::IsNullOrEmpty($Book.Author)) { throw "$Prefix Author wasn't defined" }
if ([datetime]::MinValue -eq $Book.PublishDate) { throw "$Prefix PublishDate wasn't defined" }
}

static [void] Add([Book]$Book) {
[BookList]::Initialize()
[BookList]::Validate($Book)
if ([BookList]::Books.Contains($Book)) { throw "Book '$Book' already in list" }

$findPredicate = {
param([Book]$b)

$b.Title -eq $Book.Title -and
$b.Author -eq $Book.Author -and
$b.PublishDate -eq $Book.PublishDate
}.GetNewClosure()
if ([BookList]::Books.Find($findPredicate)) { throw "Book '$Book' already in list" }

[BookList]::Books.Add($Book)
}

static [void] Clear() {
[BookList]::Initialize()
[BookList]::Books.Clear()
}

static [Book] Find([scriptblock]$Predicate) {
[BookList]::Initialize()
return [BookList]::Books.Find($Predicate)
}

static [Book[]] FindAll([scriptblock]$Predicate) {
[BookList]::Initialize()
return [BookList]::Books.FindAll($Predicate)
}
}
13 changes: 13 additions & 0 deletions tests/srcTestRepo/src/classes/public/BookLoan.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class BookLoan {
[BookCopy] $Copy
[MemberAccount] $Member
[datetime] $LoanDate
[datetime] $DueDate

BookLoan([BookCopy]$Copy, [MemberAccount]$Member, [DueDatePolicy]$Policy) {
$this.Copy = $Copy
$this.Member = $Member
$this.LoanDate = Get-Date
$this.DueDate = $this.LoanDate.AddDays($Policy.StandardLoanDays)
}
}
11 changes: 11 additions & 0 deletions tests/srcTestRepo/src/classes/public/BranchLibrary.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class BranchLibrary {
[string] $Code
[string] $Name
[OpeningHours] $Hours

BranchLibrary([string]$Code, [string]$Name, [OpeningHours]$Hours) {
$this.Code = $Code
$this.Name = $Name
$this.Hours = $Hours
}
}
9 changes: 9 additions & 0 deletions tests/srcTestRepo/src/classes/public/CatalogSection.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class CatalogSection {
[string] $Name
[Book[]] $Books

CatalogSection([string]$Name, [Book[]]$Books) {
$this.Name = $Name
$this.Books = $Books
}
}
9 changes: 9 additions & 0 deletions tests/srcTestRepo/src/classes/public/DueDatePolicy.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class DueDatePolicy {
[int] $StandardLoanDays
[int] $GraceDays

DueDatePolicy([int]$StandardLoanDays, [int]$GraceDays) {
$this.StandardLoanDays = $StandardLoanDays
$this.GraceDays = $GraceDays
}
}
Loading
Loading