 'use strict'
 
 each = require 'async-each'
+waterfall = require 'async-waterfall'
 chokidar = require 'chokidar'
 debug = require('debug')('brunch:watch')
 sysPath = require 'path'

# startTime  - Number. Timestamp of a moment when compilation started.
#
# Returns Function.
getCompileFn = (config, joinConfig, fileList, optimizers, watcher, callback) -> (startTime, watcherReady) ->
  assetErrors = fileList.getAssetErrors()
  if assetErrors?
    assetErrors.forEach (error) -> logger.error error


      # Does the user's config say this plugin should definitely be used?
      return true if plugin.brunchPluginName in alwaysEnabled

      # If the plugin is an optimizer that doesn't specify a defaultEnv
      # decide based on the config.optimize setting
      return config.optimize if plugin.optimize and not plugin.defaultEnv

      # Use plugin-specified defaultEnv or assume it's meant for any env
      env = plugin.defaultEnv ?= '*'

      # Finally, is it meant for either any environment or an active environment?
      env is '*' or env in config.env

