Skip to content

Instantly share code, notes, and snippets.

@Arcanemagus
Last active January 20, 2019 09:21
Show Gist options
  • Save Arcanemagus/f3c435fad0b531267e2ef8ba5790c209 to your computer and use it in GitHub Desktop.
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
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