// hoo release dev 开发环境测试
var settings = require('../settings');
var path = require('path');
var _ = require('../../lib/util');
module.exports = function (hoo, root, deployMsg) {
  hoo.media('submit')
    .match('**', {
      deploy: function (options, modified, total, next) {
        next();
      }
    });

  hoo.on('release:end', function (ret) {

    var files = [];
    var depsContainer = {};
    for (var key in ret.src) {
      _.insertDir(files, ret.src[key].subdirname.substring(1));
      if (ret.src[key].ext === '.scss') {
        var deps = ret.src[key].cache.deps;
        for (var dep_key in deps) {
          depsContainer[path.relative(path.join(process.cwd(), settings.sourceDir, root), dep_key)] = deps[dep_key];
        }
      }
    }

    for(var key in depsContainer){
      _.insertDir(files, key.replace(/\\/g,'\/'));
    }

    var dirArray = _.pull(_.uniq(files), '.');

    files = dirArray.map(function (file) {
        return {
          path: path.join(settings.sourceDir, root, file), dir: true
        }
      }
    ).concat(Object.keys(ret.src).map(function (file) {
        return {
          path: path.join(settings.sourceDir, root, file), dir: false
        }
      }
    ));

    require('../../lib/submit')(root, settings.sourceDir, files, deployMsg)
  });
};
