Skip to content

Commit da9479c

Browse files
authored
Merge pull request #12 from belibug/resource-handling
Resource handling - enhancement #9
2 parents fbb1e4e + 228a5bf commit da9479c

6 files changed

Lines changed: 80 additions & 19 deletions

File tree

CHANGELOG.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@
22

33
All notable changes to this project will be documented in this file.
44

5-
## Inprogress
5+
## [1.0.0] - 2025-03-11
66

7-
- Updated `ProjecUri` typo to `ProjectUri` in all places. This should work properly for all new module invokes.
7+
### Added
8+
9+
- New optional project setting `copyResourcesToModuleRoot`. Setting to true places resource files in the root directory of module. Default is `false` to provide backward compatibility. Thanks to @[BrooksV](https://github.com/BrooksV)
10+
11+
### Fixed
12+
13+
- **BREAKING CHANGE**: Typo corrected: ProjecUri to ProjectUri. Existing projects require manual update.
814

915
## [0.0.9] - 2024-07-17
1016

@@ -47,4 +53,4 @@ All notable changes to this project will be documented in this file.
4753

4854
### Added
4955
- First release to `psgallery`
50-
- All basic functionality of Module is ready
56+
- All basic functionality of Module is ready

README.md

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ Whether you're creating simple or robust modules, ModuleTools streamlines the pr
1515
[![ModuleTools@PowerShell Gallery][BadgeIOCount]][PSGalleryLink]
1616
![WorkFlow Status][WorkFlowStatus]
1717

18-
19-
2018
The structure of the ModuleTools module is meticulously designed according to PowerShell best practices for module development. While some design decisions may seem unconventional, they are made to ensure that ModuleTools and the process of building modules remain straightforward and easy to manage.
2119

2220
> [!IMPORTANT]
@@ -28,7 +26,7 @@ The structure of the ModuleTools module is meticulously designed according to Po
2826
Install-Module -Name ModuleTools
2927
```
3028

31-
> Note: ModuleTolls is still in early devleopment phase and lot of changes are expected. Please read through [ChangeLog](/CHANGELOG.md) for all updates.
29+
> Note: ModuleTolls is still in early development phase and lot of changes are expected. Please read through [ChangeLog](/CHANGELOG.md) for all updates.
3230
3331
## 🧵 Design
3432

@@ -62,8 +60,6 @@ Generated module is stored in dist folder, you can easily import it or publish i
6260
└──  TestModule.psm1
6361
```
6462

65-
66-
6763
### Project JSON File
6864

6965
The `project.json` file contains all the important details about your module and is used during the module build. It should comply with a specific schema. You can refer to the sample `project-sample.json` file in the `example` directory for guidance.
@@ -72,9 +68,42 @@ Run `New-MTModule` to generate the scaffolding; this will also create the `proje
7268

7369
### Src Folder
7470

75-
- Place all your functions in the `private` and `public` folders within the `src` directory.
76-
- All functions in the `public` folder are exported during the module build.
77-
- All functions in the `private` folder are accessible internally within the module but are not exposed outside the module.
71+
- Place all your functions in the `private` and `public` folders within the `src` directory.
72+
- All functions in the `public` folder are exported during the module build.
73+
- All functions in the `private` folder are accessible internally within the module but are not exposed outside the module.
74+
- Contents of the `src/resources` folder will be handled based on setting `copyResourcesToModuleRoot`
75+
76+
#### Resources Folder
77+
78+
The `resources` folder within the `src` directory is intended for including any additional resources required by your module. This can include files such as:
79+
80+
- **Configuration files**: Store any JSON, XML, or other configuration files needed by your module.
81+
- **Script files**: Place any scripts that are used by your functions or modules, but are not directly part of the public or private functions.
82+
- **Documentation files**: Include any supplementary documentation that supports the usage or development of the module.
83+
- **Data files**: Store any data files that are used by your module, such as CSV or JSON files.
84+
- **Subfolder**: Include any additional folders and their content to be included with the module, such as dependant Modules, APIs, DLLs, etc... organized by a subfolder.
85+
86+
87+
By default, resource files from `src/resources` go into `dist/resources`. To place them directly in dist (avoiding the resources subfolder), set `copyResourcesToModuleRoot` to `true`. This provides greater control in certain deployment scenarios where resources files are preferred in module root directory.
88+
89+
Leave `src\resources` empty if there is no need to include any additional content in the `dist` folder.
90+
91+
An example of the module build where resources were included and `copyResourcesToModuleRoot` is set to true.
92+
93+
```powershell
94+
dist
95+
└── TestModule
96+
├── TestModule.psd1
97+
├── TestModule.psm1
98+
├── config.json
99+
├── additionalScript.ps1
100+
├── helpDocumentation.md
101+
├── sampleData.csv
102+
└── subfolder
103+
├── subConfig.json
104+
├── subScript.ps1
105+
└── subData.csv
106+
```
78107

79108
### Tests Folder
80109

@@ -126,7 +155,15 @@ A simple command to update the module version by modifying the values in `projec
126155

127156
## Advanced - Use it in Github Actions
128157

129-
This is not required for local module builds, if you are running github actions, use below template to test, build and publish module with ease.
158+
This is not required for local module builds, if you are running github actions, use the following yaml workflow template to test, build and publish module which helps to automate the process of:
159+
160+
1. Checking out the repository code.
161+
1. Installing the `ModuleTools` module from the PowerShell Gallery.
162+
1. Building the module.
163+
1. Running Pester tests.
164+
1. Publishing the module to a specified repository.
165+
166+
This allows for seamless and automated management of your PowerShell module, ensuring consistency and reliability in your build, test, and release processes.
130167

131168
```yaml
132169
name: Build, Test and Publish
@@ -154,6 +191,7 @@ jobs:
154191
- name: Run Pester Tests
155192
run: Invoke-MTTest
156193
shell: pwsh
194+
157195
- name: Publish Package to Github
158196
run: |
159197
Publish-PSResource -Path ./dist/YourModule -Repository SomeRepository -ApiKey $Env:ApiKey
@@ -181,4 +219,4 @@ This project is licensed under the MIT License. See the LICENSE file for details
181219
182220
[BadgeIOCount]: https://img.shields.io/powershellgallery/dt/ModuleTools?label=ModuleTools%40PowerShell%20Gallery
183221
[PSGalleryLink]: https://www.powershellgallery.com/packages/ModuleTools/
184-
[WorkFlowStatus]: https://img.shields.io/github/actions/workflow/status/belibug/ModuleTools/Tests.yml
222+
[WorkFlowStatus]: https://img.shields.io/github/actions/workflow/status/belibug/ModuleTools/Tests.yml

project.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"ProjectName": "ModuleTools",
33
"Description": "ModuleTools is a versatile, standalone PowerShell module builder. Create anything from simple to robust modules with ease. Built for CICD and Automation.",
4-
"Version": "0.0.9",
4+
"Version": "0.0.10",
5+
"copyResourcesToModuleRoot": false,
56
"Manifest": {
67
"Author": "Manjunath Beli",
78
"PowerShellHostVersion": "7.4",
@@ -18,4 +19,4 @@
1819
"Verbosity": "Detailed"
1920
}
2021
}
21-
}
22+
}
Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
11
function Copy-ProjectResource {
22
$data = Get-MTProjectInfo
33
$resFolder = [System.IO.Path]::Join($data.ProjectRoot, 'src', 'resources')
4-
54
if (Test-Path $resFolder) {
6-
if (Get-ChildItem $resFolder -ErrorAction SilentlyContinue) {
7-
Write-Verbose 'Files found in resource folder, Copying resource folder content'
8-
Copy-Item -Path $resFolder -Destination ($data.OutputModuleDir) -Recurse -Force -ErrorAction Stop
5+
## Copy to root folder instead of creating Resource Folder in module root
6+
if ($data.copyResourcesToModuleRoot) {
7+
# Copy the resources folder content to the OutputModuleDir
8+
$items = Get-ChildItem -Path $resFolder -ErrorAction SilentlyContinue
9+
if ($items) {
10+
Write-Verbose 'Files found in resource folder, copying resource folder content'
11+
foreach ($item in $items) {
12+
Copy-Item -Path $item.FullName -Destination ($data.OutputModuleDir) -Recurse -Force -ErrorAction Stop
13+
}
14+
}
15+
} else {
16+
# Copy the resources folder to the OutputModuleDir
17+
if (Get-ChildItem $resFolder -ErrorAction SilentlyContinue) {
18+
Write-Verbose 'Files found in resource folder, Copying resource folder'
19+
Copy-Item -Path $resFolder -Destination ($data.OutputModuleDir) -Recurse -Force -ErrorAction Stop
20+
}
921
}
1022
}
1123
}

src/resources/ProjectTemplate.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"ProjectName": "",
33
"Description": "",
44
"Version": "",
5+
"copyResourcesToModuleRoot": false,
56
"Manifest": {
67
"Author": "",
78
"PowerShellHostVersion": "",

src/resources/Schema-Build.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
"Version": {
1313
"type": "string"
1414
},
15+
"copyResourcesToModuleRoot": {
16+
"type": "boolean"
17+
},
1518
"Manifest": {
1619
"type": "object",
1720
"properties": {

0 commit comments

Comments
 (0)