/**
 * Builds our libaries into a single file for easy upload to NetSuite
 */
'use strict';

// main version stamp - gets appended to the build filename
var version = require("./package.json").version;
var outdir = "dist";
var webpack = require('webpack')
var gulp = require('gulp');
var del = require("del");

// loads all gulp plugins listed as dependencies from package.json
var $ = require('gulp-load-plugins')();

/**
 * All the sources files we want minimize and combine
 */
var sources = ["References/jQueryAOP/src/aop.js",
    "node_modules/lodash/lodash.js",
    "node_modules/moment/moment.js",
    "node_modules/lazy.js/lazy.js",
    "workarounds.js",
    "EC_SharedLibrary_Common.js",
    "EC_SharedLibrary_ServerSide.js",
    "EC_Search.js",
    "EC_nsdal.js",
    "consoleAppender.js",
    "Aurelia-Logger-webpack-lib.js"
];

// uses webpack to pull together the aurelia logging stuff and depends into a single global "LogManager" identifier
gulp.task('logger', function() {
    var webpackConfig = {
        output: {
            library: "LogManager",
            filename:"Aurelia-Logger-webpack-lib.js"
        },
        entry: "./Logging.js"
    }

    webpack(webpackConfig, function(err,stats){
      if (err || stats.hasErrors()) {
          console.warn('errors doing the webpack')
      }
      else console.log('webpacked '  + stats.compilation.outputOptions.filename)
    })
})
// build the project to a single file for easy deployment to NetSuite libraries tab, includes several other open source
// libs
gulp.task('default',['clean', 'logger'], function () {
    return gulp.src(sources)
        //.pipe($.uglify()) // scrunch them individually
        .pipe($.concat("EC_Libs-" + version + ".js")) // combine into a single file w/version stamp
        .pipe(gulp.dest(outdir))
        .pipe($.size()); // outputs a blurb about how many bytes the final result is
});

// uses plain node del module to delete previous build
gulp.task('clean', function(){
    del(outdir, function() {
        console.log("Deleted " + outdir);
    });
});
@@ -969,33 +969,36 @@
 ogger', function
-(
+ (cb
 ) %7B%0A    var webp
@@ -1085,16 +1085,17 @@
 ilename:
+ 
 %22Aurelia
@@ -1205,27 +1205,30 @@
 tion
+ 
 (err,
+ 
 stats)
+ 
 %7B%0A      
 if (
@@ -1223,16 +1223,18 @@
 %7B%0A      
+ 
+ 
 if (err 
@@ -1253,24 +1253,26 @@
 Errors()) %7B%0A
+  
           co
@@ -1316,18 +1316,22 @@
 )%0A      
+ 
+ 
 %7D%0A
+  
       el
@@ -1357,17 +1357,16 @@
 packed '
- 
  + stats
@@ -1402,16 +1402,32 @@
 lename)%0A
+        cb(err)%0A
     %7D)%0A%7D
@@ -1576,16 +1576,17 @@
 efault',
+ 
 %5B'clean'
@@ -1641,20 +1641,16 @@
 ources)%0A
-    
     //.p
@@ -1999,18 +1999,20 @@
 function
+ 
 ()
+ 
 %7B%0A    de
@@ -2029,16 +2029,17 @@
 function
+ 
 () %7B%0A   

make sure webpack is done before the next task is executed re: #5