Skip to content

Commit 973f0ad

Browse files
authored
Merge pull request #21 from belibug/localpublish
Localpublish
2 parents 3775af7 + 2abea59 commit 973f0ad

3 files changed

Lines changed: 55 additions & 1 deletion

File tree

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.4.1",
4+
"Version": "1.5.0",
55
"copyResourcesToModuleRoot": false,
66
"Manifest": {
77
"Author": "Manjunath Beli",

src/private/GetLocalModulePath.ps1

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
function Get-LocalModulePath {
2+
$sep = [IO.Path]::PathSeparator
3+
4+
$ModulePaths = $env:PSModulePath -split $sep | ForEach-Object { $_.Trim() } | Select-Object -Unique
5+
6+
if ($IsWindows) {
7+
$MatchPattern = '\\Documents\\PowerShell\\Modules'
8+
$Result = $ModulePaths | Where-Object { $_ -match $MatchPattern } | Select-Object -First 1
9+
if ($Result -and (Test-Path $Result)) {
10+
return $Result
11+
} else {
12+
throw "No windows module path matching $MatchPattern found"
13+
}
14+
} else {
15+
# For Mac and Linux
16+
$MatchPattern = '/\.local/share/powershell/Modules$'
17+
$Result = $ModulePaths | Where-Object { $_ -match $MatchPattern } | Select-Object -First 1
18+
if ($Result -and (Test-Path $Result)) {
19+
return $Result
20+
} else {
21+
throw "No macOS/Linux module path matching $MatchPattern found in PSModulePath."
22+
}
23+
}
24+
}

src/public/PublishMTLocal.ps1

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
function Publish-MTLocal {
2+
[CmdletBinding()]
3+
param(
4+
[string]$ModuleDirectoryPath
5+
)
6+
7+
if ($ModuleDirectoryPath) {
8+
if (-not (Test-Path $ModuleDirectoryPath -PathType Container)) {
9+
New-Item $ModuleDirectoryPath -ItemType Directory -Force | Out-Null
10+
}
11+
} else {
12+
$ModuleDirectoryPath = Get-LocalModulePath
13+
}
14+
15+
$ProjectInfo = Get-MTProjectInfo
16+
17+
# Ensure module is locally built and ready
18+
if (-not (Test-Path $ProjectInfo.OutputModuleDir)) {
19+
trhow 'Dist folder is empty, build the module before running publish command'
20+
}
21+
22+
# Cleanup old files
23+
$OldModule = Join-Path -Path $ModuleDirectoryPath -ChildPath $ProjectInfo.ProjectName
24+
if (Test-Path -Path $OldModule) {
25+
Remove-Item -Recurse $OldModule -Force
26+
}
27+
28+
# Copy New Files
29+
Copy-Item -Path $ProjectInfo.OutputModuleDir -Destination $ModuleDirectoryPath -Recurse -ErrorAction Stop
30+
}

0 commit comments

Comments
 (0)