Skip to content

Commit 1cecb08

Browse files
authored
Merge pull request #16 from belibug/Classes
Classes
2 parents 58796c8 + 52a2a7d commit 1cecb08

File tree

7 files changed

+48
-14
lines changed

7 files changed

+48
-14
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

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

5+
## [1.2.0] - 2025-09-17
6+
7+
### Added
8+
- Added support for classes directory inside src
9+
- New-MTModule generates classes directory during fresh project
10+
- `classes` directory should include `.ps1` files which contain enums and classes
11+
12+
### Fixed
13+
- Version upgrade using update-mtmoduleversion now support build tags. Improvements to semver versioning.
14+
515
## [1.1.3] - 2025-09-14
616

717
### Added

README.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ All the Module files should be in inside `src` folder
4545
│ └──  New-PublicFunction.ps1
4646
├──  resources
4747
│ └──  some-config.json
48-
└──  tests
49-
└──  Pester.Some.Tests.ps1
48+
└──  classes
49+
└──  Person.classes.ps1
50+
└──  Person.enums.ps1
5051
```
5152

5253
### Dist Folder
@@ -71,6 +72,7 @@ Run `New-MTModule` to generate the scaffolding; this will also create the `proje
7172
- Place all your functions in the `private` and `public` folders within the `src` directory.
7273
- All functions in the `public` folder are exported during the module build.
7374
- All functions in the `private` folder are accessible internally within the module but are not exposed outside the module.
75+
- All `ps1` files in `classes` folder contains classes and enums, that are processed and placed in topmost of generated `psm1` files
7476
- Contents of the `src/resources` folder will be handled based on setting `copyResourcesToModuleRoot`
7577

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

150152
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.
151153

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

156158
## Advanced - Use it in Github Actions
157159

160+
> [!TIP]
161+
> This repository uses Github actions to run tests and publish to PowerShell Gallery, use it as reference.
162+
158163
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:
159164

160165
1. Checking out the repository code.
@@ -202,12 +207,12 @@ jobs:
202207
203208
## 📝 Requirement
204209
205-
- Only tested on PowerShell 7.4, most likely wont work on 5.1
206-
- No depenedencies. This module doesn’t depend on any other module.
210+
- 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.
211+
- No depenedencies. This module doesn’t depend on any other module. Completely self contained
207212
208213
## ✅ ToDo
209214
210-
- [ ] Support Classes and Enums in modules
215+
- [ ] Add more tests
211216
212217
## 🤝 Contributing
213218

project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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": "1.1.3",
4+
"Version": "1.2.0",
55
"copyResourcesToModuleRoot": false,
66
"Manifest": {
77
"Author": "Manjunath Beli",

src/private/Build-Module.ps1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ function Build-Module {
55

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

8+
# Classes Folder
9+
$files = Get-ChildItem -Path $data.ClassesDir -Filter *.ps1 -ErrorAction SilentlyContinue
10+
$files | ForEach-Object {
11+
$sb.AppendLine([IO.File]::ReadAllText($_.FullName)) | Out-Null
12+
}
13+
814
# Public Folder
915
$files = Get-ChildItem -Path $data.PublicDir -Filter *.ps1
1016
$files | ForEach-Object {

src/public/GetMTProjectInfo.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ function Get-MTProjectInfo {
3535
$Out['ProjectRoot'] = $ProjectRoot
3636
$Out['PublicDir'] = [System.IO.Path]::Join($ProjectRoot, 'src', 'public')
3737
$Out['PrivateDir'] = [System.IO.Path]::Join($ProjectRoot, 'src', 'private')
38+
$Out['ClassesDir'] = [System.IO.Path]::Join($ProjectRoot, 'src', 'classes')
39+
$Out['ResourcesDir'] = [System.IO.Path]::Join($ProjectRoot, 'src', 'resources')
3840
$Out['OutputDir'] = [System.IO.Path]::Join($ProjectRoot, 'dist')
3941
$Out['OutputModuleDir'] = [System.IO.Path]::Join($Out.OutputDir, $ProjectName)
4042
$Out['ModuleFilePSM1'] = [System.IO.Path]::Join($Out.OutputModuleDir, "$ProjectName.psm1")

src/public/NewMTModule.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ function New-MTModule {
9090
$DirPrivate = Join-Path -Path $DirSrc -ChildPath 'private'
9191
$DirPublic = Join-Path -Path $DirSrc -ChildPath 'public'
9292
$DirResources = Join-Path -Path $DirSrc -ChildPath 'resources'
93+
$DirClasses = Join-Path -Path $DirSrc -ChildPath 'classes'
9394
$DirTests = Join-Path -Path $DirProject -ChildPath 'tests'
9495
$ProjectJSONFile = Join-Path $DirProject -ChildPath 'project.json'
9596

@@ -100,7 +101,7 @@ function New-MTModule {
100101

101102
Write-Message "`nStarted Module Scaffolding" -color Green
102103
Write-Message 'Setting up Directories'
103-
($DirProject, $DirSrc, $DirPrivate, $DirPublic, $DirResources) | ForEach-Object {
104+
($DirProject, $DirSrc, $DirPrivate, $DirPublic, $DirResources, $DirClasses) | ForEach-Object {
104105
'Creating Directory: {0}' -f $_ | Write-Verbose
105106
New-Item -ItemType Directory -Path $_ | Out-Null
106107
}

src/public/UpdateModVersion.ps1

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,21 @@ function Update-MTModuleVersion {
3737
$jsonContent = Get-Content -Path $data.ProjecJSON | ConvertFrom-Json
3838

3939
[semver]$CurrentVersion = $jsonContent.Version
40-
41-
$Major = ($Label -eq 'Major') ? ($CurrentVersion.Major + 1) : $CurrentVersion.Major
42-
$Minor = ($Label -eq 'Minor') ? ($CurrentVersion.Minor + 1) : $CurrentVersion.Minor
43-
$Patch = ($Label -eq 'Patch') ? ($CurrentVersion.Patch + 1) : $CurrentVersion.Patch
4440

41+
if ($Label -eq 'Major') {
42+
$Major = $CurrentVersion.Major + 1
43+
$Minor = 0
44+
$Patch = 0
45+
} elseif ($Label -eq 'Minor') {
46+
$Major = $CurrentVersion.Major
47+
$Minor = $CurrentVersion.Minor + 1
48+
$Patch = 0
49+
} elseif ($Label -eq 'Patch') {
50+
$Major = $CurrentVersion.Major
51+
$Minor = $CurrentVersion.Minor
52+
$Patch = $CurrentVersion.Patch + 1
53+
}
54+
4555
if ($PreviewRelease) {
4656
$ReleaseType = 'preview'
4757
} elseif ($StableRelease) {

0 commit comments

Comments
 (0)