var bundles = require('../files/browserify_files');

module.exports = {
  task: function () {
    var cfg = {};
    for (var name in bundles) {
      var bundle = bundles[name];
      var options = {
        transform: [
          ['stringify', {
            appliesTo: {includeExtensions: ['.mustache']}
          }]
        ],

        // enables watchify when grunt is run with a watch task
        // must be evaluated lazily (using template var) to allow override by setConfig task.
        // watch: '<%= env.browserify_watch %>',
        watch: true,

        browserifyOptions: {
          debug: true,
          cache: {}
        }
      };

      if (bundle.options) {
        if (bundle.options.transform) {
          options.transform = options.transform.concat(bundle.options.transform);
        }
        if (bundle.options.external) {
          options.external = bundle.options.external;
        }
        if (bundle.options.require) {
          options.require = bundle.options.require;
        }
        if (bundle.options.plugin) {
          options.plugin = bundle.options.plugin;
        }
        if (bundle.options.cache) {
          options.cache = bundle.options.cache;
        }
      }

      cfg[name] = {
        src: bundle.src,
        dest: bundle.dest || ('<%= assets_dir %>/javascripts/' + name + '.js'),
        options: options
      };
    }

    return cfg;
  }
};

@@ -488,19 +488,16 @@
 %0A       
- //
  watch: 
@@ -530,29 +530,8 @@
 %25%3E',
-%0A        watch: true,
 %0A%0A  

revert browserify·