﻿'use strict'

const filecount = require('./filecount')
const gulp = require('gulp')
const modernizr = require('gulp-modernizr')

const jsDestination = 'scripts/lib/'
const cssDestination = 'lib/'

module.exports = function () {
  gulp.task('lib-scripts', function () {
    return gulp.src([
      'node_modules/file-saver/dist/FileSaver.js',
      'node_modules/diff/dist/diff.js',
      'node_modules/jquery/dist/jquery.js'
    ])
      .pipe(filecount())
      .pipe(gulp.dest(jsDestination))
  })

  gulp.task('lib-styles', function () {
    return gulp.src('node_modules/normalize.css/normalize.css')
      .pipe(filecount())
      .pipe(gulp.dest(cssDestination))
  })

  gulp.task('lib-modernizr', function () {
    return gulp.src(['scripts/background/featuredetect.js'])
      .pipe(filecount())
      .pipe(modernizr())
      .pipe(gulp.dest(jsDestination))
  })

  gulp.task('lib-requirejs', function () {
    return gulp.src('node_modules/requirejs/require.js')
      .pipe(filecount())
      .pipe(gulp.dest('basic/scripts/'))
      .pipe(gulp.dest('boule/scripts/'))
      .pipe(gulp.dest('tac/scripts/'))
      .pipe(gulp.dest('test/scripts/'))
  })

  gulp.task('lib-semver', function () {
    return gulp.src(['node_modules/semver/semver.browser.js'])
      .pipe(filecount())
      .pipe(gulp.dest(jsDestination))
  })

  gulp.task('lib-tuvero', function () {
    return gulp.src('node_modules/tuvero/dist/tuvero.bundle-amd.js')
      .pipe(filecount())
      .pipe(gulp.dest(jsDestination))
  })

  gulp.task('lib-test-scripts', function () {
    return gulp.src('node_modules/qunit/qunit/qunit.js')
      .pipe(filecount())
      .pipe(gulp.dest('test/scripts/'))
  })

  gulp.task('lib-test-styles', function () {
    return gulp.src('node_modules/qunit/qunit/qunit.css')
      .pipe(filecount())
      .pipe(gulp.dest('test/style/'))
  })

  return Object.keys(gulp.tasks).filter(task => /^lib-.*$/.test(task))
}

@@ -240,32 +240,107 @@
 k('lib-scripts',
+ %5B'lib-filesaver', 'lib-diff', 'lib-jquery'%5D)%0A%0A  gulp.task('lib-filesaver',
  function () %7B%0A 
@@ -362,16 +362,8 @@
 src(
-%5B%0A      
 'nod
@@ -397,32 +397,153 @@
 ileSaver.js'
-,%0A      
+)%0A      .pipe(filecount())%0A      .pipe(gulp.dest(jsDestination))%0A  %7D)%0A%0A  gulp.task('lib-diff', function () %7B%0A    return gulp.src(
 'node_module
@@ -566,16 +566,139 @@
 .js'
-,
+)
 %0A      
+.pipe(filecount())%0A      .pipe(gulp.dest(jsDestination))%0A  %7D)%0A%0A  gulp.task('lib-jquery', function () %7B%0A    return gulp.src(
 'nod
@@ -733,14 +733,8 @@
 .js'
-%0A    %5D
 )%0A  

split lib-scripts into lib-filesaver, lib-diff and lib-jquery