-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathModule-Helpers.ps1
37 lines (32 loc) · 1.01 KB
/
Module-Helpers.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# --------
# Helpers
# --------
Function Backup-Modules {
$modpath = ($env:PSModulePath -split ";")[0]
$ymlpath = "$modpath\modules.yml"
$jsonpath = "$modpath\modules.json"
$mods = (Get-ChildItem $modpath -Directory).Name
If (!(Get-Module -Name powershell-yaml -ErrorAction SilentlyContinue)) {
ConvertTo-Json $mods > $jsonpath
} else {
ConvertTo-Yaml -Data $mods -OutFile $ymlpath -Force
}
}
Function Sync-Modules {
$psdir = (Split-Path -Parent $profile)
Set-Location $psdir
git pull
git add PowerShell/Modules/**
git commit -m "config: Updated modules configurations"
git-cliff -o "$HOME\Documents\CHANGELOG.md"
git add CHANGELOG.md
git commit -m "doc: update CHANGELOG.md for added modules"
git push
}
Function Restore-Modules {
$mods = Get-Content ~/.dotfiles/powershell/modules.json | ConvertFrom-Json
foreach ($mod in $mods) {
Write-Host "Installing PowerShell Module for Current User: $mod" -ForegroundColor Yellow
Install-Module $mod -Scope CurrentUser -Force
}
}