Created
July 15, 2014 01:58
-
-
Save mohayonao/d8083b7b8f541bf05c9e to your computer and use it in GitHub Desktop.
run grunt tasks only on changed
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
module.exports = (grunt)-> | |
'use strict' | |
_ = require 'underscore' | |
toTaskArgs = (args)-> | |
switch | |
when _.isUndefined args then '' | |
when _.isArguments args then _.map(args, toTaskArgs).join ':' | |
else args | |
grunt.initConfig | |
pkg: grunt.file.readJSON 'package.json' | |
grunt.registerTask( | |
'default' | |
'Run predefined tasks whenever watched files change' | |
[ '-watch' ] | |
) | |
grunt.registerTask( | |
'coffee' | |
'Compile CoffeeScript files into JavaScript' | |
-> grunt.task.run "-coffee:#{toTaskArgs(arguments)}" | |
) | |
if _.some([ '-h', '--help' ], (opt)->_.contains process.argv, opt) | |
return | |
loadNpmTasksIfNeeded = (name)-> | |
if not loadNpmTasksIfNeeded.hasOwnProperty name | |
loadNpmTasksIfNeeded[name] = true | |
grunt.loadNpmTasks name | |
filterFiles = (list, filter)-> | |
if filter | |
_.filter list, (file)-> file.indexOf(filter) isnt -1 | |
else list | |
grunt.registerTask '-watch', -> | |
loadNpmTasksIfNeeded 'grunt-este-watch' | |
grunt.config.data.esteWatch = | |
options: | |
dirs: 'src/**/' | |
coffee: (file)-> "-coffee:#{file}" | |
grunt.task.run 'esteWatch' | |
grunt.registerTask '-coffee', (filter)-> | |
src = grunt.file.expand 'src/*.coffee' | |
src = filterFiles src, filter | |
return if src.length is 0 | |
loadNpmTasksIfNeeded 'grunt-contrib-coffee' | |
grunt.config.data.coffee = | |
files: | |
expand: yes | |
cwd : 'src/' | |
src : _.map(src, (path)-> _.rest(path.split('/')).join '/') | |
dest: 'lib/' | |
ext : '.js' | |
grunt.task.run 'coffee' |
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
{ | |
"name": "run-grunt-tasks-only-on-changed", | |
"version": "2014.07.15", | |
"dependencies": { | |
"grunt": "^0.4.5", | |
"grunt-contrib-coffee": "^0.10.1", | |
"grunt-este-watch": "^0.1.16", | |
"underscore": "^1.6.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment