/**
 * Created by nuintun on 2015/5/5.
 */

'use strict';

var gulp = require('gulp');
var util = require('../lib/util');
var colors = util.colors;
var transport = require('../index');

var alias = { 'base': 'base/base/1.2.0/base' };
var options = {
  alias: alias,
  include: function (id){
    return id.indexOf('view') === 0 ? 'all' : 'relative';
  }
};

gulp.task('default', function (){
  gulp.src('assets/js/**/*.!(css|json|tpl|html)', { base: 'assets/js' })
    .pipe(transport(options))
    .pipe(gulp.dest('dist/js'))
    .on('end', function (){
      console.log(colors.verboseBold('  gulp-cmd ') + colors.infoBold('build complete ...'));
    });
});

gulp.task('watch', function (){
  gulp.src('assets/js/**/*.*', { base: 'assets/js' })
    .pipe(transport({ alias: alias, include: 'self' }))
    .pipe(gulp.dest('dist/js'))
    .on('end', function (){
      console.log(colors.verboseBold('  gulp-cmd ') + colors.infoBold('build complete ...'));
    });

  var timer = null;

  gulp.watch('assets/js/**/*.*', function (e){
    if (e.type !== 'deleted') {
      clearTimeout(timer);

      timer = setTimeout(function (){
        gulp.src(e.path, { base: 'assets/js' })
          .pipe(transport({ alias: alias, include: 'self', cache: false }))
          .pipe(gulp.dest('dist/js'))
          .on('end', function (){
            console.log(colors.verboseBold('  gulp-cmd ') + colors.infoBold('build complete ...'));
          });
      }, 200);
    }
  });
});

@@ -351,16 +351,209 @@
   %7D%0A%7D;%0A%0A
+function complete()%7B%0A  var now = new Date();%0A%0A  console.log(%0A    '  %25s %5B%25s%5D %25s',%0A    colors.verboseBold('gulp-cmd'),%0A    now.toLocaleString(),%0A    colors.infoBold('build complete ...')%0A  );%0A%7D%0A%0A
 gulp.tas
@@ -732,120 +732,16 @@
 d', 
-function ()%7B%0A      console.log(colors.verboseBold('  gulp-cmd ') + colors.infoBold('build complete ...'));%0A    %7D
+complete
 );%0A%7D
@@ -937,120 +937,16 @@
 d', 
-function ()%7B%0A      console.log(colors.verboseBold('  gulp-cmd ') + colors.infoBold('build complete ...'));%0A    %7D
+complete
 );%0A%0A
@@ -1298,132 +1298,16 @@
 d', 
-function ()%7B%0A            console.log(colors.verboseBold('  gulp-cmd ') + colors.infoBold('build complete ...'));%0A          %7D
+complete
 );%0A 

add source file