How to debug Gruntfile.js with log statements?
Asked Answered
M

4

7

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']
        },
    }
Madame answered 25/9, 2013 at 16:11 Comment(0)
S
9

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'));
}
Stiff answered 25/9, 2013 at 23:3 Comment(0)
T
3

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?

Theophilus answered 14/7, 2014 at 10:40 Comment(0)
L
2

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!

Lousy answered 25/9, 2013 at 16:23 Comment(0)
T
0

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

Tereasaterebene answered 26/8, 2014 at 14:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.