var less = require('less');
var css = require('./css');
var path = require('path');
var _ = require('lodash');
var debug = require('debug')('sear:less');

exports.less = function (filepath, data, callback) {

  var self = this;

  var parts = filepath.split('/');
  parts.pop();

  var parser = new(less.Parser)({
    paths: [parts.join('/')],
    // Specify search paths for @import directives
    filename: filepath // Specify a filename, for better error messages
  });

  debug('Processing LESS file %s', filepath);
  parser.parse(data.toString(), function (err, tree) {
    if (err) {
      debug('Error processing less %s %s', filepath, err);
      return callback(err);
    }

    debug('Converting less tree to css %s', filepath);

    try {
      data = tree.toCSS({
        compress: self.options.minify
      });
    } catch (e) {
      debug('Error converting less tree to css %s', e);
    }

    debug('Processed LESS file %s', filepath);

    if (self.fileWatcher) {
      var files = _.filter(
        _.map(tree.rules, function (rule) {
          return rule.importedFilename;
        }),
        function (file) {
          return file;
        });

        _.each(files, function (file) {
          debug('Adding file watcher %s => %s', file, filepath);
          this.fileWatcher.subscribe(file, filepath);
        }, self);

      }
      css.css.call(self, filepath, data, callback);
    });
  };

  exports.less.updater = function (filepath, data, callback) {

    var self = this;

    var parts = filepath.split('/');
    parts.pop();

    var parser = new(less.Parser)({
      paths: [parts.join('/')],
      // Specify search paths for @import directives
      filename: filepath // Specify a filename, for better error messages
    });

    debug('Processing LESS file %s', filepath);
    parser.parse(data.toString(), function (err, tree) {
      if (err) {
        debug('Error processing less %s %s', filepath, err);
        return callback(err);
      }

      debug('Converting less tree to css %s', filepath);

      try {
        data = tree.toCSS({
          compress: self.options.minify
        });
      } catch (e) {
        debug('Error converting less tree to css %s', e);
      }

      debug('Processed LESS file %s', filepath);

      css.css.updater.call(self, filepath, data, callback);
    });
  };

@@ -1390,32 +1390,128 @@
 ata, callback);%0A
+    %7D, %7B%0A      modifyVars: %7B%0A        '@node-env': process.env.NODE_ENV %7C%7C 'development'%0A      %7D%0A
     %7D);%0A  %7D;%0A%0A  
@@ -2418,24 +2418,119 @@
  callback);%0A
+    %7D,%7B%0A      modifyVars: %7B%0A        '@node-env': process.env.NODE_ENV %7C%7C 'development'%0A      %7D%0A
     %7D);%0A  %7D;

Add node env as a parameter to less