Our plug-in’s main goal is to let a user open a web page or a URL with Grunt. Ideally, we’d like it to work like this:
$ grunt open:index.html
And then it would open that page in Google Chrome. To do this, we’ll have to detect the platform we’re running on so we can find out how to launch Chrome, and we’ll have to use some mechanism to make Grunt launch an external program. Grunt comes with grunt.util.spawn, which is perfect for this.
To call an external file from Grunt, we use Node.js’s built-in child_process module.
The exec method is a perfect fit for this situation. It takes in two arguments: the command we want to run and a callback function that executes when the command ...