Skip to content

Commit 30e034e

Browse files
🩹 [Patch]: Add condition to add data loader on root module (#24)
## Description - Only add data loader if a data folder exists. ## 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 d639ccd commit 30e034e

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ The root module file is the main file that is loaded when the module is imported
3737
It is built from the source code files in the module folder in the following order:
3838

3939
1. Adds module headers from `header.ps1`.
40-
1. Adds data loader automation that loads files from the `data` folder as variables in the module scope. The variables are available using the ´$script:<filename>´ syntax.
40+
1. Adds data loader automation that loads files from the `data` folder as variables in the module scope, if it exists. The variables are available using the ´$script:<filename>´ syntax.
4141
1. Adds content from subfolders, in the order:
4242
- Init
4343
- Private

scripts/helpers/Build/Build-PSModuleRootModule.ps1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ Write-Verbose "[$scriptName] Importing module"
7474
#endregion - Module post-header
7575

7676
#region - Data and variables
77-
Add-Content -Path $rootModuleFile.FullName -Force -Value @'
77+
if (Test-Path -Path (Join-Path -Path $ModuleOutputFolder -ChildPath 'data')) {
78+
79+
Add-Content -Path $rootModuleFile.FullName -Force -Value @'
7880
#region - Data import
7981
Write-Verbose "[$scriptName] - [data] - Processing folder"
8082
$dataFolder = (Join-Path $PSScriptRoot 'data')
@@ -89,6 +91,7 @@ Write-Verbose "[$scriptName] - [data] - Done"
8991
#endregion - Data import
9092
9193
'@
94+
}
9295
#endregion - Data and variables
9396

9497
#region - Add content from subfolders

0 commit comments

Comments
 (0)