<commit_before>import * as ts from '@schematics/angular/node_modules/typescript';
import { Tree, SchematicsException } from '@angular-devkit/schematics';
import { Schema } from './schema';
import { getProjectTargets, targetBuildNotFoundError } from '@schematics/angular/utility/project-targets';
import { addImport, getTsSourceFile, prettierConstructorParameters } from '../utils/ast';
import { findNodes } from '@schematics/angular/utility/ast-utils';

/** Adds the styles to the src/app/app.component.ts file. */
export function setUpStyles(options: Schema, filePath: string): (host: Tree) => Tree {
  return (host: Tree) => {
    const projectTargets = getProjectTargets(host, options.project);

    if (!projectTargets.build) {
      throw targetBuildNotFoundError();
    }

    const buffer = host.read(filePath);

    if (buffer === null) {
      throw new SchematicsException(`Could not read index file: ${filePath}`);
    }

    // add import style
    addImport(host, filePath, ['LyTheme2', 'ThemeVariables'], '@alyle/ui');

    let component = getComponentOrDirective(host, filePath);
    const componentStartPos = component.decorators![0].pos;

    const recorder = host.beginUpdate(filePath);
    recorder.insertLeft(componentStartPos, `\n\nconst STYLES = (theme: ThemeVariables) => ({
  '@global': {
    body: {
      backgroundColor: theme.background.default,
      color: theme.text.default,
      fontFamily: theme.typography.fontFamily,
      margin: 0,
      direction: theme.direction
    }
  }
});`);
    host.commitUpdate(recorder);

    component = getComponentOrDirective(host, filePath);

    const hasConstructor = component.members
      .some(prop => (prop.kind === ts.SyntaxKind.Constructor) && !!(prop as ts.ConstructorDeclaration).body);
    let constructor: ts.ConstructorDeclaration;
    let __recorder = host.beginUpdate(filePath);
    const propertyValue = `\n  readonly classes = this.theme.addStyleSheet(STYLES);\n`;
    const constructorCall = `  constructor(\n    private theme: LyTheme\n  ) { }\n`;
    const OpenBraceTokenPos = findNodes(component, ts.SyntaxKind.OpenBraceToken)
    .filter(prop => prop.parent === component).map(prop => prop.end)[0];

    __recorder.insertLeft(OpenBraceTokenPos, propertyValue);
    host.commitUpdate(__recorder);
    __recorder = host.beginUpdate(filePath);


    component = getComponentOrDirective(host, filePath);

    if (hasConstructor) {
      constructor = getContructor(component);

      const pos = findNodes(constructor, ts.SyntaxKind.OpenParenToken)
      .filter(prop => prop.parent === constructor).map(prop => prop.end)[0];

      if (constructor.parameters.length) {
        __recorder.insertLeft(pos, `\n    private theme: LyTheme2,\n  `);
      } else {<commit_msg>chore(schematics): fix styles<commit_after>import * as ts from '@schematics/angular/node_modules/typescript';
import { Tree, SchematicsException } from '@angular-devkit/schematics';
import { Schema } from './schema';
import { getProjectTargets, targetBuildNotFoundError } from '@schematics/angular/utility/project-targets';
import { addImport, getTsSourceFile, prettierConstructorParameters } from '../utils/ast';
import { findNodes } from '@schematics/angular/utility/ast-utils';

/** Adds the styles to the src/app/app.component.ts file. */
export function setUpStyles(options: Schema, filePath: string): (host: Tree) => Tree {
  return (host: Tree) => {
    const projectTargets = getProjectTargets(host, options.project);

    if (!projectTargets.build) {
      throw targetBuildNotFoundError();
    }

    const buffer = host.read(filePath);

    if (buffer === null) {
      throw new SchematicsException(`Could not read index file: ${filePath}`);
    }

    // add import style
    addImport(host, filePath, ['LyTheme2', 'ThemeVariables'], '@alyle/ui');

    let component = getComponentOrDirective(host, filePath);
    const componentStartPos = component.decorators![0].pos;

    const recorder = host.beginUpdate(filePath);
    recorder.insertLeft(componentStartPos, `\n\nconst STYLES = (theme: ThemeVariables) => ({
  '@global': {
    body: {
      backgroundColor: theme.background.default,
      color: theme.text.default,
      fontFamily: theme.typography.fontFamily,
      margin: 0,
      direction: theme.direction
    }
  }
});`);
    host.commitUpdate(recorder);

    component = getComponentOrDirective(host, filePath);

    const hasConstructor = component.members
      .some(prop => (prop.kind === ts.SyntaxKind.Constructor) && !!(prop as ts.ConstructorDeclaration).body);
    let constructor: ts.ConstructorDeclaration;
    let __recorder = host.beginUpdate(filePath);
    const propertyValue = `\n  readonly classes = this.theme.addStyleSheet(STYLES);\n`;
    const constructorCall = `  constructor(\n    private theme: LyTheme2\n  ) { }\n`;
    const OpenBraceTokenPos = findNodes(component, ts.SyntaxKind.OpenBraceToken)
    .filter(prop => prop.parent === component).map(prop => prop.end)[0];

    __recorder.insertLeft(OpenBraceTokenPos, propertyValue);
    host.commitUpdate(__recorder);
    __recorder = host.beginUpdate(filePath);


    component = getComponentOrDirective(host, filePath);

    if (hasConstructor) {
      constructor = getContructor(component);

      const pos = findNodes(constructor, ts.SyntaxKind.OpenParenToken)
      .filter(prop => prop.parent === constructor).map(prop => prop.end)[0];

      if (constructor.parameters.length) {
        __recorder.insertLeft(pos, `\n    private theme: LyTheme2,\n  `);
      } else {
{'fraction_non_alphanumeric': 0.13098464317976513, 'fraction_numerical': 0.0023486901535682025, 'mean_word_length': 4.046490428441203, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '2746447', 'n_tokens_mistral': 1638, 'n_tokens_neox': 1594, 'n_words': 348}