Skip to content

Instantly share code, notes, and snippets.

@kazu69
Created October 21, 2013 01:14
Show Gist options
  • Save kazu69/7077338 to your computer and use it in GitHub Desktop.
Save kazu69/7077338 to your computer and use it in GitHub Desktop.
grunt-contrib-watchで監視対象のファイルの中で変更されたファイルを取得するサンプル。 Sample to get the files that have been changed in the file to be monitored in the grunt-contrib-watch.
module.exports = (grunt) ->
changedFiles = Object.create null
# Project configuration.
grunt.initConfig
# Metadata.
pkg: grunt.file.readJSON 'package.json'
watch:
coffee:
files: ['javascripts/**/*.coffee']
tasks: ['coffeelint']
coffeelint:
gruntfile: ['Gruntfile.coffee']
lib_test: ['javascripts/**/*.coffee']
# bind watch event
grunt.event.on 'watch', (status, filepath, taskTargetName) ->
changedFiles[filepath] = status
changedCoffeeFile() if /\.(coffee)$/.test filepath
changedCoffeeFile = ->
paths = Object.keys changedFiles
for path in paths
# Log which file has changed.
grunt.log.ok "change file is #{path}"
# Reset changedFiles
changedFiles = Object.create null
# These plugins provide necessary tasks.
grunt.loadNpmTasks 'grunt-contrib-watch'
# Default task.
grunt.registerTask 'default', ['watch']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment