Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OS-independent grunt script command in NPM package.json

When the command grunt is run in a Windows shell in the same path as the grunt.js file, Windows opts to run grunt.js using the Windows Script Host. The recommended path is to explicitly call grunt.cmd.

That's all fine and dandy, but what can I do if I want to create an OS-independent script command in my NPM package.json? I can't do this if I want to also run in *nix:

"scripts": {
    "dox": "grunt.cmd dox"
}

Any pointers? Or, is there a big piece of the puzzle that I'm missing? (I'm equally new to both NPM and Grunt).

like image 305
Ates Goral Avatar asked Nov 06 '12 02:11

Ates Goral


1 Answers

I've found the solution in creating a grunt.bat file that just calls grunt.cmd:

@grunt.cmd %*

Therefore, on Windows, just invoking grunt triggers the batch file since it gets higher priority than Windows Scripting Host's picking up of grunt.js. On Linux, the regular grunt binary gets picked up. This works cross-platform for me now.

like image 136
Ates Goral Avatar answered Sep 30 '22 07:09

Ates Goral