<commit_before>import { Logger} from './logger/logger';
import { generateContext } from './util/config';
import * as Constants from './util/constants';
import { BuildContext } from './util/interfaces';
import { readFileAsync } from './util/helpers';
import { getTypescriptSourceFile, appendNgModuleDeclaration, insertNamedImportIfNeeded } from './util/typescript-utils';
import { applyTemplates, filterOutTemplates, getNgModules, GeneratorOption, GeneratorRequest, hydrateRequest, readTemplates, writeGeneratedFiles } from './generators/util';

export { getNgModules, GeneratorOption, GeneratorRequest };

export function generateNonTab(request: GeneratorRequest) {
  const context = generateContext();
  return processNonTabRequest(context, request);
}

export function processPageRequest(context: BuildContext, name: string) {
  return processNonTabRequest(context, { type: 'page', name });
}

export function processPipeRequest(context: BuildContext, name: string, ngModulePath: string) {
  const hydratedRequest = hydrateRequest(context, { type: 'pipe', name });

  return readFileAsync(ngModulePath).then((fileContent: string) => {
    fileContent = insertNamedImportIfNeeded(ngModulePath, fileContent, name, `./${name}`);
    fileContent = appendNgModuleDeclaration(ngModulePath, fileContent, name);
    // TODO: write file

    return processNonTabRequest(context, hydratedRequest).then(() => {
      // TODO
    });
  });
}

function processNonTabRequest(context: BuildContext, request: GeneratorRequest): Promise<string[]> {
  Logger.debug('[Generators] processNonTabRequest: Hydrating the request with project data ...');
  const hydratedRequest = hydrateRequest(context, request);
  Logger.debug('[Generators] processNonTabRequest: Reading templates ...');
  return readTemplates(hydratedRequest.dirToRead).then((map: Map<string, string>) => {
    Logger.debug('[Generators] processNonTabRequest: Filtering out NgModule and Specs if needed ...');
    return filterOutTemplates(hydratedRequest, map);
  }).then((filteredMap: Map<string, string>) => {
    Logger.debug('[Generators] processNonTabRequest: Applying tempaltes ...');
    const appliedTemplateMap = applyTemplates(hydratedRequest, filteredMap);
    Logger.debug('[Generators] processNonTabRequest: Writing generated files to disk ...');
    return writeGeneratedFiles(hydratedRequest, appliedTemplateMap);
  });
}

export function listOptions() {<commit_msg>chore(generators): write ngmodule changes<commit_after>import { Logger} from './logger/logger';
import { generateContext } from './util/config';
import * as Constants from './util/constants';
import { BuildContext } from './util/interfaces';
import { readFileAsync, writeFileAsync } from './util/helpers';
import { getTypescriptSourceFile, appendNgModuleDeclaration, insertNamedImportIfNeeded } from './util/typescript-utils';
import { applyTemplates, filterOutTemplates, getNgModules, GeneratorOption, GeneratorRequest, hydrateRequest, readTemplates, writeGeneratedFiles } from './generators/util';

export { getNgModules, GeneratorOption, GeneratorRequest };

export function generateNonTab(request: GeneratorRequest) {
  const context = generateContext();
  return processNonTabRequest(context, request);
}

export function processPageRequest(context: BuildContext, name: string) {
  return processNonTabRequest(context, { type: 'page', name });
}

export function processPipeRequest(context: BuildContext, name: string, ngModulePath: string) {
  const hydratedRequest = hydrateRequest(context, { type: 'pipe', name });

  return readFileAsync(ngModulePath).then((fileContent: string) => {
    fileContent = insertNamedImportIfNeeded(ngModulePath, fileContent, name, `./${name}`);
    fileContent = appendNgModuleDeclaration(ngModulePath, fileContent, name);
    return writeFileAsync(ngModulePath, fileContent);
  }).then(() => {
    return processNonTabRequest(context, hydratedRequest);
  }).then(() => {
    // TODO
  });
}

function processNonTabRequest(context: BuildContext, request: GeneratorRequest): Promise<string[]> {
  Logger.debug('[Generators] processNonTabRequest: Hydrating the request with project data ...');
  const hydratedRequest = hydrateRequest(context, request);
  Logger.debug('[Generators] processNonTabRequest: Reading templates ...');
  return readTemplates(hydratedRequest.dirToRead).then((map: Map<string, string>) => {
    Logger.debug('[Generators] processNonTabRequest: Filtering out NgModule and Specs if needed ...');
    return filterOutTemplates(hydratedRequest, map);
  }).then((filteredMap: Map<string, string>) => {
    Logger.debug('[Generators] processNonTabRequest: Applying tempaltes ...');
    const appliedTemplateMap = applyTemplates(hydratedRequest, filteredMap);
    Logger.debug('[Generators] processNonTabRequest: Writing generated files to disk ...');
    return writeGeneratedFiles(hydratedRequest, appliedTemplateMap);
  });
}

export function listOptions() {
{'fraction_non_alphanumeric': 0.12290276935516474, 'fraction_numerical': 0.0, 'mean_word_length': 6.181422351233672, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 18, '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': '7084602', 'n_tokens_mistral': 1339, 'n_tokens_neox': 1321, 'n_words': 322}