🎃

jqでpackage.jsonのversion上書き

2022/01/11に公開

たまーにコマンドラインでやりたくなって、jq力がなくて毎回ググルのでメモ.

こんな感じのpackage.jsonのversion

{
  "name": "me.mattak.waveffector",
  "displayName": "WavEffector",
  "version": "0.0.0",
  "unity": "2020.1",
  "description": "Audio effect visualizing utility",
  "license": "MIT",
  "dependencies": {}
}

jq のargと+= operatorで行ける.

$ cat /tmp/package.json  | jq --arg version 0.1.0 '. += {"version": $version}'
{
  "name": "me.mattak.waveffector",
  "displayName": "WavEffector",
  "version": "0.1.0",
  "unity": "2020.1",
  "description": "Audio effect visualizing utility",
  "license": "MIT",
  "dependencies": {}
}

Discussion