This gist demonstrates a basic Gruntfile for writing tools in CoffeeScript.
Created
July 3, 2014 16:27
-
-
Save ddaws/300fd1b0c1b3026611dc to your computer and use it in GitHub Desktop.
CoffeeScript Grunt Tools
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### | |
Dawson Reid ([email protected]) | |
### | |
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