Edit package.json from command line

前端 未结 5 425
北恋
北恋 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条回答
  •  隐瞒了意图╮
    2021-01-30 02:25

    There's also a npm package for doing this called npe: https://github.com/zeke/npe

    cd some/node/project
    
    # Get stuff from package.json
    npe name
    npe scripts
    npe scripts.test
    npe repository.url
    open $(npe repository.url)
    
    # Set stuff in package.json
    npe name foo
    npe scripts.start "node index.js"
    
    # Keywords string will be turned into an array
    # If commas are present, they'll be the delimiter. Otherwise spaces.
    npe keywords "foo, bar, cheese whiz"
    npe keywords "foo bar baz"
    
    # The current working directory's package.json is used by default,
    # but you can point to another package file with a flag:
    npe name --package=some/other/package.json
    npe name other --package=some/other/package.json
    

提交回复
热议问题