1

To run an external command as a grunt task, we can use grunt-shell, grunt-exec or grunt-spawn.

To build a project, I must ensure that a certain tool is installed. The tool isn't available via npm, but requires running a command to install. So I need to add a devDependency to a package.json that involves executing an external command. How can I do that?

Dan Dascalescu
  • 143,271
  • 52
  • 317
  • 404

1 Answers1

1

You can define preinstall/postinstall commands in the scripts block of the package.json:

{
  "scripts": {
    "preinstall": "your install-command",
    "postinstall": "your install-command"
  }
}

Choose which one fits your needs!

Dan Dascalescu
  • 143,271
  • 52
  • 317
  • 404
hereandnow78
  • 14,094
  • 8
  • 42
  • 48
  • Thanks! Unfortunately it looks like you can't pass an array of commands to the scripts. I wanted to add comments explaining what the script does, but JSON doesn't support comments. A way to bypass that would be to pass a shell comment (or echo) as the first value of "preinstall" in an array, but passing an array causes the scripts to do nothing. – Dan Dascalescu Nov 30 '14 at 21:23
  • you could concatenate commands with `&&`. i know it's not the optimal solution but it should work: `"preinstall": "echo 'this is your comment' && your-command"` – hereandnow78 Dec 01 '14 at 07:12