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
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

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

## [1.2.0] - 2025-09-17

### Added
- Added support for classes directory inside src
- New-MTModule generates classes directory during fresh project
- `classes` directory should include `.ps1` files which contain enums and classes

### Fixed
- Version upgrade using update-mtmoduleversion now support build tags. Improvements to semver versioning.

## [1.1.3] - 2025-09-14

### Added
Expand Down
21 changes: 13 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ All the Module files should be in inside `src` folder
│ └──  New-PublicFunction.ps1
├──  resources
│ └──  some-config.json
└──  tests
└──  Pester.Some.Tests.ps1
└──  classes
└──  Person.classes.ps1
└──  Person.enums.ps1
```

### Dist Folder
Expand All @@ -71,6 +72,7 @@ Run `New-MTModule` to generate the scaffolding; this will also create the `proje
- 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.
- All `ps1` files in `classes` folder contains classes and enums, that are processed and placed in topmost of generated `psm1` files
- Contents of the `src/resources` folder will be handled based on setting `copyResourcesToModuleRoot`

#### Resources Folder
Expand Down Expand Up @@ -149,12 +151,15 @@ All the pester configurations are stored in `project.json`, simply run `Invoke-M

A simple command to update the module version by modifying the values in `project.json`. You can also manually edit the file in your favorite editor. This command makes it easy to update the semantic version.

- Running `Update-MTModuleVersion` without any parameters will update the patch version (e.g., 1.0.1 -> 1.0.2).
- Running `Update-MTModuleVersion -Label Major` updates the major version (e.g., 1.0.1 -> 2.0.1).
- Running `Update-MTModuleVersion -Label Minor` updates the minor version (e.g., 1.0.1 -> 1.1.1).
- Running `Update-MTModuleVersion` without any parameters will update the patch version (e.g., 1.2.3 -> 1.2.4)
- Running `Update-MTModuleVersion -Label Major` updates the major version and resets Minor, Patch to 0 (e.g., 1.2.1 -> 2.0.0)
- Running `Update-MTModuleVersion -Label Minor` updates the minor version and resets Patch to 0 (e.g., 1.2.3 -> 1.3.0)

## Advanced - Use it in Github Actions

> [!TIP]
> This repository uses Github actions to run tests and publish to PowerShell Gallery, use it as reference.

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.
Expand Down Expand Up @@ -202,12 +207,12 @@ jobs:

## 📝 Requirement

- Only tested on PowerShell 7.4, most likely wont work on 5.1
- No depenedencies. This module doesn’t depend on any other module.
- Only tested on PowerShell 7.4, ~most likely~ will not work on 5.1. Underlying module can still support older version, only the ModuleTools builder wont work on older version.
- No depenedencies. This module doesn’t depend on any other module. Completely self contained

## ✅ ToDo

- [ ] Support Classes and Enums in modules
- [ ] Add more tests

## 🤝 Contributing

Expand Down
2 changes: 1 addition & 1 deletion project.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"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": "1.1.3",
"Version": "1.2.0",
"copyResourcesToModuleRoot": false,
"Manifest": {
"Author": "Manjunath Beli",
Expand Down
6 changes: 6 additions & 0 deletions src/private/Build-Module.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ function Build-Module {

$sb = [System.Text.StringBuilder]::new()

# Classes Folder
$files = Get-ChildItem -Path $data.ClassesDir -Filter *.ps1 -ErrorAction SilentlyContinue
$files | ForEach-Object {
$sb.AppendLine([IO.File]::ReadAllText($_.FullName)) | Out-Null
}

# Public Folder
$files = Get-ChildItem -Path $data.PublicDir -Filter *.ps1
$files | ForEach-Object {
Expand Down
2 changes: 2 additions & 0 deletions src/public/GetMTProjectInfo.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ function Get-MTProjectInfo {
$Out['ProjectRoot'] = $ProjectRoot
$Out['PublicDir'] = [System.IO.Path]::Join($ProjectRoot, 'src', 'public')
$Out['PrivateDir'] = [System.IO.Path]::Join($ProjectRoot, 'src', 'private')
$Out['ClassesDir'] = [System.IO.Path]::Join($ProjectRoot, 'src', 'classes')
$Out['ResourcesDir'] = [System.IO.Path]::Join($ProjectRoot, 'src', 'resources')
$Out['OutputDir'] = [System.IO.Path]::Join($ProjectRoot, 'dist')
$Out['OutputModuleDir'] = [System.IO.Path]::Join($Out.OutputDir, $ProjectName)
$Out['ModuleFilePSM1'] = [System.IO.Path]::Join($Out.OutputModuleDir, "$ProjectName.psm1")
Expand Down
3 changes: 2 additions & 1 deletion src/public/NewMTModule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ function New-MTModule {
$DirPrivate = Join-Path -Path $DirSrc -ChildPath 'private'
$DirPublic = Join-Path -Path $DirSrc -ChildPath 'public'
$DirResources = Join-Path -Path $DirSrc -ChildPath 'resources'
$DirClasses = Join-Path -Path $DirSrc -ChildPath 'classes'
$DirTests = Join-Path -Path $DirProject -ChildPath 'tests'
$ProjectJSONFile = Join-Path $DirProject -ChildPath 'project.json'

Expand All @@ -100,7 +101,7 @@ function New-MTModule {

Write-Message "`nStarted Module Scaffolding" -color Green
Write-Message 'Setting up Directories'
($DirProject, $DirSrc, $DirPrivate, $DirPublic, $DirResources) | ForEach-Object {
($DirProject, $DirSrc, $DirPrivate, $DirPublic, $DirResources, $DirClasses) | ForEach-Object {
'Creating Directory: {0}' -f $_ | Write-Verbose
New-Item -ItemType Directory -Path $_ | Out-Null
}
Expand Down
18 changes: 14 additions & 4 deletions src/public/UpdateModVersion.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,21 @@ function Update-MTModuleVersion {
$jsonContent = Get-Content -Path $data.ProjecJSON | ConvertFrom-Json

[semver]$CurrentVersion = $jsonContent.Version

$Major = ($Label -eq 'Major') ? ($CurrentVersion.Major + 1) : $CurrentVersion.Major
$Minor = ($Label -eq 'Minor') ? ($CurrentVersion.Minor + 1) : $CurrentVersion.Minor
$Patch = ($Label -eq 'Patch') ? ($CurrentVersion.Patch + 1) : $CurrentVersion.Patch

if ($Label -eq 'Major') {
$Major = $CurrentVersion.Major + 1
$Minor = 0
$Patch = 0
} elseif ($Label -eq 'Minor') {
$Major = $CurrentVersion.Major
$Minor = $CurrentVersion.Minor + 1
$Patch = 0
} elseif ($Label -eq 'Patch') {
$Major = $CurrentVersion.Major
$Minor = $CurrentVersion.Minor
$Patch = $CurrentVersion.Patch + 1
}

if ($PreviewRelease) {
$ReleaseType = 'preview'
} elseif ($StableRelease) {
Expand Down
Loading