Last active
January 20, 2019 09:21
-
-
Save Arcanemagus/f3c435fad0b531267e2ef8ba5790c209 to your computer and use it in GitHub Desktop.
Runs npm prune + dedupe + update on all subdirectories that have a package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Exec | |
{ | |
[CmdletBinding()] | |
param ( | |
[Parameter(Position=0, Mandatory=1)] | |
[scriptblock]$Command, | |
[Parameter(Position=1, Mandatory=0)] | |
[string]$ErrorMessage = "Execution of command failed.`n$Command" | |
) | |
& $Command | |
if ($LastExitCode -ne 0) { | |
throw "Exec: $ErrorMessage" | |
} | |
} | |
Get-ChildItem -Depth 1 | where { $_.name -eq "package.json" } | ForEach-Object { | |
$dirName = (Split-Path ($_.DirectoryName) -Leaf); | |
Write-Host "Updating ${dirName}:"; | |
Push-Location $_.DirectoryName; | |
Exec { npm prune } | |
Exec { npm dedupe } | |
Exec { npm update } | |
Exec { git gc } | |
Pop-Location; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment