Skip to content
Scott P edited this page Jul 6, 2014 · 10 revisions

Running Grunt Tasks

You can manually run the grunt tasks on which lineman is built with the lineman grunt command. (It just delegates through to grunt.) You can also run any additional grunt tasks that you've added yourself.

$ lineman grunt <taskname>

Loading Grunt Tasks

Lineman can easily be extended to do extra grunt-work for your application above-and-beyond the built-in grunt tasks. You may add tasks to your project in several ways:

  • Custom tasks you've written yourself:
    1. add it to the tasks/ directory. Lineman will automatically load any tasks found here.
  • npm-packaged tasks:
    1. add it to your package.json as a dependency
    2. add it to the loadNpmTasks key in config/application.js using the task's npm module name (normally used in grunt.loadNpmTasks(<module_name>))
    3. run npm install
  • npm install --save or --save-dev
    1. use --save for runtime dependencies and --save-dev for development dependencies
    2. npm install <grunt-pkg> --save or npm install <grunt-pkg> --save-dev
    3. add or add to the loadNpmTasks key in config/application.js' loadNPMTasks: ['grunt-pkg'],`
    4. add or add to the prependTasks or appendTasks as below.

Once they're loaded, you can manually run the task from the command line using lineman grunt. But you're probably more interested in having these tasks run alongside the other tasks as part of lineman run and/or lineman build...

Adding tasks to Lineman's run/build process

You can add any task to the lineman run/build processes by adding it to the appropriate array under the prependTasks and appendTasks objects in config/application.js:

  prependTasks: {
    common: ["A"],
    dev: ["B"],
    dist: ["C"]
  },
  appendTasks: {
    common: ["D"],
    dev: ["E"],
    dist: ["F"]
  }

In the above example, tasks "A" & "D" would run during both lineman run and lineman build. Meanwhile, "B" & "E" would run only during lineman run, while "C" & "F" would only run during lineman build.

Tasks specified under prependTasks will be run before Lineman's built-in tasks for the corresponding phase (dev or dist), while tasks specified under appendTasks will run immediately afterward. For reference, check out Lineman's default configuration.

Removing tasks from Lineman's run/build process

If you need to remove a task that's built into Lineman, you can use the removeTasks configuration. For example, if you wanted to disable Lineman's CoffeeScript task, you could do this:

  removeTasks: {
    common: ["coffee"]
  }

complete example

To use grunt-codo (Codo is a javascript documentation tool) in a lineman project.

# From the top dir of your project.
$ npm install grunt-codo --save-dev
# config/application.coffee
module.exports = (lineman)->
  loadNpmTasks: ['grunt-codo']
  codo:
    options:
      name: "Awesome Lib"
      title: "Awesome Lib Documentation"
      undocumented: yes
    src: ["app/js"]
  appendTasks:
    common: ["codo"]

Modifying Lineman's run/build process directly

If you need more fine-grained control, you can use custom JavaScript in your application config file to edit the appropriate array directly; here's an example of removing a task from the Ember.js template. Note: This example is out of date and is more easily accomplished with removeTasks as described above. The Ember.js template has been appropriately updated as well.

# grab lineman's config object
config = require(process.env['LINEMAN_MAIN']).config

# remove the 'handlebars' task
config.application.appTasks.common = _(config.application.appTasks.common).reject (n) -> n == "handlebars"

# extend as usual
module.exports = config.extend 'application',
  server:
  ...