From b8d0431bf0ae6aa74f4de14bfc6c4fa570df9f64 Mon Sep 17 00:00:00 2001 From: Manjunath Beli Date: Fri, 13 Mar 2026 10:38:13 -0500 Subject: [PATCH 1/2] Local Module Publishing --- project.json | 2 +- src/private/GetLocalModulePath.ps1 | 24 ++++++++++++++++++++++++ src/public/PublishMTLocal.ps1 | 28 ++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 src/private/GetLocalModulePath.ps1 create mode 100644 src/public/PublishMTLocal.ps1 diff --git a/project.json b/project.json index 08e84bf..be7ace8 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.4.1", + "Version": "1.5.0", "copyResourcesToModuleRoot": false, "Manifest": { "Author": "Manjunath Beli", diff --git a/src/private/GetLocalModulePath.ps1 b/src/private/GetLocalModulePath.ps1 new file mode 100644 index 0000000..6712f8c --- /dev/null +++ b/src/private/GetLocalModulePath.ps1 @@ -0,0 +1,24 @@ +function Get-LocalModulePath { + $sep = [IO.Path]::PathSeparator + + $ModulePaths = $env:PSModulePath -split $sep | ForEach-Object { $_.Trim() } | Select-Object -Unique + + if ($IsWindows) { + $MatchPattern = '\\Documents\\PowerShell\\Modules' + $Result = $ModulePaths | Where-Object { $_ -match $MatchPattern } | Select-Object -First 1 + if ($Result -and (Test-Path $Result)) { + return $Result + } else { + throw "No windows module path matching $MatchPattern found" + } + } else { + # For Mac and Linux + $MatchPattern = '/\.local/share/powershell/Modules$' + $Result = $ModulePaths | Where-Object { $_ -match $MatchPattern } | Select-Object -First 1 + if ($Result -and (Test-Path $Result)) { + return $Result + } else { + throw "No macOS/Linux module path matching $MatchPattern found in PSModulePath." + } + } +} \ No newline at end of file diff --git a/src/public/PublishMTLocal.ps1 b/src/public/PublishMTLocal.ps1 new file mode 100644 index 0000000..c13d899 --- /dev/null +++ b/src/public/PublishMTLocal.ps1 @@ -0,0 +1,28 @@ +function Publish-MTLocal { + [CmdletBinding()] + param( + [string]$ModuleDirectoryPath + ) + + if ($ModuleDirectoryPath -and (-not (Test-Path $ModuleDirectoryPath -PathType Container)) ) { + New-Item $ModuleDirectoryPath -ItemType Directory -Force + } else { + $ModuleDirectoryPath = Get-LocalModulePath + } + + $ProjectInfo = Get-MTProjectInfo + + # Ensure module is locally built and ready + if (-not (Test-Path $ProjectInfo.OutputModuleDir)) { + trhow 'Dist folder is empty, build the module before running publish command' + } + + # Cleanup old files + $OldModule = Join-Path -Path $ModuleDirectoryPath -ChildPath $ProjectInfo.ProjectName + if (Test-Path -Path $OldModule) { + Remove-Item -Recurse $OldModule -Force + } + + # Copy New Files + Copy-Item -Path $ProjectInfo.OutputModuleDir -Destination $ModuleDirectoryPath -Recurse -ErrorAction Stop +} \ No newline at end of file From 2abea599297e0d0de8cc839bdaf66fa1659ddd2c Mon Sep 17 00:00:00 2001 From: Manjunath Beli Date: Fri, 13 Mar 2026 10:44:18 -0500 Subject: [PATCH 2/2] Local Module Publishing with input param --- src/public/PublishMTLocal.ps1 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/public/PublishMTLocal.ps1 b/src/public/PublishMTLocal.ps1 index c13d899..e9f7418 100644 --- a/src/public/PublishMTLocal.ps1 +++ b/src/public/PublishMTLocal.ps1 @@ -4,8 +4,10 @@ function Publish-MTLocal { [string]$ModuleDirectoryPath ) - if ($ModuleDirectoryPath -and (-not (Test-Path $ModuleDirectoryPath -PathType Container)) ) { - New-Item $ModuleDirectoryPath -ItemType Directory -Force + if ($ModuleDirectoryPath) { + if (-not (Test-Path $ModuleDirectoryPath -PathType Container)) { + New-Item $ModuleDirectoryPath -ItemType Directory -Force | Out-Null + } } else { $ModuleDirectoryPath = Get-LocalModulePath }