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

import yargs from 'yargs';
const argv = yargs.argv;
import gulp from 'gulp';
import path from 'path';
import fs from 'fs';
import grommetToolbox, {getOptions} from 'grommet-toolbox';
import git from 'gulp-git';
import del from 'del';
import mkdirp from 'mkdirp';
import gulpWebpack from 'webpack-stream';

const options = getOptions();

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

gulp.task('generate-static-site', ['generate-icons-map'], () => {
  var staticSiteConfig = require('./site-generator.webpack.config');
  options.copyAssets = options.copyAssets.splice(1);
  return gulp.src(options.mainJs)
      .pipe(gulpWebpack(staticSiteConfig))
      .pipe(gulp.dest(options.dist));
});

gulp.task('generate-icons-map', (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', '') + "\":\n" +
          "    require('" + grommetIconPath + componentName + "')"
        );

        if (index === icons.length - 1) {
          iconsMap.push('};\n');

          var destinationFile = path.join(__dirname,
            'src/docs/components/iconsMap.js');
          fs.writeFile(destinationFile, iconsMap.join("\n"), function(err) {
            if (err) {
              throw err;
            }

            done();
          });
        } else {
          iconsMap.push(',');
        }
      }
    });
  });
});

gulp.task('release:createTmp', (done) => {
  del.sync(['./tmp']);
  mkdirp('./tmp', function(err) {
    if (err) {
      throw err;
    }
    done();
  });
});

gulp.task('release:gh-pages', ['dist', 'release:createTmp'], (done) => {
  if (process.env.CI) {
    git.clone('https://' + process.env.GH_TOKEN +
      '@github.com/grommet/grommet.github.io.git',
      {
        cwd: './tmp/'
      },
      function(err) {<commit_msg>quick fix to allow Node 8 users to use grommet-docs<commit_after>// (C) Copyright 2014-2016 Hewlett Packard Enterprise Development LP

import yargs from 'yargs';
const argv = yargs.argv;
import gulp from 'gulp';
import path from 'path';
import fs from 'fs';
import grommetToolbox, {getOptions} from 'grommet-toolbox';
import del from 'del';
import mkdirp from 'mkdirp';
import gulpWebpack from 'webpack-stream';

const options = getOptions();

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

gulp.task('generate-static-site', ['generate-icons-map'], () => {
  var staticSiteConfig = require('./site-generator.webpack.config');
  options.copyAssets = options.copyAssets.splice(1);
  return gulp.src(options.mainJs)
      .pipe(gulpWebpack(staticSiteConfig))
      .pipe(gulp.dest(options.dist));
});

gulp.task('generate-icons-map', (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', '') + "\":\n" +
          "    require('" + grommetIconPath + componentName + "')"
        );

        if (index === icons.length - 1) {
          iconsMap.push('};\n');

          var destinationFile = path.join(__dirname,
            'src/docs/components/iconsMap.js');
          fs.writeFile(destinationFile, iconsMap.join("\n"), function(err) {
            if (err) {
              throw err;
            }

            done();
          });
        } else {
          iconsMap.push(',');
        }
      }
    });
  });
});

gulp.task('release:createTmp', (done) => {
  del.sync(['./tmp']);
  mkdirp('./tmp', function(err) {
    if (err) {
      throw err;
    }
    done();
  });
});

gulp.task('release:gh-pages', ['dist', 'release:createTmp'], (done) => {
  if (process.env.CI) {
    const git = require('gulp-git');
    git.clone('https://' + process.env.GH_TOKEN +
      '@github.com/grommet/grommet.github.io.git',
      {
        cwd: './tmp/'
      },
      function(err) {
{'fraction_non_alphanumeric': 0.18478474542952625, 'fraction_numerical': 0.00491448791035974, 'mean_word_length': 2.6420901932712955, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '7174565', 'n_tokens_mistral': 1707, 'n_tokens_neox': 1661, 'n_words': 316}