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
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.4.1",
"Version": "1.5.0",
"copyResourcesToModuleRoot": false,
"Manifest": {
"Author": "Manjunath Beli",
Expand Down
24 changes: 24 additions & 0 deletions src/private/GetLocalModulePath.ps1
Original file line number Diff line number Diff line change
@@ -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."
}
}
}
30 changes: 30 additions & 0 deletions src/public/PublishMTLocal.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
function Publish-MTLocal {
[CmdletBinding()]
param(
[string]$ModuleDirectoryPath
)

if ($ModuleDirectoryPath) {
if (-not (Test-Path $ModuleDirectoryPath -PathType Container)) {
New-Item $ModuleDirectoryPath -ItemType Directory -Force | Out-Null
}
} 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
}
Loading