Gururaj
Gururaj

Reputation: 1155

How to debug Gruntfile.js with log statements?

In my Gruntfile, how can I add log statements, to its processing, as in the following example?

 karma: {
        unit: {
            configFile: "<%= grunt.option('Debug') ? 'build/karma.conf.js' : '' %>",
            console.log(configFile),
            singleRun: true,
            browsers: ['PhantomJS']
        },
    }

Upvotes: 7

Views: 16809

Answers (4)

chrisl-921fb74d
chrisl-921fb74d

Reputation: 23182

There are various tools like node inspector that'll allow one to debug these particular files.

On node inspector (from the github page):

Node Inspector is a debugger interface for Node.js applications that uses the Blink Developer Tools (formerly WebKit Web Inspector).

This stackoverflow question has some great answers regarding how to do this specifically: Using node-inspector with Grunt tasks

Upvotes: 0

Lee Goddard
Lee Goddard

Reputation: 11183

I'm not what you are asking, but if you want to place debug logging in a Gruntfile.js, have you seen the grunt.log method?

Upvotes: 3

Kyle Robinson Young
Kyle Robinson Young

Reputation: 13762

Gruntfiles are javascript so you can use console.log() where ever as long as it is valid javascript.

grunt.initConfig({
  karma: {
    unit: {
      configFile: 'build/karma.conf.js'
    }
  }
});
if (grunt.option('debug')) {
  console.log(grunt.config('karma.unit.configFile'));
}

Upvotes: 9

RomoCode
RomoCode

Reputation: 1119

It would be nice if it were that easy... console.log() only outputs client-side stuff to the client; however, since you're working on the server-side of things, you won't see anything pop up in the browser console (rather the server console, probably your terminal).

There is a way around this thanks to the work of others, for instance: https://github.com/ethanl/connect-browser-logger

This will basically hoist those server side logs out to the client for you to see. If you do a Google, you'll find a slew of other solutions (some with the ability to set breakpoints, step through code, etc).

Not shabby!

Edit: Christ, I just realized you wanted the logging specifically IN your gruntfile. That's a bit of a different story, but it still should work for you!

Upvotes: 2

Related Questions