<commit_before>// (C) Copyright 2014-2015 Hewlett Packard Enterprise Development LP

var argv = require('yargs').argv;
var gulp = require('gulp');
var path = require('path');
var fs = require('fs');
var sass = require('gulp-sass');
var rename = require('gulp-rename');
var minifyCss = require('gulp-cssnano');
var devGulpTasks = require('grommet/utils/gulp/gulp-tasks');
var webpack = require('webpack');
var gulpWebpack = require('webpack-stream');
var git = require('gulp-git');
var del = require('del');
var http = require('http');
var mkdirp = require('mkdirp');
var replace = require('gulp-replace');

var opts = {
  base: '.',
  publicPath: 'docs',
  dist: path.resolve(__dirname, 'dist/'),
  copyAssets: [
    'src/index.html',
    'src/robots.txt',
    {
      asset: 'src/develop/img/**',
      dist: 'dist/img/'
    },
    {
      asset: 'src/design/img/**',
      dist: 'dist/img/'
    },
    {
      asset: 'src/img/**',
      dist: 'dist/img/'
    },
    {
      asset: 'design/**',
      dist: 'dist/assets/design/'
    },
    {
      asset: 'node_modules/grommet/*.min.js',
      dist: 'dist/assets/latest/'
    },
    {
      asset: 'node_modules/grommet/*.min.css',
      dist: 'dist/assets/latest/css/'
    },
    {
      asset: 'node_modules/grommet/img/**',
      dist: 'dist/img/'
    },
    {
      asset: 'src/video/**',
      dist: 'dist/video/'
    }
  ],
  scssAssets: ['src/scss/**/*.scss'],
  jsAssets: ['src/**/*.js'],
  mainJs: 'src/index.js',
  mainScss: 'src/scss/index.scss',
  webpack: {
    resolve: {
      root: [
        path.resolve(__dirname, './node_modules')
      ]
    },
    module: {
      loaders: [
        {
          test: /develop(\/|\\).*\.htm$|design(\/|\\)[^\/]*\.htm$|design(\/|\\).*\/.*\.htm$/,
          loader: 'babel-loader!imports?React=react,Router=react-router,Link=>Router.Link!html-jsx-loader',
          exclude: /(node_modules|bower_components)/
        }
      ]
    }
  },
  devServerPort: 8002,
  devServerDisableHot: true,
  // devServerHost: "0.0.0.0",
  scsslint: true,
  alias: {
    'grommet/scss': path.resolve(__dirname, '../grommet/src/scss'),
    'grommet': path.resolve(__dirname, '../grommet/src/js')
  },
  devPreprocess: [
    'set-webpack-alias', 'dist-css', 'generate-icons-map', 'watch-css'
  ],
  distPreprocess: ['set-webpack-alias', 'dist-css', 'generate-icons-map',
    'generate-server-routes']
};

function distSass() {
  return sass({
    includePaths: [
      path.resolve(__dirname, '../grommet/src/'),
      path.resolve(__dirname, './node_modules'),
      path.resolve(__dirname, './node_modules/grommet/node_modules')
    ]
  });
}

var host = opts.devServerHost ? opts.devServerHost : 'localhost';

gulp.task('set-webpack-alias', function () {
  if (opts.alias && argv.useAlias) {
    console.log('Using local alias for development.');
    opts.webpack.resolve.alias = opts.alias;
  }
});

gulp.task('watch-css', function() {
  if (opts.webpack.resolve.alias) {
    var watcher = gulp.watch(
      path.resolve(__dirname, '../grommet/src/scss/**/*.scss'),
      ['dist-css']
    );

    watcher.on('change', function() {
      //notify the webpack dev server that a change happened
      http.get(
        'http://' + host + ':' + opts.devServerPort + '/invalid'
      );
    });
  }
});

gulp.task('dist-css', function() {
  var prefix = opts.webpack.resolve.alias ? 'grommet/' : '';

  gulp.src('src/scss/index-aruba.scss')
    .pipe(replace(prefix, ''))
    .pipe(distSass())
    .pipe(rename('aruba.min.css'))
    .pipe(minifyCss())
    .pipe(gulp.dest('dist/'));

  gulp.src('src/scss/index-grommet.scss')
    .pipe(replace(prefix, ''))
    .pipe(distSass())
    .pipe(rename('grommet.min.css'))
    .pipe(minifyCss())
    .pipe(gulp.dest('dist/'));

  gulp.src('src/scss/index-hpe.scss')
    .pipe(replace(prefix, ''))
    .pipe(distSass())
    .pipe(rename('hpe.min.css'))
    .pipe(minifyCss())
    .pipe(gulp.dest('dist/'));

  gulp.src('src/scss/index-hpinc.scss')
    .pipe(replace(prefix, ''))
    .pipe(distSass())
    .pipe(rename('hpinc.min.css'))
    .pipe(minifyCss())
    .pipe(gulp.dest('dist/'));

  return gulp.src('src/scss/index-vanilla.scss')
    .pipe(replace(prefix, ''))
    .pipe(distSass())
    .pipe(rename('vanilla.min.css'))
    .pipe(minifyCss())
    .pipe(gulp.dest('dist/')).on('end', function () {
      if (opts.webpack.resolve.alias) {
        //notify the webpack dev server to reload when compilation is finished
        http.get(
          'http://' + host + ':' + opts.devServerPort + '/reload'
        );
      }
    });
});

var nodeModules = {};
fs.readdirSync('node_modules')
  .filter(function(x) {
    return ['.bin'].indexOf(x) === -1;
  })
  .forEach(function(mod) {
    nodeModules[mod] = 'commonjs ' + mod;
  });

gulp.task('generate-icons-map', function (done) {
  var iconsFolder = path.join(__dirname, './node_modules/grommet/img/icons');
  var iconsMap = ['module.exports = {'];
  fs.readdir(iconsFolder, function(err, icons) {
    icons.forEach(function (icon, index) {

      if (/\.svg$/.test(icon)) {
        var componentName = icon.replace('.svg', '.js');
        componentName = componentName.replace(/^(.)|-([a-z])/g, function (g) {
          return g.length > 1 ? g[1].toUpperCase() : g.toUpperCase();
        });

        var grommetIconPath = "grommet/components/icons/base/";
        iconsMap.push(
          "\"" + icon.replace('.svg', '') + "\":" +
          " require('" + grommetIconPath + componentName + "')"
        );
<commit_msg>Fixed gulp config for webpack<commit_after>// (C) Copyright 2014-2015 Hewlett Packard Enterprise Development LP

var argv = require('yargs').argv;
var gulp = require('gulp');
var path = require('path');
var fs = require('fs');
var sass = require('gulp-sass');
var rename = require('gulp-rename');
var minifyCss = require('gulp-cssnano');
var devGulpTasks = require('grommet/utils/gulp/gulp-tasks');
var webpack = require('webpack');
var gulpWebpack = require('webpack-stream');
var git = require('gulp-git');
var del = require('del');
var http = require('http');
var mkdirp = require('mkdirp');
var replace = require('gulp-replace');
var runSequence = require('run-sequence');

var opts = {
  base: '.',
  publicPath: 'docs',
  dist: path.resolve(__dirname, 'dist/'),
  copyAssets: [
    'src/index.html',
    'src/robots.txt',
    {
      asset: 'src/develop/img/**',
      dist: 'dist/img/'
    },
    {
      asset: 'src/design/img/**',
      dist: 'dist/img/'
    },
    {
      asset: 'src/img/**',
      dist: 'dist/img/'
    },
    {
      asset: 'design/**',
      dist: 'dist/assets/design/'
    },
    {
      asset: 'node_modules/grommet/*.min.js',
      dist: 'dist/assets/latest/'
    },
    {
      asset: 'node_modules/grommet/*.min.css',
      dist: 'dist/assets/latest/css/'
    },
    {
      asset: 'node_modules/grommet/img/**',
      dist: 'dist/img/'
    },
    {
      asset: 'src/video/**',
      dist: 'dist/video/'
    }
  ],
  scssAssets: ['src/scss/**/*.scss'],
  jsAssets: ['src/**/*.js'],
  mainJs: 'src/index.js',
  mainScss: 'src/scss/index.scss',
  webpack: {
    resolve: {
      root: [
        path.resolve(__dirname, './node_modules')
      ]
    }
  },
  devServerPort: 8002,
  // devServerHost: "0.0.0.0",
  scsslint: true,
  alias: {
    'grommet/scss': path.resolve(__dirname, '../grommet/src/scss'),
    'grommet': path.resolve(__dirname, '../grommet/src/js')
  },
  devPreprocess: [
    'set-webpack-alias', 'dist-css', 'generate-icons-map', 'watch-css'
  ],
  distPreprocess: ['set-webpack-alias', 'dist-css', 'generate-icons-map',
    'generate-server-routes']
};

function distSass() {
  return sass({
    includePaths: [
      path.resolve(__dirname, '../grommet/src/'),
      path.resolve(__dirname, './node_modules'),
      path.resolve(__dirname, './node_modules/grommet/node_modules')
    ]
  });
}

var host = opts.devServerHost ? opts.devServerHost : 'localhost';

gulp.task('set-webpack-alias', function () {
  if (opts.alias && argv.useAlias) {
    console.log('Using local alias for development.');
    opts.webpack.resolve.alias = opts.alias;
  }
});

gulp.task('watch-css', function() {
  if (opts.webpack.resolve.alias) {
    var watcher = gulp.watch(
      path.resolve(__dirname, '../grommet/src/scss/**/*.scss'),
      ['dist-css']
    );

    watcher.on('change', function() {
      //notify the webpack dev server that a change happened
      http.get(
        'http://' + host + ':' + opts.devServerPort + '/invalid'
      );
    });
  }
});

function distCss (name) {
  var prefix = opts.webpack.resolve.alias ? 'grommet/' : '';
  return gulp.src('src/scss/index-' + name + '.scss')
    .pipe(replace(prefix, ''))
    .pipe(distSass())
    .pipe(rename(name + '.min.css'))
    .pipe(minifyCss())
    .pipe(gulp.dest('dist/'));
}

gulp.task('dist-css-aruba', function () {
  return distCss('aruba');
});

gulp.task('dist-css-grommet', function () {
  return distCss('grommet');
});

gulp.task('dist-css-hpe', function () {
  return distCss('hpe');
});

gulp.task('dist-css-hpinc', function () {
  return distCss('hpinc');
});

gulp.task('dist-css-vanilla', function () {
  return distCss('vanilla');
});

gulp.task('notify', function () {
  if (opts.webpack.resolve.alias) {
    //notify the webpack dev server to reload when compilation is finished
    http.get(
      'http://' + host + ':' + opts.devServerPort + '/reload'
    );
  }
});

gulp.task('dist-css', function(done) {
  runSequence(
    ['dist-css-aruba', 'dist-css-grommet', 'dist-css-hpe',
    'dist-css-hpinc', 'dist-css-vanilla'], 'notify', done);
});

var nodeModules = {};
fs.readdirSync('node_modules')
  .filter(function(x) {
    return ['.bin'].indexOf(x) === -1;
  })
  .forEach(function(mod) {
    nodeModules[mod] = 'commonjs ' + mod;
  });

gulp.task('generate-icons-map', function (done) {
  var iconsFolder = path.join(__dirname, './node_modules/grommet/img/icons');
  var iconsMap = ['module.exports = {'];
  fs.readdir(iconsFolder, function(err, icons) {
    icons.forEach(function (icon, index) {

      if (/\.svg$/.test(icon)) {
        var componentName = icon.replace('.svg', '.js');
        componentName = componentName.replace(/^(.)|-([a-z])/g, function (g) {
          return g.length > 1 ? g[1].toUpperCase() : g.toUpperCase();
        });

        var grommetIconPath = "grommet/components/icons/base/";
        iconsMap.push(
          "\"" + icon.replace('.svg', '') + "\":" +
          " require('" + grommetIconPath + componentName + "')"
        );

{'fraction_non_alphanumeric': 0.20838881491344874, 'fraction_numerical': 0.0036142286475175957, 'mean_word_length': 2.8236363636363637, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '558496', 'n_tokens_mistral': 3803, 'n_tokens_neox': 3762, 'n_words': 614}