Last active
November 1, 2021 23:10
-
-
Save sheldonhull/47b949c91ebc12b2836b985f30fe2c0d to your computer and use it in GitHub Desktop.
Using pwsh to edit package.json temporalio version update
This file contains hidden or 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
# 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