Skip to content

Commit 03b5889

Browse files
🩹 [Patch]: Let Site builder adhere to module folder structure (#55)
## Description - Let Site builder adhere to module folder structure ## Type of change <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [x] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist <!-- Use the check-boxes [x] on the options that are relevant. --> - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas
1 parent 1e41aef commit 03b5889

File tree

11 files changed

+68
-56
lines changed

11 files changed

+68
-56
lines changed

.github/workflows/workflow.yml

Lines changed: 58 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -524,64 +524,66 @@ jobs:
524524
pip install mkdocs-git-revision-date-localized-plugin
525525
pip install mkdocs-git-committers-plugin-2
526526
527-
- name: Run Script
528-
shell: pwsh
529-
run: |
530-
$ModuleName = '${{ inputs.Name }}'
531-
532-
if (-not $ModuleName) {
533-
$ModuleName = $env:GITHUB_REPOSITORY -replace '.+/'
534-
}
535-
Write-Verbose "Module name: $ModuleName"
536-
537-
$ModuleSourcePath = Join-Path (Get-Location) -ChildPath '${{ inputs.Path }}'
538-
$DocsOutputPath = Join-Path (Get-Location) -ChildPath "${{ inputs.DocsOutputPath }}/$ModuleName"
539-
$SiteOutputPath = Join-Path (Get-Location) -ChildPath '${{ inputs.SiteOutputPath }}'
540-
541-
$functionDocsFolderPath = Join-Path -Path $SiteOutputPath -ChildPath 'docs/Functions'
542-
$functionDocsFolder = New-Item -Path $functionDocsFolderPath -ItemType Directory -Force
543-
Get-ChildItem -Path $DocsOutputPath -Recurse -Force -Include '*.md' | Copy-Item -Destination $functionDocsFolder -Recurse -Force
544-
Get-ChildItem -Path $functionDocsFolder -Recurse -Force -Include '*.md' | ForEach-Object {
545-
$fileName = $_.Name
546-
$hash = (Get-FileHash -Path $_.FullName -Algorithm SHA256).Hash
547-
Start-LogGroup " - [$fileName] - [$hash]"
548-
Show-FileContent -Path $_
549-
Stop-LogGroup
550-
}
551-
552-
Start-LogGroup 'Build docs - Process about topics'
553-
$aboutDocsFolderPath = Join-Path -Path $SiteOutputPath -ChildPath 'docs/About'
554-
$aboutDocsFolder = New-Item -Path $aboutDocsFolderPath -ItemType Directory -Force
555-
$aboutSourceFolder = Get-ChildItem -Path $ModuleSourcePath -Directory | Where-Object { $_.Name -eq 'en-US' }
556-
Get-ChildItem -Path $aboutSourceFolder -Filter *.txt | Copy-Item -Destination $aboutDocsFolder -Force -Verbose -PassThru |
557-
Rename-Item -NewName { $_.Name -replace '.txt', '.md' }
558-
Stop-LogGroup
527+
- name: Structure site
528+
uses: PSModule/GitHub-Script@v1
529+
with:
530+
Script: |
531+
$ModuleName = '${{ inputs.Name }}'
559532
560-
Start-LogGroup 'Build docs - Copy icon to assets'
561-
$assetsFolderPath = Join-Path -Path $SiteOutputPath -ChildPath 'docs/Assets'
562-
$null = New-Item -Path $assetsFolderPath -ItemType Directory -Force
563-
$rootPath = Split-Path -Path $ModuleSourcePath -Parent
564-
$iconPath = Join-Path -Path $rootPath -ChildPath 'icon\icon.png'
565-
Copy-Item -Path $iconPath -Destination $assetsFolderPath -Force -Verbose
566-
567-
Start-LogGroup 'Build docs - Copy readme.md'
568-
$rootPath = Split-Path -Path $ModuleSourcePath -Parent
569-
$readmePath = Join-Path -Path $rootPath -ChildPath 'README.md'
570-
$readmeTargetPath = Join-Path -Path $SiteOutputPath -ChildPath 'docs/README.md'
571-
Copy-Item -Path $readmePath -Destination $readmeTargetPath -Force -Verbose
572-
Stop-LogGroup
533+
if (-not $ModuleName) {
534+
$ModuleName = $env:GITHUB_REPOSITORY -replace '.+/'
535+
}
536+
Write-Verbose "Module name: $ModuleName"
537+
538+
$ModuleSourcePath = Join-Path (Get-Location) -ChildPath '${{ inputs.Path }}'
539+
$DocsOutputPath = Join-Path (Get-Location) -ChildPath "${{ inputs.DocsOutputPath }}/$ModuleName"
540+
$SiteOutputPath = Join-Path (Get-Location) -ChildPath '${{ inputs.SiteOutputPath }}'
541+
542+
$functionDocsFolderPath = Join-Path -Path $SiteOutputPath -ChildPath 'docs/Functions'
543+
$functionDocsFolder = New-Item -Path $functionDocsFolderPath -ItemType Directory -Force
544+
Copy-Item -Path $DocsOutputPath -Destination $functionDocsFolder -Recurse -Force
545+
Get-ChildItem -Path $functionDocsFolder -Recurse -Force -Include '*.md' | ForEach-Object {
546+
$fileName = $_.Name
547+
$hash = (Get-FileHash -Path $_.FullName -Algorithm SHA256).Hash
548+
LogGroup " - [$fileName] - [$hash]" {
549+
Show-FileContent -Path $_
550+
}
551+
}
573552
574-
Start-LogGroup 'Build docs - Create mkdocs.yml'
575-
$rootPath = Split-Path -Path $ModuleSourcePath -Parent
576-
# This should be moved to an action so that we can use a default one, and not have to copy it from the repo.
577-
$mkdocsSourcePath = Join-Path -Path $rootPath -ChildPath 'mkdocs.yml'
578-
$mkdocsTargetPath = Join-Path -Path $SiteOutputPath -ChildPath 'mkdocs.yml'
579-
$mkdocsContent = Get-Content -Path $mkdocsSourcePath -Raw
580-
$mkdocsContent = $mkdocsContent.Replace('-{{ REPO_NAME }}-', $ModuleName)
581-
$mkdocsContent = $mkdocsContent.Replace('-{{ REPO_OWNER }}-', $env:GITHUB_REPOSITORY_OWNER)
582-
$mkdocsContent | Set-Content -Path $mkdocsTargetPath -Force
583-
Show-FileContent -Path $mkdocsTargetPath
584-
Stop-LogGroup
553+
LogGroup 'Build docs - Process about topics' {
554+
$aboutDocsFolderPath = Join-Path -Path $SiteOutputPath -ChildPath 'docs/About'
555+
$aboutDocsFolder = New-Item -Path $aboutDocsFolderPath -ItemType Directory -Force
556+
$aboutSourceFolder = Get-ChildItem -Path $ModuleSourcePath -Directory | Where-Object { $_.Name -eq 'en-US' }
557+
Get-ChildItem -Path $aboutSourceFolder -Filter *.txt | Copy-Item -Destination $aboutDocsFolder -Force -Verbose -PassThru |
558+
Rename-Item -NewName { $_.Name -replace '.txt', '.md' }
559+
}
560+
561+
LogGroup 'Build docs - Copy icon to assets' {
562+
$assetsFolderPath = Join-Path -Path $SiteOutputPath -ChildPath 'docs/Assets'
563+
$null = New-Item -Path $assetsFolderPath -ItemType Directory -Force
564+
$rootPath = Split-Path -Path $ModuleSourcePath -Parent
565+
$iconPath = Join-Path -Path $rootPath -ChildPath 'icon\icon.png'
566+
Copy-Item -Path $iconPath -Destination $assetsFolderPath -Force -Verbose
567+
}
568+
569+
LogGroup 'Build docs - Copy readme.md' {
570+
$rootPath = Split-Path -Path $ModuleSourcePath -Parent
571+
$readmePath = Join-Path -Path $rootPath -ChildPath 'README.md'
572+
$readmeTargetPath = Join-Path -Path $SiteOutputPath -ChildPath 'docs/README.md'
573+
Copy-Item -Path $readmePath -Destination $readmeTargetPath -Force -Verbose
574+
}
575+
576+
LogGroup 'Build docs - Create mkdocs.yml' {
577+
$rootPath = Split-Path -Path $ModuleSourcePath -Parent
578+
# This should be moved to an action so that we can use a default one, and not have to copy it from the repo.
579+
$mkdocsSourcePath = Join-Path -Path $rootPath -ChildPath 'mkdocs.yml'
580+
$mkdocsTargetPath = Join-Path -Path $SiteOutputPath -ChildPath 'mkdocs.yml'
581+
$mkdocsContent = Get-Content -Path $mkdocsSourcePath -Raw
582+
$mkdocsContent = $mkdocsContent.Replace('-{{ REPO_NAME }}-', $ModuleName)
583+
$mkdocsContent = $mkdocsContent.Replace('-{{ REPO_OWNER }}-', $env:GITHUB_REPOSITORY_OWNER)
584+
$mkdocsContent | Set-Content -Path $mkdocsTargetPath -Force
585+
Show-FileContent -Path $mkdocsTargetPath
586+
}
585587
586588
- name: Debug File system
587589
shell: pwsh

tests/src/functions/public/Get-PSModuleTest.ps1 renamed to tests/src/functions/public/PSModule/Get-PSModuleTest.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#Requires -Modules Utilities
2+
#Requires -Modules @{ ModuleName = 'PSSemVer'; RequiredVersion = '1.0.0' }
3+
#Requires -Modules @{ ModuleName = 'DynamicParams'; ModuleVersion = '1.1.8' }
4+
#Requires -Modules @{ ModuleName = 'Store'; ModuleVersion = '0.3.1' }
25

36
function Get-PSModuleTest {
47
<#
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# This is PSModule
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# This is SomethingElse

tests/srcWithManifest/functions/public/Get-PSModuleTest.ps1 renamed to tests/srcWithManifest/functions/public/PSModule/Get-PSModuleTest.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#Requires -Modules Utilities
2+
#Requires -Modules @{ ModuleName = 'PSSemVer'; RequiredVersion = '1.0.0' }
3+
#Requires -Modules @{ ModuleName = 'DynamicParams'; ModuleVersion = '1.1.8' }
4+
#Requires -Modules @{ ModuleName = 'Store'; ModuleVersion = '0.3.1' }
25

36
function Get-PSModuleTest {
47
<#
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# This is PSModule

0 commit comments

Comments
 (0)