Created
October 21, 2013 01:14
-
-
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.
This file contains hidden or 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) -> | |
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