<commit_before>'use strict';

var gulp = require('gulp');
var gulpif = require('gulp-if');
var argv = require('yargs').argv;
var browserSync = require('browser-sync').create();
var conf = require('../gulp_conf/conf');
var fs = require('fs');
var modifyCssUrls = require('gulp-modify-css-urls');
var path = require('path');
var reload = browserSync.reload;
var runSequence = require('run-sequence');
var series = require('stream-series');
var utils = require('./utils');

var $ = require('gulp-load-plugins')({
    pattern: ['gulp-*', 'gulp.*', 'del', 'path']
});

var prod = argv.prod;
var serve = argv.serve;

var stylesTasks = [],
stylesDir = [],
scriptsTasks = [],
scriptsDir = [],
buildTasks = [],
compiled = {};

function addTaskDir(arrayVar, arrayTask, arrayDir){
    if (arrayVar.hasOwnProperty(name)) {
        arrayTask.push(name);
        arrayDir.push(arrayVar[name]);
        compiled[path.extname(arrayVar[name][0]).substring(1)] = name;
    }
}

for (var name in conf.assets.styles) {
    addTaskDir(conf.assets.styles, stylesTasks, stylesDir);
}

for (name in conf.assets.scripts) {
    addTaskDir(conf.assets.scripts, scriptsTasks, scriptsDir);
}

gulp.task('styles', stylesTasks);
gulp.task('scripts', scriptsTasks);

gulp.task('fonts', function () {
    return gulp.src(conf.assets.fonts)
        .pipe(gulp.dest('./web/sources'))
        .pipe($.rename(function (path) {
            path.dirname = utils.getShortPath(path.dirname, 'fonts')
        }))
        .pipe(gulp.dest('./web/fonts'));
});

gulp.task('components', function() {
    try {
      var wd = utils.wiredepPath();
      var wdPaths = [];
      for(var i in wd){
          var steps = wd[i].split(path.sep);
          wdPaths.push(conf.assets.components+'/**/'+steps[steps.length-2]+'/'+steps[steps.length-1]);
      }
      wdPaths.push(conf.assets.components+'/**/*.{png,jpg,jpeg,gif,svg,eot,woff,woff2,ttf,otf}');
      return gulp.src(wdPaths)
          .pipe(gulp.dest('./web/components'));
    } catch(e){
      // Cannot find where you keep your Bower packages
    }
})

var injectOptions = {
    ignorePath: '/web/',
    addRootSlash: false,
    transform: function (filePath, file, i, length) {
        if (path.extname(filePath) === '.js') {
            console.log('Inject script  '+ filePath);
            return conf.inject.scripts.replace('[filePath]',filePath);
        }
        else if(path.extname(filePath) === '.css'){
            console.log('Inject stylesheet  '+ filePath);
            return conf.inject.styles.replace('[filePath]',filePath);
        }
        return null;
    }
};

var injectOptions2 = Object.assign({}, injectOptions);
injectOptions2['starttag'] = '<!-- inject:head:{{ext}} -->';

function transformCssUrls(url, filePath){
    var patterns = ['/', 'data:', 'http:', 'https:'];
    for(var i in patterns){
        if(url.indexOf(patterns[i]) === 0){
            return url.slice(url.indexOf(patterns[i]));
        }
    }
    var split = path.resolve(filePath,'../'+url).split(path.join(path.resolve(),utils.formatPath('/web')));
    var folder = split[1].indexOf('img') === 0 ? 'fonts' : 'img';
    return utils.formatPath(utils.findShortPath(split[1], folder));
}

var fileCssStream = function(paths, filename){
    return gulp.src(paths)
        .pipe(modifyCssUrls({
            modify: function (url, filePath) {
                return transformCssUrls(url, filePath);
            }
        }))
        .pipe(gulpif(prod, $.concat(filename+'.css')))
        .pipe(gulpif(prod, $.cssmin()))
        .pipe(gulpif(prod, $.rev()))
        .pipe(gulpif(prod, gulp.dest('./web/css')));
}

var fileJsStream = function(paths, filename){<commit_msg>Update main.js<commit_after>'use strict';

var gulp = require('gulp');
var gulpif = require('gulp-if');
var argv = require('yargs').argv;
var browserSync = require('browser-sync').create();
var conf = require('../gulp_conf/conf');
var fs = require('fs');
var modifyCssUrls = require('gulp-modify-css-urls');
var path = require('path');
var reload = browserSync.reload;
var runSequence = require('run-sequence');
var series = require('stream-series');
var utils = require('./utils');

var $ = require('gulp-load-plugins')({
    pattern: ['gulp-*', 'gulp.*', 'del', 'path']
});

var prod = argv.prod;
var serve = argv.serve;

var stylesTasks = [],
stylesDir = [],
scriptsTasks = [],
scriptsDir = [],
buildTasks = [],
compiled = {};

function addTaskDir(arrayVar, arrayTask, arrayDir){
    if (arrayVar.hasOwnProperty(name)) {
        arrayTask.push(name);
        arrayDir.push(arrayVar[name]);
        compiled[path.extname(arrayVar[name][0]).substring(1)] = name;
    }
}

for (var name in conf.assets.styles) {
    addTaskDir(conf.assets.styles, stylesTasks, stylesDir);
}

for (name in conf.assets.scripts) {
    addTaskDir(conf.assets.scripts, scriptsTasks, scriptsDir);
}

gulp.task('styles', stylesTasks);
gulp.task('scripts', scriptsTasks);

gulp.task('fonts', function () {
    return gulp.src(conf.assets.fonts)
        .pipe(gulp.dest('./web/sources'))
        .pipe($.rename(function (path) {
            path.dirname = utils.getShortPath(path.dirname, 'fonts')
        }))
        .pipe(gulp.dest('./web/fonts'));
});

gulp.task('components', function() {
    try {
      var wd = utils.wiredepPath();
      var wdPaths = [];
      for(var i in wd){
          var steps = wd[i].split(path.sep);
          wdPaths.push(conf.assets.components+'/**/'+steps[steps.length-2]+'/'+steps[steps.length-1]);
      }
      wdPaths.push(conf.assets.components+'/**/*.{png,jpg,jpeg,gif,svg,eot,woff,woff2,ttf,otf}');
      return gulp.src(wdPaths)
          .pipe(gulp.dest('./web/components'));
    } catch(e){
      // Cannot find where you keep your Bower packages
    }
})

var injectOptions = {
    ignorePath: '/web/',
    addRootSlash: false,
    transform: function (filePath, file, i, length) {
        if (path.extname(filePath) === '.js') {
            console.log('Inject script  '+ filePath);
            return conf.inject.scripts.replace('[filePath]',filePath);
        }
        else if(path.extname(filePath) === '.css'){
            console.log('Inject stylesheet  '+ filePath);
            return conf.inject.styles.replace('[filePath]',filePath);
        }
        return null;
    }
};

var injectOptions2 = Object.assign({}, injectOptions);
injectOptions2['starttag'] = '<!-- inject:head:{{ext}} -->';

function transformCssUrls(url, filePath){
    var patterns = ['/', 'data:', 'http:', 'https:'];
    for(var i in patterns){
        if(url.indexOf(patterns[i]) === 0){
            return url.slice(url.indexOf(patterns[i]));
        }
    }
    var split = path.resolve(filePath,'../'+url).split(path.join(path.resolve(),utils.formatPath('/web')));
    var folder = split[1].indexOf('img') === -1 ? 'fonts' : 'img';
    return utils.formatPath(utils.findShortPath(split[1], folder));
}

var fileCssStream = function(paths, filename){
    return gulp.src(paths)
        .pipe(modifyCssUrls({
            modify: function (url, filePath) {
                return transformCssUrls(url, filePath);
            }
        }))
        .pipe(gulpif(prod, $.concat(filename+'.css')))
        .pipe(gulpif(prod, $.cssmin()))
        .pipe(gulpif(prod, $.rev()))
        .pipe(gulpif(prod, gulp.dest('./web/css')));
}

var fileJsStream = function(paths, filename){
{'fraction_non_alphanumeric': 0.18889493739793142, 'fraction_numerical': 0.0029940119760479044, 'mean_word_length': 3.1803185437997725, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4386354', 'n_tokens_mistral': 2420, 'n_tokens_neox': 2408, 'n_words': 436}