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
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ jobs:
Get-PackageProvider -Name NuGet -ForceBootstrap | Out-Null
Install-Module -Name Pester -RequiredVersion 5.7.1 -Scope CurrentUser -Force -SkipPublisherCheck -AllowClobber
Install-Module -Name PSScriptAnalyzer -RequiredVersion 1.25.0 -Scope CurrentUser -Force -SkipPublisherCheck -AllowClobber
Install-Module -Name DependsOn -Scope CurrentUser -Force -SkipPublisherCheck -AllowClobber

- name: Import module from source
shell: pwsh
Expand Down Expand Up @@ -111,7 +110,6 @@ jobs:
Get-PackageProvider -Name NuGet -ForceBootstrap | Out-Null
Install-Module -Name Pester -RequiredVersion 5.7.1 -Scope CurrentUser -Force -SkipPublisherCheck -AllowClobber
Install-Module -Name PSScriptAnalyzer -RequiredVersion 1.25.0 -Scope CurrentUser -Force -SkipPublisherCheck -AllowClobber
Install-Module -Name DependsOn -Scope CurrentUser -Force -SkipPublisherCheck -AllowClobber

- name: Import module from source
shell: powershell
Expand Down
164 changes: 1 addition & 163 deletions BuildTasks/BuildModule.Task.ps1
Original file line number Diff line number Diff line change
@@ -1,170 +1,11 @@

# namespaces for Move-Statement
using namespace System.Collections.Generic
using namespace System.IO
using namespace System.Management.Automation


# Temporarily added this here to be refactored/replaced by LDModuleBuilder Module
function Move-Statement
{
<#
.SYNOPSIS
Moves statements containing a specified token to the specified index in a file.
.DESCRIPTION
Move-Statement moves statements containing a specified token, to the specified index
in a file. This can be used when building a module to move any using directives and
#Requires statements to the top of a file.
.PARAMETER Path
Specifies the path to an item to get its contents.
.PARAMETER Type
Specifies the type of tokens to examine. Accepted values include "Comment" and "Keyword".
.PARAMETER Token
Specifies the contents to filter on when examining a supplied token.
.PARAMETER Index
Specifies the line to move a statement to. Each line in an item has a corresponding
index, starting from 0.
.EXAMPLE
Move-Statement -Path $Path -Type 'Comment', 'Keyword' -Token '#Requires', 'using' -Index 0

Moves any using directives or #Requires statements to the top of a file.
.NOTES
Copy/Paste from LDModuleBuilder
#>
[CmdletBinding(SupportsShouldProcess)]

param(
[Parameter(Mandatory,
Position = 0,
ValueFromPipeline,
ValueFromPipelineByPropertyName)]
[ValidateNotNullOrEmpty()]
[ValidateScript({ Test-Path -Path $PSItem })]
[string] $Path,

[Parameter(Position = 1,
ValueFromPipelineByPropertyName)]
[ValidateNotNullOrEmpty()]
[ValidateSet('Comment', 'Keyword')]
[string[]] $Type = ('Comment', 'Keyword'),

[Parameter(Position = 2,
ValueFromPipelineByPropertyName)]
[ValidateNotNullOrEmpty()]
[string[]] $Token = ('#Requires', 'using'),

[Parameter(Position = 3,
ValueFromPipelineByPropertyName)]
[ValidateNotNullOrEmpty()]
[int] $Index = 0
)

process
{
try
{
$statements = [SortedSet[String]]::new(
[StringComparer]::InvariantCultureIgnoreCase
)

Write-Verbose -Message "Reading content from $Path..."
$content = [List[String]] ([File]::ReadLines($Path))

Write-Verbose -Message "Tokenizing content from $Path..."
$tokens = [PSParser]::Tokenize($content, [ref] $null)

$match = $Token -join '|'

Write-Verbose -Message 'Matching tokens...'
Write-Verbose -Message "Type = [$Type]; Token = [$Token]"
$keywords = $tokens.Where({
$PSItem.Type -in $Type -and
$PSItem.Content -imatch "^(?:$match)"
})

if (-not $keywords) {
Write-Verbose -Message 'No matching tokens found! Returning...'
return
}

$offset = 1
foreach ($keyword in $keywords)
{
$line = $keyword.StartLine - $offset

Write-Verbose -Message "Moving [$($content[$line])] to Index [$Index]..."
$null = $statements.Add($content[$line]),
$content.RemoveAt($line)
$offset++
}

[string[]] $comments, [string[]] $statements = $statements.Where({
$PSItem -match '^#'
}, 'Split')

foreach ($item in ($statements, $comments))
{
$content.Insert($Index, '')
$content.InsertRange($Index, $item)
}

if ($PSCmdlet.ShouldProcess($Path, $MyInvocation.MyCommand.Name))
{
Write-Verbose -Message "Writing content to $Path..."
[File]::WriteAllLines($Path, $content)
}
}
catch
{
$PSCmdlet.ThrowTerminatingError($PSItem)
}
}
}

taskx BuildModule @{
Inputs = (Get-ChildItem -Path $Source -Recurse -Filter *.ps1)
Outputs = $ModulePath
Jobs = {
$sb = [Text.StringBuilder]::new()
$null = $sb.AppendLine('$Script:PSModuleRoot = $PSScriptRoot')

# Class importer
$root = Join-Path -Path $source -ChildPath 'Classes'
"Load classes from [$root]"
$classFiles = Get-ChildItem -Path $root -Filter '*.ps1' -Recurse |
Where-Object Name -notlike '*.Tests.ps1'

$classes = @{}

foreach($file in $classFiles)
{
$name = $file.BaseName
$classes[$name] = @{
Name = $name
Path = $file.FullName
}
$data = Get-Content $file.fullname
foreach($line in $data)
{
if($line -match "\s+($Name)\s*(:|requires)\s*(?<baseclass>\w*)|\[(?<baseclass>\w+)\]")
{
$classes[$name].Base += @($Matches.baseclass)
}
}
}

$importOrder = $classes.GetEnumerator() |
Resolve-DependencyOrder -Key {$_.Name} -DependsOn {$_.Value.Base}

foreach($class in $importOrder)
{
$classPath = $class.Value.Path
"Importing [$classPath]..."
$null = $sb.AppendLine("# .$classPath")
$null = $sb.AppendLine([IO.File]::ReadAllText($classPath))
}

foreach ($folder in ($Folders -ne 'Classes'))
foreach ($folder in $Folders)
{
if (Test-Path -Path "$Source\$folder")
{
Expand All @@ -186,8 +27,5 @@ taskx BuildModule @{
"Creating Module [$ModulePath]..."
$null = New-Item -Path (Split-path $ModulePath) -ItemType Directory -ErrorAction SilentlyContinue -Force
Set-Content -Path $ModulePath -Value $sb.ToString() -Encoding 'UTF8'

'Moving "#Requires" statements and "using" directives...'
Move-Statement -Path $ModulePath -Type 'Comment', 'Keyword' -Token '#Requires', 'using' -Index 0
}
}
2 changes: 1 addition & 1 deletion BuildTasks/InvokeBuildInit.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Write-Verbose " ManifestPath [$ManifestPath]" -Verbose
$Script:ModulePath = Join-Path -Path $Destination -ChildPath "$ModuleName.psm1"
Write-Verbose " ModulePath [$ModulePath]" -Verbose

$Script:Folders = 'Classes', 'Includes', 'Internal', 'Private', 'Public', 'Resources'
$Script:Folders = 'Includes', 'Internal', 'Private', 'Public', 'Resources'
Write-Verbose " Folders [$Folders]" -Verbose

$Script:TestFile = "$BuildRoot\Output\TestResults_PS$PSVersion`_$TimeStamp.xml"
Expand Down
20 changes: 0 additions & 20 deletions BuildTasks/Pester.Task.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
task Pester {
$requiredPercent = $Script:CodeCoveragePercent

$config = New-PesterConfiguration
$config.Run.Path = 'Tests'
$config.Run.PassThru = $true
Expand All @@ -10,27 +8,9 @@ task Pester {
$config.TestResult.OutputFormat = 'NUnitXml'
$config.TestResult.OutputPath = $testFile

if ($requiredPercent -gt 0.00)
{
$config.CodeCoverage.Enabled = $true
$config.CodeCoverage.Path = 'Output\*\*.psm1'
$config.CodeCoverage.OutputPath = 'Output\codecoverage.xml'
}

$results = Invoke-Pester -Configuration $config
if ($results.FailedCount -gt 0)
{
Write-Error -Message "Failed [$($results.FailedCount)] Pester tests."
}

if ($results.CodeCoverage.NumberOfCommandsAnalyzed -gt 0)
{
$codeCoverage = $results.CodeCoverage.NumberOfCommandsExecuted /
$results.CodeCoverage.NumberOfCommandsAnalyzed

if ($codeCoverage -lt $requiredPercent)
{
Write-Error ("Failed Code Coverage [{0:P}] below {1:P}" -f $codeCoverage, $requiredPercent)
}
}
}
6 changes: 0 additions & 6 deletions PSGraph/Data/Aliases.json

This file was deleted.

36 changes: 0 additions & 36 deletions PSGraph/PSGraph.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,6 @@ $Script:PSModuleRoot = $PSScriptRoot
Write-Verbose -Message "This file is replaced in the build output, and is only used for debugging."
Write-Verbose -Message $PSScriptRoot

# Class importer
# $root = '.\LDAppSettings\Classes'
$root = Join-Path -Path $PSScriptRoot -ChildPath 'Classes'
Write-Verbose "Load classes from [$root]"
$classFiles = Get-ChildItem -Path $root -Filter '*.ps1' -Recurse |
Where-Object Name -notlike '*.Tests.ps1'

$classes = @{}

# $file = $classFiles[3]
foreach($file in $classFiles)
{
$name = $file.BaseName
$classes[$name] = @{
Name = $name
Path = $file.FullName
}
$data = Get-Content $file.fullname
# $line = $data[0]
foreach($line in $data)
{
if($line -match "\s+($Name)\s*(:|requires)\s*(?<baseclass>\w*)|\[(?<baseclass>\w+)\]")
{
$classes[$name].Base += @($Matches.baseclass)
}
}
}

$importOrder = $classes.GetEnumerator() | Resolve-DependencyOrder -Key {$_.Name} -DependsOn {$_.Value.Base}

foreach( $class in $importOrder )
{
Write-Verbose $class.Value.Path
. $class.Value.Path
}

$folders = 'Includes', 'Internal', 'Private', 'Public', 'Resources'
foreach ($folder in $folders)
{
Expand Down
3 changes: 1 addition & 2 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ $Script:Modules = @(
'BuildHelpers',
'InvokeBuild',
'platyPS',
'PSScriptAnalyzer',
'DependsOn'
'PSScriptAnalyzer'
)

# Pinned explicitly: Pester 4.x and 5.x can be installed side by side, which
Expand Down
29 changes: 0 additions & 29 deletions deploy.PSDeploy.ps1

This file was deleted.

1 change: 0 additions & 1 deletion module.build.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
$Script:ModuleName = Get-ChildItem -Path (Join-Path $PSScriptRoot '*\*.psm1') |
Select-Object -ExpandProperty BaseName
$Script:CodeCoveragePercent = 0.0 # 0 to 1
. $PSScriptRoot\BuildTasks\InvokeBuildInit.ps1

task Default Build, Test, UpdateSource
Expand Down
20 changes: 0 additions & 20 deletions requirements.psd1

This file was deleted.

Loading