diff --git a/CHANGELOG.md b/CHANGELOG.md index e762d46..9ba0457 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 633d9e2..d56f40b 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 @@ -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. @@ -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 diff --git a/project.json b/project.json index b37e9c8..bcbe4d3 100644 --- a/project.json +++ b/project.json @@ -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", diff --git a/src/private/Build-Module.ps1 b/src/private/Build-Module.ps1 index badccf1..ba8b304 100644 --- a/src/private/Build-Module.ps1 +++ b/src/private/Build-Module.ps1 @@ -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 { diff --git a/src/public/GetMTProjectInfo.ps1 b/src/public/GetMTProjectInfo.ps1 index aebf7c2..e41247a 100644 --- a/src/public/GetMTProjectInfo.ps1 +++ b/src/public/GetMTProjectInfo.ps1 @@ -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") diff --git a/src/public/NewMTModule.ps1 b/src/public/NewMTModule.ps1 index c0aecae..02a42b6 100644 --- a/src/public/NewMTModule.ps1 +++ b/src/public/NewMTModule.ps1 @@ -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' @@ -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 } diff --git a/src/public/UpdateModVersion.ps1 b/src/public/UpdateModVersion.ps1 index ade6e1b..1d3c250 100644 --- a/src/public/UpdateModVersion.ps1 +++ b/src/public/UpdateModVersion.ps1 @@ -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) {