Edit package.json from command line

前端 未结 5 429
北恋
北恋 2021-01-30 01:19

I\'m trying to add or edit a variable in my package.json from a shell script. So if i have a package.json like this:

{
  \"name\": \"my-project\",
  \"descripti         


        
5条回答
  •  -上瘾入骨i
    2021-01-30 02:03

    The package.json is just a json file, so you could use the tool json. To install it use:

    npm install -g json
    

    Then you can edit a file in-place. More information here.

    Example

    $ cat package.json
    {
      "name": "my-project",
      "description": "Project by @DerZyklop",
      "version": "0.0.0"
    }
    
    $ json -I -f package.json -e 'this.foo="bar"'
    json: updated "package.json" in-place
    
    $ cat package.json
    {
      "name": "my-project",
      "description": "Project by @DerZyklop",
      "version": "0.0.0",
      "foo": "bar"
    }
    

提交回复
热议问题