Skip to content

Instantly share code, notes, and snippets.

@shama
Created October 24, 2012 18:24
Show Gist options
  • Save shama/3947882 to your computer and use it in GitHub Desktop.
Save shama/3947882 to your computer and use it in GitHub Desktop.
Instances Where The Grunt Bin Is Needed

Never mind about everything below. I overcomplicated something very simple. Spawn child process with process.argv[0] and use process.argv[1] as the first argument. Duh.

Instances Where The Grunt Bin Is Needed

  1. Project w/ Locally Installed Grunt

    Unix: [cwd]/node_modules/.bin/grunt

    Win: [cwd]/node_modules/.bin/grunt.cmd

  2. Project w/ Globally Installed Grunt (not installed locally, Grunt v0.3)

    Unix: process.argv[1] ([npm]/grunt)

    Win: process.argv[1] (AppData\Roaming\npm\node_modules\grunt\bin\grunt)

    On Unix, process.execPath is the same as process.argv[1]. On Windows, process.execPath is different: C:\Program Files\nodejs\ where process.argv[1] would be AppData\Roaming\npm\node_modules\grunt\bin\grunt. So appending .cmd doesn't work with this option on Windows currently.

    It should be AppData\Roaming\npm\grunt.cmd so maybe a findup from process.argv[1] is the solution for Windows.

  3. Running Tests While Developing grunt-contrib-watch

    Unix: [__dirname]/../node_modules/.bin/grunt

    Win: [__dirname]/../node_modules/.bin/grunt.cmd

    This is because the tests use a different cwd for fixtures and they don't install grunt locally to each fixture.

  4. Running Watch While Developing grunt

    Since node_modules/.bin/grunt doesn't exist on grunt itself we have to use the globally installed grunt in instance 2.

    When Grunt v0.4 must be installed locally, the watch would do: [cwd]/bin/grunt. Although still won't work with Windows as [cwd]\bin\grunt.cmd doesn't exist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment