<commit_before>import type { BuildContext, BuildEvents } from '@jovotech/cli-command-build';
import {
  ANSWER_BACKUP,
  ANSWER_CANCEL,
  deleteFolderRecursive,
  getResolvedLocales,
  JovoCliError,
  mergeArrayCustomizer,
  OK_HAND,
  printHighlight,
  printStage,
  printSubHeadline,
  promptOverwriteReverseBuild,
  REVERSE_ARROWS,
  STATION,
  Task,
  wait,
} from '@jovotech/cli-core';
import { FileBuilder, FileObject } from '@jovotech/filebuilder';
import { JovoModelData, JovoModelDataV3, NativeFileInformation } from '@jovotech/model';
import { JovoModelAlexa } from '@jovotech/model-alexa';
import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'fs';
import _get from 'lodash.get';
import _has from 'lodash.has';
import _merge from 'lodash.merge';
import _mergeWith from 'lodash.mergewith';
import _set from 'lodash.set';
import { AlexaCli } from '..';
import { SupportedLocales } from '../constants';
import DefaultFiles from '../DefaultFiles.json';
import { AlexaContext, SupportedLocalesType } from '../interfaces';
import { AlexaHook } from './AlexaHook';

export interface AlexaBuildContext extends AlexaContext, BuildContext {}

export class BuildHook extends AlexaHook<BuildEvents> {
  $plugin!: AlexaCli;
  $context!: AlexaBuildContext;

  install(): void {
    this.middlewareCollection = {
      'before.build': [
        this.updatePluginContext.bind(this),
        this.checkForPlatform.bind(this),
        this.checkForCleanBuild.bind(this),
        this.validateLocales.bind(this),
      ],
      'build': [this.validateModels.bind(this), this.build.bind(this)],
      'reverse.build': [this.buildReverse.bind(this)],
    };
  }

  /**
   * Updates the current plugin context with platform-specific values.
   */
  async updatePluginContext(): Promise<void> {
    if (!this.$context.alexa) {
      this.$context.alexa = {};
    }

    this.$context.alexa.askProfile = this.$plugin.$config.askProfile || 'default';
  }

  /**
   * Checks if the currently selected platform matches this CLI plugin.
   */
  checkForPlatform(): void {
    // Check if this plugin should be used or not.
    if (!this.$context.platforms.includes(this.$plugin.$id)) {
      this.uninstall();
    }
  }

  /**
   * Checks if any provided locale is not supported, thus invalid.
   */
  validateLocales(): void {
    for (const locale of this.$context.locales) {
      const resolvedLocales = getResolvedLocales(
        locale,
        SupportedLocales,
        this.$plugin.$config.locales,
      );

      for (const resolvedLocale of resolvedLocales) {
        if (!SupportedLocales.includes(resolvedLocale as SupportedLocalesType)) {<commit_msg>:sparkles: Add --ask-profile to build<commit_after>import type { BuildPlatformContext, BuildPlatformEvents } from '@jovotech/cli-command-build';
import {
  ANSWER_BACKUP,
  ANSWER_CANCEL,
  deleteFolderRecursive,
  flags,
  getResolvedLocales,
  InstallContext,
  JovoCliError,
  mergeArrayCustomizer,
  OK_HAND,
  printHighlight,
  printStage,
  printSubHeadline,
  promptOverwriteReverseBuild,
  REVERSE_ARROWS,
  STATION,
  Task,
  wait,
} from '@jovotech/cli-core';
import { FileBuilder, FileObject } from '@jovotech/filebuilder';
import { JovoModelData, JovoModelDataV3, NativeFileInformation } from '@jovotech/model';
import { JovoModelAlexa } from '@jovotech/model-alexa';
import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'fs';
import _get from 'lodash.get';
import _has from 'lodash.has';
import _merge from 'lodash.merge';
import _mergeWith from 'lodash.mergewith';
import _set from 'lodash.set';
import { AlexaCli } from '..';
import { SupportedLocales } from '../constants';
import DefaultFiles from '../DefaultFiles.json';
import { AlexaContext, SupportedLocalesType } from '../interfaces';
import { AlexaHook } from './AlexaHook';

export interface AlexaBuildPlatformContext extends AlexaContext, BuildPlatformContext {
  flags: BuildPlatformContext['flags'] & { 'ask-profile'?: string };
}

export class BuildHook extends AlexaHook<BuildEvents> {
  $plugin!: AlexaCli;
  $context!: AlexaBuildContext;

  install(): void {
    this.middlewareCollection = {
      'before.build': [
        this.updatePluginContext.bind(this),
        this.checkForPlatform.bind(this),
        this.checkForCleanBuild.bind(this),
        this.validateLocales.bind(this),
      ],
      'build': [this.validateModels.bind(this), this.build.bind(this)],
      'reverse.build': [this.buildReverse.bind(this)],
    };
  }

  /**
   * Add platform-specific CLI options, including flags and args.
   * @param context - Context providing an access point to command flags and args.
   */
  addCliOptions(context: InstallContext): void {
    if (context.command !== 'build:platform') {
      return;
    }

    context.flags['ask-profile'] = flags.string({
      description: 'Name of used ASK profile',
    });
  }

  /**
   * Updates the current plugin context with platform-specific values.
   */
  async updatePluginContext(): Promise<void> {
    if (!this.$context.alexa) {
      this.$context.alexa = {};
    }

    this.$context.alexa.askProfile = this.$plugin.config.askProfile || 'default';
  }

  /**
   * Checks if the currently selected platform matches this CLI plugin.
   */
  checkForPlatform(): void {
    // Check if this plugin should be used or not.
    if (!this.$context.platforms.includes(this.$plugin.$id)) {
      this.uninstall();
    }
  }

  /**
   * Checks if any provided locale is not supported, thus invalid.
   */
  validateLocales(): void {
    for (const locale of this.$context.locales) {
      const resolvedLocales = getResolvedLocales(
        locale,
        SupportedLocales,
        this.$plugin.$config.locales,
      );

      for (const resolvedLocale of resolvedLocales) {
        if (!SupportedLocales.includes(resolvedLocale as SupportedLocalesType)) {
{'fraction_non_alphanumeric': 0.12154133423866915, 'fraction_numerical': 0.00033950093362756747, 'mean_word_length': 3.7325301204819277, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '2646347', 'n_tokens_mistral': 1838, 'n_tokens_neox': 1754, 'n_words': 421}