<commit_before>'use strict';
import shell from 'shelljs';
import bs from 'browser-sync';
import config from '../config.js';
import configLoader from './../config-loader';
import Generator from 'confetti-generator';
import Loader from 'confetti-loader';
import watchAll from './../assets-watchers';
import * as logger from './../logger';
import path from 'path';
import del from 'del';
const loader = new Loader();
/*
 Function to load data and to build the slide deck.
 */
const build = (bs, dev, folder, serveDist, cb) => {
  logger.message('Loading speaker deck data...');
  loader.loadDeck(configLoader, serveDist)
    .then(deckData => {
      const generator = new Generator(deckData.paths, serveDist);
      logger.success('Speaker deck data loaded.');
      logger.message('Generating speaker deck...');
      generator.generate(deckData)
        .then(() => {
          cb(generator, deckData, bs, folder, serveDist, dev);
        })
        .catch(error => {
          logger.error(error);
          shell.exit(1);
        });
    })
    .catch(error => {
      logger.error(error);
      shell.exit(1);
    });
};
/*
 Function called after the slide deck is built.
 */
const callback = (generator, deckData, bs, folder, serveDist, dev) => {
  // Don't call init method if the bs is active yet.
  if (!bs.active) {
    bs.create();
    bs.init({server: folder, open: false});
    /*
     Watch changes on:
     - slide deck settings
     - data slides
     - selected theme config
     */
    bs.watch([
      configLoader.paths.settings,
      configLoader.paths.slides,
      path.join(configLoader.paths.themes, deckData.theme, 'data.yml')
    ]).on('change', () => {
      // If anything is changed rebuild the deck
      build(bs, dev, folder, serveDist, callback);
    });
    bs.watch(configLoader.paths.covers).on('change',
      () => generator.copyCovers().catch(error => logger.error(error)));
    bs.watch(folder).on('change', bs.reload);
    /*
     Watch the theme assets only if the dev mode is switched on.
     */
    if (dev) {
      logger.info('Theme development environment enabled.');
      watchAll(bs, generator, deckData);
    }
  }
};
//--------------
// Serve Command
//--------------
exports.command = 'server';
exports.builder = {
  dev: {
    describe: `Enables watching and reload the browser when theme assets changes.`,
    requiresArg: false
  },
  dist: {
    describe: `Serve the dist folder (${config.DIST_FOLDER}).`,
    requiresArg: false
  }
};
exports.desc = `Serve the compiled deck folder`;
exports.handler = argv => {
  const SERVE_FOLDER = argv.dist ? config.DIST_FOLDER : config.DEV_FOLDER;
  del(SERVE_FOLDER)
    .then(() => {
      const serveDist = Boolean(argv.dist);
      build(bs, argv.dev, SERVE_FOLDER, serveDist, callback);
    })
    .catch(error => {
      logger.error(error);
      shell.exit(1);
    });
};<commit_msg>Improves code<commit_after>'use strict';
import shell from 'shelljs';
import bs from 'browser-sync';
import config from '../config.js';
import configLoader from './../config-loader';
import Generator from 'confetti-generator';
import Loader from 'confetti-loader';
import watchAll from './../assets-watchers';
import * as logger from './../logger';
import path from 'path';
import del from 'del';
const loader = new Loader();
/*
 Function to load data and to build the slide deck.
 */
const build = (bs, dev, folder, serveDist) => {
  logger.message('Loading speaker deck data...');
  loader.loadDeck(configLoader, serveDist)
    .then(deckData => {
      const generator = new Generator(deckData.paths, serveDist);
      logger.success('Speaker deck data loaded.');
      logger.message('Generating speaker deck...');
      generator.generate(deckData)
        .then(() => {
          if (!bs.active) {
            bs.create();
            bs.init({server: folder, open: false});
            /*
             Watch changes on:
             - slide deck settings
             - data slides
             - selected theme config
             */
            bs.watch([
              configLoader.paths.settings,
              configLoader.paths.slides,
              path.join(configLoader.paths.themes, deckData.theme, 'data.yml')
            ]).on('change', () => {
              // If anything is changed rebuild the deck
              build(bs, dev, folder, serveDist);
            });
            bs.watch(configLoader.paths.covers).on('change',
              () => generator.copyCovers().catch(error => logger.error(error)));
            bs.watch(folder).on('change', bs.reload);
            /*
             Watch the theme assets only if the dev mode is switched on.
             */
            if (dev) {
              logger.info('Theme development environment enabled.');
              watchAll(bs, generator, deckData);
            }
          }
        })
        .catch(error => {
          logger.error(error);
          shell.exit(1);
        });
    })
    .catch(error => {
      logger.error(error);
      shell.exit(1);
    });
};
//--------------
// Serve Command
//--------------
exports.command = 'server';
exports.builder = {
  dev: {
    describe: `Enables watching and reload the browser when theme assets changes.`,
    requiresArg: false
  },
  dist: {
    describe: `Serve the dist folder (${config.DIST_FOLDER}).`,
    requiresArg: false
  }
};
exports.desc = `Serve the compiled deck folder`;
exports.handler = argv => {
  const SERVE_FOLDER = argv.dist ? config.DIST_FOLDER : config.DEV_FOLDER;
  del(SERVE_FOLDER)
    .then(() => {
      const serveDist = Boolean(argv.dist);
      build(bs, argv.dev, SERVE_FOLDER, serveDist);
    })
    .catch(error => {
      logger.error(error);
      shell.exit(1);
    });
};
{'fraction_non_alphanumeric': 0.15334961618981158, 'fraction_numerical': 0.00104675505931612, 'mean_word_length': 2.3448074679113184, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 26, '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': '7442925', 'n_tokens_mistral': 1674, 'n_tokens_neox': 1643, 'n_words': 446}