'use strict';

var _            = require('underscore');
var elixir       = require('laravel-elixir');
var gulp         = require('gulp');
var gutil        = require('gulp-util');
var plugins      = require('gulp-load-plugins')();
var config       = elixir.config;

elixir.extend('postcss', function(src, opts) {

  var css = config.css;
  var name = 'postcss';
  var notification = elixir.Notification ? elixir.Notification : require('laravel-elixir/Notification');

  opts = _.extend({}, opts);

  opts = _.extend({
    output: config.publicPath + '/' + config.css.folder,
    options: {},
    plugins: [],
    srcPath: config.assetsPath + '/' + name,
    sourcemaps: opts.sourcemaps ? opts.sourcemaps : config.sourcemaps,
    watch: [],
  }, opts);

  new elixir.Task(name, function() {

    var cssnano = css.cssnano ? css.cssnano.pluginOptions : undefined;
    var srcPath = opts.srcPath + '/' + src;

    var err = function(e) {
      // line break
      console.log('');
      console.log(gutil.colors.bgRed('PostCSS - Error'));
      console.log('   - ' + e.message);
    };

    if(typeof this.recordStep !== 'undefined') {
        this.recordStep('Post processing CSS');
        this.src = srcPath;
        this.output = opts.output;
    }

    return gulp.src(srcPath)
      .pipe(plugins.if(opts.sourcemaps, plugins.sourcemaps.init()))
      .pipe(plugins.postcss(opts.plugins, opts.options).on('error', err))
      .pipe(plugins.if(config.production, plugins.cssnano(cssnano)))
      .pipe(plugins.if(opts.sourcemaps, plugins.sourcemaps.write('.')))
      .pipe(gulp.dest(opts.output))
      .pipe(new notification().message(name + ' Compiled!'));
  })
  .watch(_.union([opts.srcPath + '/**/*.css'], opts.watch));

});

@@ -177,23 +177,17 @@
 ');%0Avar 
-plugins
+$
       = 
@@ -1271,39 +1271,33 @@
 th)%0A      .pipe(
-plugins
+$
 .if(opts.sourcem
@@ -1293,39 +1293,33 @@
 pts.sourcemaps, 
-plugins
+$
 .sourcemaps.init
@@ -1335,23 +1335,17 @@
   .pipe(
-plugins
+$
 .postcss
@@ -1399,31 +1399,25 @@
       .pipe(
-plugins
+$
 .if(config.p
@@ -1427,23 +1427,17 @@
 uction, 
-plugins
+$
 .cssnano
@@ -1460,23 +1460,17 @@
   .pipe(
-plugins
+$
 .if(opts
@@ -1482,23 +1482,17 @@
 cemaps, 
-plugins
+$
 .sourcem

Rename plugins to $