Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modularization of Entra Powershell Module #1165

Open
wants to merge 115 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 101 commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
dd67223
Usability Params for Set-EntraUserExtension
emmanuel-karanja Oct 18, 2024
3cd2eb9
Added module splitter and psm1 builder
emmanuel-karanja Oct 21, 2024
92611df
Added module splitter and psm1 builder
emmanuel-karanja Oct 21, 2024
084601d
added moduleMapper.json
emmanuel-karanja Oct 21, 2024
64935a0
added runner script and typedefs
emmanuel-karanja Oct 21, 2024
79a2a4f
Added Comments
emmanuel-karanja Oct 21, 2024
230b98d
Added WriteModuleManifest
emmanuel-karanja Oct 21, 2024
a312a45
changed name to Create-EntraModule
emmanuel-karanja Oct 21, 2024
81c1d9a
Added CreateModuleHelp
emmanuel-karanja Oct 21, 2024
06a0a04
fixed the help generation code
emmanuel-karanja Oct 21, 2024
c7d0a91
Fixed the runner script
emmanuel-karanja Oct 21, 2024
6146040
added dependency mapping
emmanuel-karanja Oct 21, 2024
0b61ead
Added dependency mapping.json
emmanuel-karanja Oct 21, 2024
856a0cd
Fixes
emmanuel-karanja Oct 21, 2024
546221c
fixes
emmanuel-karanja Oct 21, 2024
edb585b
fixes
emmanuel-karanja Oct 21, 2024
cdff71e
fixes to EntraModulebuilder
emmanuel-karanja Oct 21, 2024
0037a34
fixes to EntraModuleBuilder
emmanuel-karanja Oct 21, 2024
001b0d9
formatting
emmanuel-karanja Oct 21, 2024
bb30596
fixed manifest gen bug
emmanuel-karanja Oct 21, 2024
fb5edbb
fixed manifest gen bug
emmanuel-karanja Oct 21, 2024
8de8367
Created New-Build.md
emmanuel-karanja Oct 21, 2024
c213e1c
added Doc Splitting code and Module Mapping creator
emmanuel-karanja Oct 21, 2024
4bd0157
updates
emmanuel-karanja Oct 21, 2024
a504871
Debugged to add Get-EntraUnsupportedCommand and New-EntraCustomHeader…
emmanuel-karanja Oct 21, 2024
c462d95
Debug to add export
emmanuel-karanja Oct 21, 2024
ec32f69
Debug to add export
emmanuel-karanja Oct 21, 2024
d8b0810
Refactored Create-ModuleMapping
emmanuel-karanja Oct 22, 2024
a0eff7a
refactored logging code
emmanuel-karanja Oct 22, 2024
3958673
refactored Split-Docs code
emmanuel-karanja Oct 22, 2024
3417cc9
Refactor
emmanuel-karanja Oct 22, 2024
89ca0e7
rename file
emmanuel-karanja Oct 22, 2024
8d58714
Delete build/Create-EntraModule.ps1
emmanuel-karanja Oct 22, 2024
1120db6
minor changes
emmanuel-karanja Oct 23, 2024
7802919
minor changes
emmanuel-karanja Oct 23, 2024
7c1d326
minor changes
emmanuel-karanja Oct 23, 2024
053a1db
Small changes to mapping generation and doc splitting
emmanuel-karanja Oct 23, 2024
122e876
Small changes to mapping generation and doc splitting
emmanuel-karanja Oct 23, 2024
76e405e
fixes
emmanuel-karanja Oct 23, 2024
2cc12ee
Updated dependencyMapping.json
emmanuel-karanja Oct 23, 2024
1f177b3
Updated module map code
emmanuel-karanja Oct 23, 2024
dcad4a9
Added Meta-Module Generation Code
emmanuel-karanja Oct 23, 2024
d3d5693
Added Meta-Module Generation Code
emmanuel-karanja Oct 23, 2024
ee4abdd
Added Meta-Module Generation Code
emmanuel-karanja Oct 24, 2024
4b947c6
Fixes
emmanuel-karanja Oct 24, 2024
a3fafc3
fixed submodule loading code
emmanuel-karanja Oct 24, 2024
620a49c
fixed root module manifest gen code
emmanuel-karanja Oct 24, 2024
3df3253
fixed root module manifest gen code
emmanuel-karanja Oct 24, 2024
eca83c1
fixed root module manifest gen code
emmanuel-karanja Oct 24, 2024
6baa466
fixed root module manifest gen code
emmanuel-karanja Oct 24, 2024
316ed23
fixed root module manifest gen code
emmanuel-karanja Oct 24, 2024
2923ad6
fixed root module manifest gen code
emmanuel-karanja Oct 24, 2024
62b30af
fixed module loading issue
emmanuel-karanja Oct 24, 2024
8c8ff5d
fixed root module generation to give correct path
emmanuel-karanja Oct 24, 2024
7ba6e3f
Fixed required module fetching
emmanuel-karanja Oct 24, 2024
691277c
Added logging for testing
emmanuel-karanja Oct 24, 2024
db55a34
Added logging for testing
emmanuel-karanja Oct 24, 2024
7037e10
Added correct moduleMapping for Entra
emmanuel-karanja Oct 28, 2024
f335495
fix bug
emmanuel-karanja Oct 28, 2024
2521c0c
fix bug
emmanuel-karanja Oct 28, 2024
5cd1461
fix bug
emmanuel-karanja Oct 28, 2024
7627504
fix bug
emmanuel-karanja Oct 28, 2024
a3489ec
Split Files
emmanuel-karanja Oct 28, 2024
1d4369a
Split Files
emmanuel-karanja Oct 28, 2024
4ce2772
fix bug
emmanuel-karanja Oct 28, 2024
5571504
New Split
emmanuel-karanja Oct 28, 2024
3b7a839
resplit docs
emmanuel-karanja Oct 28, 2024
2753ee4
fixes to dependency mapping and added logic to skip the Migrations di…
emmanuel-karanja Oct 28, 2024
af63ab8
update dependency maps
emmanuel-karanja Oct 28, 2024
d62bd0f
fixes
emmanuel-karanja Oct 29, 2024
e6f290f
fixes
emmanuel-karanja Oct 29, 2024
2c29633
migrate to moduleVNext
emmanuel-karanja Oct 29, 2024
7dbc505
migrate to moduleVNext
emmanuel-karanja Oct 29, 2024
6c62949
migrate to moduleVNext
emmanuel-karanja Oct 29, 2024
69fc8ac
fixes
emmanuel-karanja Oct 29, 2024
0dc2eeb
fixes
emmanuel-karanja Oct 29, 2024
16a4736
Update VNext-Build.md file
emmanuel-karanja Oct 29, 2024
ffadaa4
Update VNext-Build.md file
emmanuel-karanja Oct 29, 2024
4bde041
Update VNext-Build.md file
emmanuel-karanja Oct 29, 2024
76beb43
Update VNext-Build.md file
emmanuel-karanja Oct 29, 2024
1ce98de
Update VNext-Build.md file
emmanuel-karanja Oct 29, 2024
acdb69b
Update VNext-Build.md file
emmanuel-karanja Oct 29, 2024
bef471a
Update RootModule Import for Tests
emmanuel-karanja Oct 29, 2024
4616107
Update modularization paths (#1177)
KenitoInc Oct 29, 2024
35c7814
Fix telemetry custom headers (#1179)
KenitoInc Oct 30, 2024
08f91e5
Split Test files to sub-module directories (#1180)
emmanuel-karanja Nov 5, 2024
40dfe4f
Changes
emmanuel-karanja Nov 7, 2024
24393c5
Changes
emmanuel-karanja Nov 7, 2024
9b7b5c4
Generate the Root Module .ps1 file (#1192)
emmanuel-karanja Nov 7, 2024
b6e5db3
resolve conflictS
emmanuel-karanja Nov 7, 2024
0e93058
resolve conflictS
emmanuel-karanja Nov 7, 2024
8c4a76d
resolve New-EntraBetaCustomHeaders
emmanuel-karanja Nov 7, 2024
2cfb611
resolve New-EntraBetaCustomHeaders
emmanuel-karanja Nov 7, 2024
5d74f42
resolve New-EntraBetaCustomHeaders and updated splitting
emmanuel-karanja Nov 7, 2024
5060d5b
clean up
emmanuel-karanja Nov 7, 2024
35103d5
clean up
emmanuel-karanja Nov 7, 2024
999236d
Directory Harmonization
emmanuel-karanja Nov 7, 2024
03f7ee8
Directory Harmonization
emmanuel-karanja Nov 7, 2024
2d67686
Inject RequiredModules section into Root Module Manifest (#1195)
emmanuel-karanja Nov 11, 2024
522e0c2
Commented out call to create root psm1 file (#1199)
emmanuel-karanja Nov 11, 2024
a889baf
Commented out call to create root psm1 file
emmanuel-karanja Nov 11, 2024
3c741a1
Enganga/remove root module psm1 file (#1200)
emmanuel-karanja Nov 11, 2024
ca6158c
Tests Cleanup (#1209)
emmanuel-karanja Nov 14, 2024
5f9291d
Add the Sub-Modules as RequiredModules in the Root Module Manifest (#…
emmanuel-karanja Nov 14, 2024
dfefad0
Merge branch 'modularize' of https://github.com/microsoftgraph/entra-…
emmanuel-karanja Nov 14, 2024
ccd2b5b
Merge branch 'modularize' of https://github.com/microsoftgraph/entra-…
emmanuel-karanja Nov 14, 2024
92793c6
Groups changes
emmanuel-karanja Nov 14, 2024
242e3c1
Groups changes
emmanuel-karanja Nov 14, 2024
b6d0d71
Groups changes
emmanuel-karanja Nov 14, 2024
05a9ce7
entra-beta-audit changes (#1210)
emmanuel-karanja Nov 15, 2024
b3a30e7
Additional EntraBeta Tests Issues (#1211)
emmanuel-karanja Nov 15, 2024
d5a2874
Removed additional entry for MsDirectoryObject
emmanuel-karanja Nov 15, 2024
904851a
Removed additional entry for MsDirectoryObject and MsRoleMemberInfo (…
emmanuel-karanja Nov 15, 2024
6d0225f
Run modular tests on the pipeline (#1186)
KenitoInc Nov 18, 2024
ec776dc
Credscan and PSScriptAnalyzer suppressions (#1220)
KenitoInc Nov 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
965 changes: 965 additions & 0 deletions build/Beta-TypeDefs.txt

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions build/Create-EntraModule.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

[cmdletbinding()]
param (
[string]$Module = "Entra", # Default to "Entra" if no argument is provided
[switch]$Root
)

. (Join-Path $psscriptroot "/common-functions.ps1")
. (Join-Path $psscriptroot "../src/EntraModuleBuilder.ps1")

$moduleBuilder = [EntraModuleBuilder]::new()

if($Module -eq 'Entra'){

$typeDefsPath=(Join-Path $PSScriptRoot "/V1.0-Typedefs.txt")
}else{
$typeDefsPath=(Join-Path $PSScriptRoot "/Beta-TypeDefs.txt")
}

if($Root){
$moduleBuilder.CreateRootModuleManifest($Module)
}else{
$moduleBuilder.CreateModuleHelp($Module)
$moduleBuilder.CreateSubModuleFile($Module, $typeDefsPath)
$moduleBuilder.CreateModuleManifest($Module)
}

75 changes: 75 additions & 0 deletions build/Create-ModuleMapping.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# ------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
# ------------------------------------------------------------------------------

#This function uses the moduleMapping.json to split the docs to subdirectories i.e. Key =SubModule name and
# Value =an array of strings representing the files in that directory
. ./common-functions.ps1
function Get-DirectoryFileMap {
param (
[string]$Source = 'Entra' # Default to 'Entra'
)


# Determine the root directory and the output based on the Source parameter
switch ($Source) {
'Entra' {
$RootDirectory = "../module/Entra/Microsoft.Graph.Entra/"
$OutputDirectory = '../module/Entra/config/'
}
'EntraBeta' {
$RootDirectory = "../module/EntraBeta/Microsoft.Graph.Entra.Beta/"
$OutputDirectory = "../module/EntraBeta/config/"
}
default {
Log-Message "Invalid Source specified. Use 'Entra' or 'EntraBeta'." 'Error'
throw "Invalid Source specified. Use 'Entra' or 'EntraBeta'."
}
}

# Check if the root directory exists
if (-not (Test-Path -Path $RootDirectory -PathType Container)) {
Log-Message "Directory '$RootDirectory' does not exist." 'Error'
throw "Directory '$RootDirectory' does not exist."
} else {
Log-Message "Root directory '$RootDirectory' found."
}

# Check if the output directory exists, create if it doesn't
if (-not (Test-Path -Path $OutputDirectory -PathType Container)) {
New-Item -Path $OutputDirectory -ItemType Directory | Out-Null
Log-Message "Output directory '$OutputDirectory' did not exist, created it." 'Warning'
} else {
Log-Message "Output directory '$OutputDirectory' exists."
}

$fileDirectoryMap = @{}

# Get all the subdirectories under the root directory
$subDirectories = Get-ChildItem -Path $RootDirectory -Directory

foreach ($subDir in $subDirectories) {
Log-Message "Processing subdirectory '$($subDir.Name)'." 'Info'

# Get the files in each sub-directory without their extensions
$files = Get-ChildItem -Path $subDir.FullName -File | ForEach-Object {
$fileName = [System.IO.Path]::GetFileNameWithoutExtension($_.Name)
# Map the file name to the directory name
$fileDirectoryMap[$fileName] = $subDir.Name
Log-Message "Mapped file '$fileName' to directory '$($subDir.Name)'." 'Info'
}
}

# Convert the file-directory map to JSON
$jsonOutput = $fileDirectoryMap | ConvertTo-Json -Depth 3

# Define the output file path as moduleMapping.json
$outputFilePath = Join-Path -Path $OutputDirectory -ChildPath "newModuleMapping.json"

# Write the JSON output to moduleMapping.json
$jsonOutput | Out-File -FilePath $outputFilePath -Encoding UTF8

Log-Message "moduleMapping.json has been created at '$outputFilePath'." 'Info'
}

Get-DirectoryFileMap -Source 'Entra'
83 changes: 83 additions & 0 deletions build/Split-Docs.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# ------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
# ------------------------------------------------------------------------------

#This function copies the docs using the moduleMapping.json into their submodule directories
# i.e. For each entry, it will use the Key(cmdlet name) and map it to the Value(A subdirectory created in the respective docs directory)

. ./common-functions.ps1


function Split-Docs {
param (
[string]$Module = 'Entra', # Default to 'Entra'
[string]$OutputDirectory # Allow custom output directory
)

# Determine source directories and mapping file paths based on the Source parameter
switch ($Module) {
'Entra' {
$DocsSourceDirectory = "../module/docs/entra-powershell-v1.0/Microsoft.Graph.Entra"
$MappingFilePath = '../moduleVNext/Entra/config/moduleMapping.json'
$OutputDirectory='../moduleVNext/docs/entra-powershell-v1.0'
}
'EntraBeta' {
$DocsSourceDirectory = "../module/docs/entra-powershell-beta/Microsoft.Graph.Entra.Beta"
$MappingFilePath = "../moduleVNext/EntraBeta/config/moduleMapping.json"
$OutputDirectory="../moduleVNext/docs/entra-powershell-beta"
}
default {
Log-Message -Message "[Split-Docs]: Invalid Source specified. Use 'Entra' or 'EntraBeta'." -Level 'ERROR'
return
}
}

# Use the provided output directory or default to DocsSourceDirectory if none specified
$TargetRootDirectory = $OutputDirectory

# Check if the mapping file exists
if (-not (Test-Path -Path $MappingFilePath -PathType Leaf)) {
Log-Message -Message "[Split-Docs]: Mapping file '$MappingFilePath' does not exist." -Level 'ERROR'
return
}

# Load the JSON content from the mapping file
$moduleMapping = Get-Content -Path $MappingFilePath | ConvertFrom-Json

# Ensure the root documentation directory exists, create if it doesn't
if (-not (Test-Path -Path $TargetRootDirectory -PathType Container)) {
New-Item -Path $TargetRootDirectory -ItemType Directory | Out-Null
Log-Message -Message "[Split-Docs]: Created directory: $TargetRootDirectory" -Level 'SUCCESS'
}

# Iterate over each file-directory pair in the moduleMapping.json
foreach ($fileEntry in $moduleMapping.PSObject.Properties) {
$fileName = $fileEntry.Name # Key (file name without extension)
$subDirName = $fileEntry.Value # Value (sub-directory name)

# Create the sub-directory under the output root directory if it doesn't exist
$targetSubDir = Join-Path -Path $TargetRootDirectory -ChildPath $subDirName

if($subDirName -eq 'Migration' -or $subDirName -eq 'Invitations'){
Log-Message "[Split-Docs]: Skipping $subDirName" -Level 'WARNING'
continue
}
if (-not (Test-Path -Path $targetSubDir -PathType Container)) {
New-Item -Path $targetSubDir -ItemType Directory | Out-Null
Log-Message -Message "[Split-Docs]: Created sub-directory: $targetSubDir" -Level 'SUCCESS'
}

# Build the full source file path for the .md file
$sourceFile = Join-Path -Path $DocsSourceDirectory -ChildPath "$fileName.md"
if (Test-Path -Path $sourceFile -PathType Leaf) {
# Copy the .md file to the target sub-directory
Copy-Item -Path $sourceFile -Destination $targetSubDir
Log-Message -Message "[Split-Docs]: Copied '$sourceFile' to '$targetSubDir'" -Level 'SUCCESS'
} else {
# Log a warning if the .md file doesn't exist in the source directory
Log-Message -Message "[Split-Docs]: File '$fileName.md' not found in '$DocsSourceDirectory'" -Level 'WARNING'
}
}

Log-Message -Message "[Split-Docs]: Markdown file copying complete." -Level 'INFO'
}
21 changes: 21 additions & 0 deletions build/Split-EntraModule.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# ------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
# ------------------------------------------------------------------------------

param (
[string]$Module = "Entra" # Default to "Entra" if no argument is provided
)

# Import the necessary scripts
. ..\src\EntraModuleSplitter.ps1
. .\Split-Docs



# Split the module and take into account the AzureADAliases as well
$entraModuleSplitter = [EntraModuleSplitter]::new()
$entraModuleSplitter.SplitEntraModule($Module) # Pass the module argument
$entraModuleSplitter.ProcessEntraAzureADAliases($Module)

./Split-Docs.ps1 -Module $Module
./Split-Tests.ps1 -Module $Module
184 changes: 184 additions & 0 deletions build/Split-Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
# ------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All Rights Reserved.
# Licensed under the MIT License. See License in the project root for license information.
# ------------------------------------------------------------------------------

# This function copies the docs using the moduleMapping.json into their submodule directories.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this description was copied and left from the Split-Docs function. Minor, but worth changing to speak regarding tests instead of docs.

# For each entry, it uses the Key (cmdlet name) to map it to the Value (a subdirectory created in the respective docs directory).

. ./common-functions.ps1

function Split-Tests {
param (
[string]$Module = 'Entra', # Default to 'Entra'
[string]$OutputDirectory # Allow custom output directory
)

# Determine source directories and mapping file paths based on the Source parameter

switch ($Module) {
'Entra' {
$TestSourceDirectory = "../test/module/Entra"
$MappingFilePath = '../moduleVNext/Entra/config/moduleMapping.json'
$OutputDirectory = '../testVNext/Entra'
$modulePrefix = 'Microsoft.Graph.Entra'
}
'EntraBeta' {
$TestSourceDirectory = "../test/module/EntraBeta"
$MappingFilePath = "../moduleVNext/EntraBeta/config/moduleMapping.json"
$OutputDirectory = "../testVNext/EntraBeta"
$modulePrefix = 'Microsoft.Graph.Entra.Beta'
}
default {
Log-Message -Message "Invalid Source specified. Use 'Entra' or 'EntraBeta'." -Level 'ERROR'
return
}
}

# Check if the mapping file exists
if (-not (Test-Path -Path $MappingFilePath -PathType Leaf)) {
Log-Message -Message "Mapping file '$MappingFilePath' does not exist." -Level 'ERROR'
return
}

# Load the JSON content from the mapping file
$moduleMapping = Get-Content -Path $MappingFilePath | ConvertFrom-Json

# Create a set to track files that have been processed
$processedFiles = @{}

# Ensure the root documentation directory exists
if (-not (Test-Path -Path $OutputDirectory -PathType Container)) {
New-Item -Path $OutputDirectory -ItemType Directory | Out-Null
Log-Message -Message "Created directory: $OutputDirectory" -Level 'SUCCESS'
}

# Collect all test files in the source directory
$allTestFiles = Get-ChildItem -Path $TestSourceDirectory -Filter "*.Tests.ps1" -File

# Define additional test files to be copied to each subdirectory
$additionalTestFiles = @("General.Test.ps1", "Invalid.Tests.ps1", "Module.Tests.ps1", "Valid.Tests.ps1", "Entra.Tests.ps1")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this should reference "General.Tests.ps1".


# Iterate over each file-directory pair in the moduleMapping.json
foreach ($fileEntry in $moduleMapping.PSObject.Properties) {
$fileName = $fileEntry.Name # Key (file name without extension)
$subDirName = $fileEntry.Value # Value (sub-directory name)

# Create the sub-directory under the output root directory if it doesn't exist
$targetSubDir = Join-Path -Path $OutputDirectory -ChildPath $subDirName

# Skip specified subdirectories
if ($subDirName -eq 'Migration' -or $subDirName -eq 'Invitations') {
Log-Message "Skipping $subDirName" -Level 'WARNING'
continue
}

if (-not (Test-Path -Path $targetSubDir -PathType Container)) {
New-Item -Path $targetSubDir -ItemType Directory | Out-Null
Log-Message -Message "Created sub-directory: $targetSubDir" -Level 'SUCCESS'
}

# Build the full source file path for the .Tests.ps1 file
$sourceFile = Join-Path -Path $TestSourceDirectory -ChildPath "$fileName.Tests.ps1"

if (Test-Path -Path $sourceFile -PathType Leaf) {
# Copy the file to the target sub-directory
Copy-Item -Path $sourceFile -Destination $targetSubDir
Log-Message -Message "Copied '$sourceFile' to '$targetSubDir'" -Level 'SUCCESS'

# Track the processed file
$processedFiles[$fileName] = $true
} else {
Log-Message -Message "File '$fileName.Tests.ps1' not found in '$TestSourceDirectory'" -Level 'WARNING'
}

# Copy additional test files to the target sub-directory
foreach ($additionalTestFile in $additionalTestFiles) {
$additionalSourceFile = Join-Path -Path $TestSourceDirectory -ChildPath $additionalTestFile
if (Test-Path -Path $additionalSourceFile -PathType Leaf) {
# Copy the additional test file
Copy-Item -Path $additionalSourceFile -Destination $targetSubDir
Log-Message -Message "Copied additional test file '$additionalSourceFile' to '$targetSubDir'" -Level 'SUCCESS'

# Track the processed additional file
$processedFiles[$additionalTestFile] = $true
} else {
Log-Message -Message "Additional test file '$additionalTestFile' not found in '$TestSourceDirectory'" -Level 'WARNING'
}
}

# Check if the current test file name contains "Dir" or "Application" and handle them appropriately
if ($fileName -like "*Dir*" -or $fileName -like "*Application*") {
# Prepare the modified content for Dir or Application tests
$sourceFileDir = Join-Path -Path $TestSourceDirectory -ChildPath "$fileName.Tests.ps1"
if (Test-Path -Path $sourceFileDir -PathType Leaf) {
# Copy the file to the appropriate target directory
$targetDirSubDir = if ($fileName -like "*Dir*") {
Join-Path -Path $OutputDirectory -ChildPath "DirectoryManagement"
} elseif ($fileName -like "*Application*") {
Join-Path -Path $OutputDirectory -ChildPath "Applications"
} else {
$targetSubDir
}

if (-not (Test-Path -Path $targetDirSubDir -PathType Container)) {
New-Item -Path $targetDirSubDir -ItemType Directory | Out-Null
Log-Message -Message "Created target directory: $targetDirSubDir" -Level 'SUCCESS'
}

# Copy the file to the determined sub-directory
Copy-Item -Path $sourceFileDir -Destination $targetDirSubDir
Log-Message -Message "Copied '$sourceFileDir' to '$targetDirSubDir'" -Level 'SUCCESS'

# Track the processed Dir/Application file

$processedFiles[$fileName] = $true
}
}
}

# Process all copied files to update their contents
foreach ($subDir in Get-ChildItem -Path $OutputDirectory -Directory) {
$subDirPath = $subDir.FullName
$testFilesInSubDir = Get-ChildItem -Path $subDirPath -Filter "*.Tests.ps1"

foreach ($testFile in $testFilesInSubDir) {
$fileContent = Get-Content -Path $testFile.FullName -Raw
$updatedContent = $fileContent -replace [regex]::Escape($modulePrefix), "$modulePrefix.$($subDir.Name)"


# Save the modified content back to the file
$updatedContent | Set-Content -Path $testFile.FullName
Log-Message -Message "Updated content in '$testFile.FullName'" -Level 'SUCCESS'
}
}



# Handle unmapped files that do not exist in the mapping
foreach ($testFile in $allTestFiles) {
$baseName = $testFile.BaseName -replace '\.Tests$', '' # Remove '.Tests' suffix

# Only consider unmapped files if they haven't been processed
if (-not $processedFiles.ContainsKey($baseName)) {
# Check if the test file already exists in the output directories
$isMapped = $false

# Check for both Entra and EntraBeta directories
if (Test-Path -Path (Join-Path -Path $OutputDirectory -ChildPath $baseName)) {
$isMapped = $true
}

# If not mapped, copy it to the root output directory
if (-not $isMapped) {
Copy-Item -Path $testFile.FullName -Destination $OutputDirectory
Log-Message -Message "Copied unmapped test '$testFile' to '$OutputDirectory'" -Level 'INFO'
}
}
}

Log-Message -Message "Split-Tests completed for source: $Module" -Level 'SUCCESS'
}


Split-Tests -Module 'EntraBeta'
Loading