-
Notifications
You must be signed in to change notification settings - Fork 18
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
emmanuel-karanja
wants to merge
115
commits into
main
Choose a base branch
from
modularize
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+179,193
−109
Open
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 3cd2eb9
Added module splitter and psm1 builder
emmanuel-karanja 92611df
Added module splitter and psm1 builder
emmanuel-karanja 084601d
added moduleMapper.json
emmanuel-karanja 64935a0
added runner script and typedefs
emmanuel-karanja 79a2a4f
Added Comments
emmanuel-karanja 230b98d
Added WriteModuleManifest
emmanuel-karanja a312a45
changed name to Create-EntraModule
emmanuel-karanja 81c1d9a
Added CreateModuleHelp
emmanuel-karanja 06a0a04
fixed the help generation code
emmanuel-karanja c7d0a91
Fixed the runner script
emmanuel-karanja 6146040
added dependency mapping
emmanuel-karanja 0b61ead
Added dependency mapping.json
emmanuel-karanja 856a0cd
Fixes
emmanuel-karanja 546221c
fixes
emmanuel-karanja edb585b
fixes
emmanuel-karanja cdff71e
fixes to EntraModulebuilder
emmanuel-karanja 0037a34
fixes to EntraModuleBuilder
emmanuel-karanja 001b0d9
formatting
emmanuel-karanja bb30596
fixed manifest gen bug
emmanuel-karanja fb5edbb
fixed manifest gen bug
emmanuel-karanja 8de8367
Created New-Build.md
emmanuel-karanja c213e1c
added Doc Splitting code and Module Mapping creator
emmanuel-karanja 4bd0157
updates
emmanuel-karanja a504871
Debugged to add Get-EntraUnsupportedCommand and New-EntraCustomHeader…
emmanuel-karanja c462d95
Debug to add export
emmanuel-karanja ec32f69
Debug to add export
emmanuel-karanja d8b0810
Refactored Create-ModuleMapping
emmanuel-karanja a0eff7a
refactored logging code
emmanuel-karanja 3958673
refactored Split-Docs code
emmanuel-karanja 3417cc9
Refactor
emmanuel-karanja 89ca0e7
rename file
emmanuel-karanja 8d58714
Delete build/Create-EntraModule.ps1
emmanuel-karanja 1120db6
minor changes
emmanuel-karanja 7802919
minor changes
emmanuel-karanja 7c1d326
minor changes
emmanuel-karanja 053a1db
Small changes to mapping generation and doc splitting
emmanuel-karanja 122e876
Small changes to mapping generation and doc splitting
emmanuel-karanja 76e405e
fixes
emmanuel-karanja 2cc12ee
Updated dependencyMapping.json
emmanuel-karanja 1f177b3
Updated module map code
emmanuel-karanja dcad4a9
Added Meta-Module Generation Code
emmanuel-karanja d3d5693
Added Meta-Module Generation Code
emmanuel-karanja ee4abdd
Added Meta-Module Generation Code
emmanuel-karanja 4b947c6
Fixes
emmanuel-karanja a3fafc3
fixed submodule loading code
emmanuel-karanja 620a49c
fixed root module manifest gen code
emmanuel-karanja 3df3253
fixed root module manifest gen code
emmanuel-karanja eca83c1
fixed root module manifest gen code
emmanuel-karanja 6baa466
fixed root module manifest gen code
emmanuel-karanja 316ed23
fixed root module manifest gen code
emmanuel-karanja 2923ad6
fixed root module manifest gen code
emmanuel-karanja 62b30af
fixed module loading issue
emmanuel-karanja 8c8ff5d
fixed root module generation to give correct path
emmanuel-karanja 7ba6e3f
Fixed required module fetching
emmanuel-karanja 691277c
Added logging for testing
emmanuel-karanja db55a34
Added logging for testing
emmanuel-karanja 7037e10
Added correct moduleMapping for Entra
emmanuel-karanja f335495
fix bug
emmanuel-karanja 2521c0c
fix bug
emmanuel-karanja 5cd1461
fix bug
emmanuel-karanja 7627504
fix bug
emmanuel-karanja a3489ec
Split Files
emmanuel-karanja 1d4369a
Split Files
emmanuel-karanja 4ce2772
fix bug
emmanuel-karanja 5571504
New Split
emmanuel-karanja 3b7a839
resplit docs
emmanuel-karanja 2753ee4
fixes to dependency mapping and added logic to skip the Migrations di…
emmanuel-karanja af63ab8
update dependency maps
emmanuel-karanja d62bd0f
fixes
emmanuel-karanja e6f290f
fixes
emmanuel-karanja 2c29633
migrate to moduleVNext
emmanuel-karanja 7dbc505
migrate to moduleVNext
emmanuel-karanja 6c62949
migrate to moduleVNext
emmanuel-karanja 69fc8ac
fixes
emmanuel-karanja 0dc2eeb
fixes
emmanuel-karanja 16a4736
Update VNext-Build.md file
emmanuel-karanja ffadaa4
Update VNext-Build.md file
emmanuel-karanja 4bde041
Update VNext-Build.md file
emmanuel-karanja 76beb43
Update VNext-Build.md file
emmanuel-karanja 1ce98de
Update VNext-Build.md file
emmanuel-karanja acdb69b
Update VNext-Build.md file
emmanuel-karanja bef471a
Update RootModule Import for Tests
emmanuel-karanja 4616107
Update modularization paths (#1177)
KenitoInc 35c7814
Fix telemetry custom headers (#1179)
KenitoInc 08f91e5
Split Test files to sub-module directories (#1180)
emmanuel-karanja 40dfe4f
Changes
emmanuel-karanja 24393c5
Changes
emmanuel-karanja 9b7b5c4
Generate the Root Module .ps1 file (#1192)
emmanuel-karanja b6e5db3
resolve conflictS
emmanuel-karanja 0e93058
resolve conflictS
emmanuel-karanja 8c4a76d
resolve New-EntraBetaCustomHeaders
emmanuel-karanja 2cfb611
resolve New-EntraBetaCustomHeaders
emmanuel-karanja 5d74f42
resolve New-EntraBetaCustomHeaders and updated splitting
emmanuel-karanja 5060d5b
clean up
emmanuel-karanja 35103d5
clean up
emmanuel-karanja 999236d
Directory Harmonization
emmanuel-karanja 03f7ee8
Directory Harmonization
emmanuel-karanja 2d67686
Inject RequiredModules section into Root Module Manifest (#1195)
emmanuel-karanja 522e0c2
Commented out call to create root psm1 file (#1199)
emmanuel-karanja a889baf
Commented out call to create root psm1 file
emmanuel-karanja 3c741a1
Enganga/remove root module psm1 file (#1200)
emmanuel-karanja ca6158c
Tests Cleanup (#1209)
emmanuel-karanja 5f9291d
Add the Sub-Modules as RequiredModules in the Root Module Manifest (#…
emmanuel-karanja dfefad0
Merge branch 'modularize' of https://github.com/microsoftgraph/entra-…
emmanuel-karanja ccd2b5b
Merge branch 'modularize' of https://github.com/microsoftgraph/entra-…
emmanuel-karanja 92793c6
Groups changes
emmanuel-karanja 242e3c1
Groups changes
emmanuel-karanja b6d0d71
Groups changes
emmanuel-karanja 05a9ce7
entra-beta-audit changes (#1210)
emmanuel-karanja b3a30e7
Additional EntraBeta Tests Issues (#1211)
emmanuel-karanja d5a2874
Removed additional entry for MsDirectoryObject
emmanuel-karanja 904851a
Removed additional entry for MsDirectoryObject and MsRoleMemberInfo (…
emmanuel-karanja 6d0225f
Run modular tests on the pipeline (#1186)
KenitoInc ec776dc
Credscan and PSScriptAnalyzer suppressions (#1220)
KenitoInc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
# 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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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' |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.