Skip to content

Instantly share code, notes, and snippets.

@sheldonhull
Last active November 1, 2021 23:10
Show Gist options
  • Save sheldonhull/47b949c91ebc12b2836b985f30fe2c0d to your computer and use it in GitHub Desktop.
Save sheldonhull/47b949c91ebc12b2836b985f30fe2c0d to your computer and use it in GitHub Desktop.
Using pwsh to edit package.json temporalio version update
# this uses aliases to simulate what a linux user would normally expect to write
# idiomatic powershell leans on clarity over being terse, so "%" would be ForEach-Object for example.
$Files = gci -Recurse -Filter package.json | Where Name -notmatch "node_modules" | % { [pscustomobject]@{FullName = $_.FullName; Content = (gc $_.FullName -raw | ConvertFrom-Json) }}
$UpdateFiles = $files | ? {$_.Content.Dependencies -match 'temporalio'}
$UpdateFiles | % {
$f = $_ # $_ = pipelined object with all properties available
$f.Content.Dependencies.temporalio = '^0.13.0' # this is object property reference because ConvertFrom-Json gave us an object, not raw text
$f.Content | ConvertTo-Json -depth 100 | Out-File -Path $f.FullName -Force # convert back to json as it was actually an object
}
# Note this could be turned into a long one liner, but it's better to break into steps like this for easy review.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment