 
 class GeneratedFile
   constructor: (@path, @sourceFiles, @config) ->
-    null
-  
-  # Collects content from a list of files and wraps it with
-  # require.js module definition if needed.
-  getData: (files) ->
-    data = ''
-    data += requireDefinition if /\.js$/.test @path
-    data += files.map((file) -> file.data).join ''
-    data
-    
+    @type = if (@sourceFiles.some (file) -> file.type is 'javascript')
+      'javascript'
+    else
+      'stylesheet'
+
   _extractOrder: (files, config) ->
     types = files.map (file) -> pluralize file.type
     arrays = (value.order for own key, value of config.files when key in types)

          (string) -> regExpOrFunction.test string
    config

  getDestinationPathes: (file) ->
    pathes = []
    data = @config.files[pluralize file.type]
    for own destinationPath, tester of data.joinTo when tester file.path
      pathes.push destinationPath
    if pathes.length > 0 then pathes else null

  getFiles: (fileList) ->
    map = {}
    fileList.files.forEach (file) =>
      pathes = @getDestinationPathes file
      return unless pathes?
      pathes.forEach (path) =>
        map[path] ?= []
        map[path].push file
    for generatedFilePath, sourceFiles of map
      generatedFilePath = sysPath.join @config.buildPath, generatedFilePath
      new GeneratedFile generatedFilePath, sourceFiles, @config

  ###
  write: (fileList, filesConfig) ->
    write = (callback) -> file.write callback
    async.forEach (@getFiles fileList), write, (error, results) =>
      return helpers.logError "write error. #{error}" if error?
      @emit 'write', results
  ###

  write: (fileList) =>
    minifiers = @plugins
      .filter((plugin) -> plugin.minify)
      .map((plugin) -> plugin.minify)
    getFiles = (callback) => callback null, @getFiles fileList
    write = (file, callback) -> file.write callback

    async.waterfall [getFiles, minifiers...], (error, files) =>
      return helpers.logError "minify error. #{error}" if error?
      async.forEach files, write, (error, results) =>
        return helpers.logError "write error. #{error}" if error?
        @emit 'write', results

class exports.FileWriter extends EventEmitter
  constructor: (@config, @plugins) ->
    @destFiles = []
    @_initFilesConfig @config.files

  _initFilesConfig: (filesConfig) ->
    # Copy config.
    config = helpers.extend filesConfig, {}
    for own type, data of config
