Running a command in a Grunt Task

JuanO picture JuanO · May 5, 2012 · Viewed 68.2k times · Source

I'm using Grunt (task-based command line build tool for JavaScript projects) in my project. I've created a custom tag and I am wondering if it is possible to run a command into it.

To clarify, I'm trying to use Closure Templates and "the task" should call the jar file to pre-compile the Soy file to a javascript file.

I'm running this jar from command line, but I want to set it as a task.

Answer

papercowboy picture papercowboy · Nov 2, 2012

Alternatively you could load in grunt plugins to help this:

grunt-shell example:

shell: {
  make_directory: {
    command: 'mkdir test'
  }
}

or grunt-exec example:

exec: {
  remove_logs: {
    command: 'rm -f *.log'
  },
  list_files: {
    command: 'ls -l **',
    stdout: true
  },
  echo_grunt_version: {
    command: function(grunt) { return 'echo ' + grunt.version; },
    stdout: true
  }
}