Skip to content

Instantly share code, notes, and snippets.

@ddaws
Created July 3, 2014 16:27
Show Gist options
  • Save ddaws/300fd1b0c1b3026611dc to your computer and use it in GitHub Desktop.
Save ddaws/300fd1b0c1b3026611dc to your computer and use it in GitHub Desktop.
CoffeeScript Grunt Tools

This gist demonstrates a basic Gruntfile for writing tools in CoffeeScript.

###
Dawson Reid (dawson@streamlyne.co)
###
exec = require('child_process').exec
util = require 'util'
path = require 'path'
module.exports = (grunt) ->
grunt.loadNpmTasks 'grunt-contrib-coffee'
grunt.loadNpmTasks 'grunt-contrib-watch'
grunt.loadNpmTasks 'grunt-coffeelint'
grunt.loadNpmTasks 'grunt-exec'
grunt.initConfig
watch:
coffee:
files: ['Gruntfile.coffee', 'tools/*.coffee']
tasks: ['coffeelint:tools']
coffeelint:
tools: ['tools/*.coffee']
coffee:
compile:
expand: true,
flatten: true,
cwd: "#{__dirname}/tools/",
src: ['*.coffee'],
dest: '.tmp/',
ext: '.js'
exec:
target:
cmd: (target) ->
script = path.join(__dirname, '.tmp/', target + '.js')
execCmd = util.format 'node %s', script
return execCmd
grunt.registerTask 'dev', ['watch']
grunt.registerTask 'run', 'Run a coffeescript tool.', (n) ->
target = grunt.option('target');
if not target
console.err 'Run target is required.'
process.exit(1)
else
console.log 'Run target :', target
executeTask = util.format 'exec:target:%s', target
grunt.task.run ['coffee:compile', executeTask]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment