Replace an entire line in package.json using bash tools

Viewed 2884

I am working on a command line that will install every required node for a nodejs project.

Currently you can do:

sudo gen-web-app express

and this will genereate everything you need to start developing for expressjs.

I'm working now on

sudo gen-web-app reactjs

Everything is working except I have to go manually in the package.json and add the startup script to the file. I know this is possible using SED In BASH, but I need a little help using sed.

This is the file:

{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "nodemon": "^1.11.0",
    "path": "^0.12.7",
    "react": "^15.6.1",
    "webpack": "^3.1.0",
    "webpack-dev-server": "^2.5.1"
  }
}

I want to replace the following, but I would appreciate a little help :)

"test": "echo \"Error: no test specified\" && exit 1"

with

"start": "webpack-dev-server"
3 Answers
Related