Skip to content

Commit

Permalink
Improve vars name and shorten cmdlets name from VERB-LocalNAME in VER…
Browse files Browse the repository at this point in the history
…B-LNAME, improve manifest
  • Loading branch information
HumanAgainstMachine committed Oct 20, 2024
1 parent ea4991d commit cd2a6d8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 25 deletions.
22 changes: 19 additions & 3 deletions localmodules/LocalModules.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 30,11 @@ CompanyName = 'Unknown'
Copyright = '(c) Human.Against.Machine. All rights reserved.'

# Description of the functionality provided by this module
Description = "LocalModules allows you to install and uninstall PowerShell (PS) modules that are not yet published to a repository, facilitating a quicker development and testing cycle. Additionally, it enables you to set up a local repository for testing PS module publishing."
Description = @'
LocalModules allows you to easily install and uninstall PowerShell (PS) modules that are still under development and not yet ready for publishing. This streamlines the development and testing process.
Additionally, it supports setting up a local repository for testing PS module publishing.
'@

# Minimum version of the PowerShell engine required by this module
PowerShellVersion = '7.1'
Expand Down Expand Up @@ -95,7 99,7 @@ PrivateData = @{
PSData = @{

# Tags applied to this module. These help with module discovery in online galleries.
Tags = @('Windows', 'DevOps', 'PackageManagement')
Tags = @('Powershell', 'DevOps', 'PackageManagement', 'Modules', 'PS', 'Local')

# A URL to the license for this module.
LicenseUri = 'https://github.com/HumanAgainstMachine/LocalModules?tab=MIT-1-ov-file'
Expand All @@ -107,7 111,19 @@ PrivateData = @{
# IconUri = ''

# ReleaseNotes of this module
# ReleaseNotes = ''
ReleaseNotes = @'
[ver 1.0.0] - 2024-10-20
* Improve vars and cmdlets names
* Improve manifest
* Under-development modules are now installed in a separate folder named 0.0.0 as they were version 0.0.0.
Any configuration files outside the 0.0.0 folder will be preserved.
[ver 0.9.1] - 2024-07-01
Improve cmdlets Set-LocalRepo and Remove-LocalRepo
[ver 0.9.0] - 2024-06-23
Initial release
'@

# Prerelease string of this module
# Prerelease = ''
Expand Down
41 changes: 19 additions & 22 deletions localmodules/LocalModules.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 6,21 @@
Cmdlets to manage a local modules for current user
#>

# The folder where are under development modules
$localModulesPath = 'C:\Users\Admin\works' # to be used later ...

$localRepoPath = Join-Path -Path $env:USERPROFILE -ChildPath 'LocalRepo'

# Get path to user-specific installed modules
$userModulesPath = $env:PSModulePath -split ';' | Where-Object { $_ -like [Environment]::GetFolderPath('MyDocuments') '*'}
# From all available paths, select only the user-specific path to installed modules
$myModulePath = $env:PSModulePath -split ';' | Where-Object { $_ -like [Environment]::GetFolderPath('MyDocuments') '*'}

if (-not ($userModulesPath)) {
if (-not ($myModulePath)) {
Write-Host "User-specific module path " -NoNewline -ForegroundColor Red
Write-Host $userModulesPath -NoNewline -ForegroundColor DarkGray
Write-Host $myModulePath -NoNewline -ForegroundColor DarkGray
Write-Host " not found in PSModulePath." -ForegroundColor Red
Exit 2
}

$RepoInstalledModules = (Get-InstalledModule).Name
$repoInstalledModNames = (Get-InstalledModule).Name

function Install-LocalModule {
function Install-LModule {
<#
.SYNOPSIS
Install a local module bypassing repositories
Expand All @@ -42,13 39,13 @@ function Install-LocalModule {
# Get module name from folder name
$moduleName = Split-Path -Path $Path -Leaf

if ($RepoInstalledModules -contains $moduleName) {# Local module installed from a repo check
if ($repoInstalledModNames -contains $moduleName) {# Local module installed from a repo check
Write-Host "$moduleName already installed from a repository" -ForegroundColor Red
Write-Host "Uninstall any version installed from a repository before continuing" -ForegroundColor DarkYellow
}
else {
# Uninstall previous local module if exist
$ver0ModulePath = Join-Path $userModulesPath $moduleName '0.0.0'
$ver0ModulePath = Join-Path $myModulePath $moduleName '0.0.0'
Remove-Item -Path $ver0ModulePath -Recurse -Force -ErrorAction SilentlyContinue

# Install current local module
Expand Down Expand Up @@ -93,7 90,7 @@ function Install-LocalModule {
}


function Uninstall-LocalModule {
function Uninstall-LModule {
<#
.SYNOPSIS
Uninstall a local module
Expand All @@ -106,13 103,13 @@ function Uninstall-LocalModule {
[String]$Name
)

# $ver0ModulePath = Join-Path -Path $userModulesPath -ChildPath $Name
$ver0ModulePath = Join-Path $userModulesPath $Name '0.0.0'
# $ver0ModulePath = Join-Path -Path $myModulePath -ChildPath $Name
$ver0ModulePath = Join-Path $myModulePath $Name '0.0.0'

# Local module installed check
if (Test-Path -Path $ver0ModulePath -PathType Container) {

if ($RepoInstalledModules -contains $Name) {# Local module installed from a repo check
if ($repoInstalledModNames -contains $Name) {# Local module installed from a repo check
Write-Host "$Name is installed from a repository. Use cmdlet Uninstall-Module to uninstall it"
} else {
Remove-Item -Path $ver0ModulePath -Recurse -Force
Expand All @@ -123,7 120,7 @@ function Uninstall-LocalModule {
}
}

function Get-LocalInstalledModule {
function Get-LInstalledModule {
<#
.SYNOPSIS
Get locally installed modules
Expand All @@ -133,20 130,20 @@ function Get-LocalInstalledModule {
[CmdletBinding()]
param ()
# Get all directories in user modules path
$installedModules = (Get-ChildItem -Path $userModulesPath -Directory).Name
$localInstalledModules = Compare-Object -ReferenceObject $installedModules -DifferenceObject $RepoInstalledModules -PassThru |
$allInstalledModNames = (Get-ChildItem -Path $myModulePath -Directory).Name
$localInstalledModNames = Compare-Object -ReferenceObject $allInstalledModNames -DifferenceObject $repoInstalledModNames -PassThru |
Where-Object { $_.SideIndicator -eq "<=" }

if ($localInstalledModules.Count -eq 0) {
if ($localInstalledModNames.Count -eq 0) {
Write-Host "No local modules found." -ForegroundColor DarkYellow
} else {
Write-Host "`nName`n----" -ForegroundColor Green
Write-Host $localInstalledModules -Separator "`n"
Write-Host $localInstalledModNames -Separator "`n"
Write-Host " "
}
}

function Set-LocalRepo {
function Set-LRepo {
<#
.SYNOPSIS
Set up LocalRepo repository on the file system
Expand All @@ -171,7 168,7 @@ function Set-LocalRepo {
}
}

function Remove-LocalRepo {
function Remove-LRepo {
<#
.SYNOPSIS
Remove LocalRepo repository from the file system
Expand Down

0 comments on commit cd2a6d8

Please sign in to comment.