<commit_before>#!/usr/bin/env node

/* eslint-disable global-require */
const { lstatSync, readdirSync } = require('fs');
const { join } = require('path');
const { checkDependenciesAndRun, spawn } = require('./cli-utils');

function run() {
  const inquirer = require('inquirer');
  const program = require('commander');
  const chalk = require('chalk');
  const log = require('npmlog');

  const isTgz = (source) => lstatSync(source).isFile() && source.match(/.tgz$/);
  const getDirectories = (source) =>
    readdirSync(source)
      .map((name) => join(source, name))
      .filter(isTgz);

  log.heading = 'storybook';
  const prefix = 'bootstrap';
  log.addLevel('aborted', 3001, { fg: 'red', bold: true });

  const main = program
    .version('5.0.0')
    .option('--all', `Bootstrap everything ${chalk.gray('(all)')}`);

  const createTask = ({
    defaultValue,
    option,
    name,
    check = () => true,
    command,
    pre = [],
    order,
  }) => ({
    value: false,
    defaultValue: defaultValue || false,
    option: option || undefined,
    name: name || 'unnamed task',
    check: check || (() => true),
    order,
    command: () => {
      // run all pre tasks
      pre
        .map((key) => tasks[key])
        .forEach((task) => {
          if (task.check()) {
            task.command();
          }
        });

      log.info(prefix, name);
      command();
    },
  });

  const tasks = {
    core: createTask({
      name: `Core, Dll & Examples ${chalk.gray('(core)')}`,
      defaultValue: true,
      option: '--core',
      command: () => {
        log.info(prefix, 'yarn workspace');
      },
      pre: ['install', 'build', 'dll'],
      order: 1,
    }),
    reset: createTask({
      name: `Clean repository ${chalk.red('(reset)')}`,
      defaultValue: false,
      option: '--reset',
      command: () => {
        log.info(prefix, 'git clean');
        spawn('node -r esm ./scripts/reset.js');
      },
      order: 0,
    }),
    install: createTask({
      name: `Install dependencies ${chalk.gray('(install)')}`,
      defaultValue: false,
      option: '--install',
      command: () => {
        spawn('yarn install --ignore-optional --network-concurrency 8');
      },
      order: 1,
    }),
    build: createTask({
      name: `Build packages ${chalk.gray('(build)')}`,
      defaultValue: false,
      option: '--build',
      command: () => {
        log.info(prefix, 'prepare');
        spawn('lerna run prepare');
      },
      order: 2,
    }),
    dll: createTask({
      name: `Generate DLL ${chalk.gray('(dll)')}`,
      defaultValue: false,
      option: '--dll',
      command: () => {
        log.info(prefix, 'dll');
        setTimeout(() => {
          spawn('lerna run createDlls --scope "@storybook/ui" --scope "@storybook/addon-docs"');
        }, 5000);
      },
      order: 3,
    }),<commit_msg>CHANGE the bootstrap script so it also installs optional dependencies on CI<commit_after>#!/usr/bin/env node

/* eslint-disable global-require */
const { lstatSync, readdirSync } = require('fs');
const { join } = require('path');
const { checkDependenciesAndRun, spawn } = require('./cli-utils');

function run() {
  const inquirer = require('inquirer');
  const program = require('commander');
  const chalk = require('chalk');
  const log = require('npmlog');

  const isTgz = (source) => lstatSync(source).isFile() && source.match(/.tgz$/);
  const getDirectories = (source) =>
    readdirSync(source)
      .map((name) => join(source, name))
      .filter(isTgz);

  log.heading = 'storybook';
  const prefix = 'bootstrap';
  log.addLevel('aborted', 3001, { fg: 'red', bold: true });

  const main = program
    .version('5.0.0')
    .option('--all', `Bootstrap everything ${chalk.gray('(all)')}`);

  const createTask = ({
    defaultValue,
    option,
    name,
    check = () => true,
    command,
    pre = [],
    order,
  }) => ({
    value: false,
    defaultValue: defaultValue || false,
    option: option || undefined,
    name: name || 'unnamed task',
    check: check || (() => true),
    order,
    command: () => {
      // run all pre tasks
      pre
        .map((key) => tasks[key])
        .forEach((task) => {
          if (task.check()) {
            task.command();
          }
        });

      log.info(prefix, name);
      command();
    },
  });

  const tasks = {
    core: createTask({
      name: `Core, Dll & Examples ${chalk.gray('(core)')}`,
      defaultValue: true,
      option: '--core',
      command: () => {
        log.info(prefix, 'yarn workspace');
      },
      pre: ['install', 'build', 'dll'],
      order: 1,
    }),
    reset: createTask({
      name: `Clean repository ${chalk.red('(reset)')}`,
      defaultValue: false,
      option: '--reset',
      command: () => {
        log.info(prefix, 'git clean');
        spawn('node -r esm ./scripts/reset.js');
      },
      order: 0,
    }),
    install: createTask({
      name: `Install dependencies ${chalk.gray('(install)')}`,
      defaultValue: false,
      option: '--install',
      command: () => {
        const command = process.env.CI
          ? 'yarn install --network-concurrency 8'
          : 'yarn install --ignore-optional --network-concurrency 8';
        spawn(command);
      },
      order: 1,
    }),
    build: createTask({
      name: `Build packages ${chalk.gray('(build)')}`,
      defaultValue: false,
      option: '--build',
      command: () => {
        log.info(prefix, 'prepare');
        spawn('lerna run prepare');
      },
      order: 2,
    }),
    dll: createTask({
      name: `Generate DLL ${chalk.gray('(dll)')}`,
      defaultValue: false,
      option: '--dll',
      command: () => {
        log.info(prefix, 'dll');
        setTimeout(() => {
          spawn('lerna run createDlls --scope "@storybook/ui" --scope "@storybook/addon-docs"');
        }, 5000);
      },
      order: 3,
    }),
{'fraction_non_alphanumeric': 0.18943626206196038, 'fraction_numerical': 0.005925173522938886, 'mean_word_length': 2.296875, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 33, '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': '7420719', 'n_tokens_mistral': 1918, 'n_tokens_neox': 1849, 'n_words': 429}