Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@

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

## Inprogress
## [1.0.0] - 2025-03-11

- Updated `ProjecUri` typo to `ProjectUri` in all places. This should work properly for all new module invokes.
### Added

- 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)

### Fixed

- **BREAKING CHANGE**: Typo corrected: ProjecUri to ProjectUri. Existing projects require manual update.

## [0.0.9] - 2024-07-17

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

### Added
- First release to `psgallery`
- All basic functionality of Module is ready
- All basic functionality of Module is ready
58 changes: 48 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ Whether you're creating simple or robust modules, ModuleTools streamlines the pr
[![ModuleTools@PowerShell Gallery][BadgeIOCount]][PSGalleryLink]
![WorkFlow Status][WorkFlowStatus]



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.

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

> Note: ModuleTolls is still in early devleopment phase and lot of changes are expected. Please read through [ChangeLog](/CHANGELOG.md) for all updates.
> Note: ModuleTolls is still in early development phase and lot of changes are expected. Please read through [ChangeLog](/CHANGELOG.md) for all updates.

## 🧵 Design

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



### Project JSON File

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.
Expand All @@ -72,9 +68,42 @@ Run `New-MTModule` to generate the scaffolding; this will also create the `proje

### Src Folder

- Place all your functions in the `private` and `public` folders within the `src` directory.
- All functions in the `public` folder are exported during the module build.
- All functions in the `private` folder are accessible internally within the module but are not exposed outside the module.
- Place all your functions in the `private` and `public` folders within the `src` directory.
- All functions in the `public` folder are exported during the module build.
- All functions in the `private` folder are accessible internally within the module but are not exposed outside the module.
- Contents of the `src/resources` folder will be handled based on setting `copyResourcesToModuleRoot`

#### Resources Folder

The `resources` folder within the `src` directory is intended for including any additional resources required by your module. This can include files such as:

- **Configuration files**: Store any JSON, XML, or other configuration files needed by your module.
- **Script files**: Place any scripts that are used by your functions or modules, but are not directly part of the public or private functions.
- **Documentation files**: Include any supplementary documentation that supports the usage or development of the module.
- **Data files**: Store any data files that are used by your module, such as CSV or JSON files.
- **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.


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.

Leave `src\resources` empty if there is no need to include any additional content in the `dist` folder.

An example of the module build where resources were included and `copyResourcesToModuleRoot` is set to true.

```powershell
dist
└── TestModule
├── TestModule.psd1
├── TestModule.psm1
├── config.json
├── additionalScript.ps1
├── helpDocumentation.md
├── sampleData.csv
└── subfolder
├── subConfig.json
├── subScript.ps1
└── subData.csv
```

### Tests Folder

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

## Advanced - Use it in Github Actions

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.
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:

1. Checking out the repository code.
1. Installing the `ModuleTools` module from the PowerShell Gallery.
1. Building the module.
1. Running Pester tests.
1. Publishing the module to a specified repository.

This allows for seamless and automated management of your PowerShell module, ensuring consistency and reliability in your build, test, and release processes.

```yaml
name: Build, Test and Publish
Expand Down Expand Up @@ -154,6 +191,7 @@ jobs:
- name: Run Pester Tests
run: Invoke-MTTest
shell: pwsh

- name: Publish Package to Github
run: |
Publish-PSResource -Path ./dist/YourModule -Repository SomeRepository -ApiKey $Env:ApiKey
Expand Down Expand Up @@ -181,4 +219,4 @@ This project is licensed under the MIT License. See the LICENSE file for details

[BadgeIOCount]: https://img.shields.io/powershellgallery/dt/ModuleTools?label=ModuleTools%40PowerShell%20Gallery
[PSGalleryLink]: https://www.powershellgallery.com/packages/ModuleTools/
[WorkFlowStatus]: https://img.shields.io/github/actions/workflow/status/belibug/ModuleTools/Tests.yml
[WorkFlowStatus]: https://img.shields.io/github/actions/workflow/status/belibug/ModuleTools/Tests.yml
5 changes: 3 additions & 2 deletions project.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"ProjectName": "ModuleTools",
"Description": "ModuleTools is a versatile, standalone PowerShell module builder. Create anything from simple to robust modules with ease. Built for CICD and Automation.",
"Version": "0.0.9",
"Version": "0.0.10",
"copyResourcesToModuleRoot": false,
"Manifest": {
"Author": "Manjunath Beli",
"PowerShellHostVersion": "7.4",
Expand All @@ -18,4 +19,4 @@
"Verbosity": "Detailed"
}
}
}
}
20 changes: 16 additions & 4 deletions src/private/CopyProjectResource.ps1
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
function Copy-ProjectResource {
$data = Get-MTProjectInfo
$resFolder = [System.IO.Path]::Join($data.ProjectRoot, 'src', 'resources')

if (Test-Path $resFolder) {
if (Get-ChildItem $resFolder -ErrorAction SilentlyContinue) {
Write-Verbose 'Files found in resource folder, Copying resource folder content'
Copy-Item -Path $resFolder -Destination ($data.OutputModuleDir) -Recurse -Force -ErrorAction Stop
## Copy to root folder instead of creating Resource Folder in module root
if ($data.copyResourcesToModuleRoot) {
# Copy the resources folder content to the OutputModuleDir
$items = Get-ChildItem -Path $resFolder -ErrorAction SilentlyContinue
if ($items) {
Write-Verbose 'Files found in resource folder, copying resource folder content'
foreach ($item in $items) {
Copy-Item -Path $item.FullName -Destination ($data.OutputModuleDir) -Recurse -Force -ErrorAction Stop
}
}
} else {
# Copy the resources folder to the OutputModuleDir
if (Get-ChildItem $resFolder -ErrorAction SilentlyContinue) {
Write-Verbose 'Files found in resource folder, Copying resource folder'
Copy-Item -Path $resFolder -Destination ($data.OutputModuleDir) -Recurse -Force -ErrorAction Stop
}
}
}
}
1 change: 1 addition & 0 deletions src/resources/ProjectTemplate.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"ProjectName": "",
"Description": "",
"Version": "",
"copyResourcesToModuleRoot": false,
"Manifest": {
"Author": "",
"PowerShellHostVersion": "",
Expand Down
3 changes: 3 additions & 0 deletions src/resources/Schema-Build.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
"Version": {
"type": "string"
},
"copyResourcesToModuleRoot": {
"type": "boolean"
},
"Manifest": {
"type": "object",
"properties": {
Expand Down
Loading