<commit_before>// Copyright 2018 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';

import * as getStdin from 'get-stdin';
import * as protobuf from 'protobufjs';
import * as path from 'path';
import * as plugin from '../../pbjs-genfiles/plugin';

export class Generator {
  root: protobuf.Root;
  request: plugin.google.protobuf.compiler.CodeGeneratorRequest;

  constructor() {
    this.root = new protobuf.Root();
    this.root.resolvePath = (origin, target) => {
      if (origin === '') {
        return target;
      }
      return path.join('proto', target);
    };
    this.request =
        plugin.google.protobuf.compiler.CodeGeneratorRequest.create();
  }

  async initializeFromStdin() {
    const inputBuffer = await getStdin.buffer();
    this.request = plugin.google.protobuf.compiler.CodeGeneratorRequest.decode(
        inputBuffer);
    console.warn(this.request);
  }

  async generate() {
    const fileToGenerate = this.request.fileToGenerate;
    console.warn(fileToGenerate);

    const response =
        plugin.google.protobuf.compiler.CodeGeneratorResponse.create();
    const outputBuffer =
        plugin.google.protobuf.compiler.CodeGeneratorResponse.encode(response)
            .finish();
    process.stdout.write(outputBuffer.toString());
  }
}
<commit_msg>dump list of proto files to response<commit_after>// Copyright 2018 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';

import * as getStdin from 'get-stdin';
import * as protobuf from 'protobufjs';
import * as path from 'path';
import * as plugin from '../../pbjs-genfiles/plugin';

export class Generator {
  root: protobuf.Root;
  request: plugin.google.protobuf.compiler.CodeGeneratorRequest;
  response: plugin.google.protobuf.compiler.CodeGeneratorResponse;

  constructor() {
    this.root = new protobuf.Root();
    this.root.resolvePath = (origin, target) => {
      if (origin === '') {
        return target;
      }
      return path.join('proto', target);
    };
    this.request =
        plugin.google.protobuf.compiler.CodeGeneratorRequest.create();
    this.response =
        plugin.google.protobuf.compiler.CodeGeneratorResponse.create();
  }

  async initializeFromStdin() {
    const inputBuffer = await getStdin.buffer();
    this.request = plugin.google.protobuf.compiler.CodeGeneratorRequest.decode(
        inputBuffer);
    console.warn(this.request);
  }

  addProtosToResponse() {
    const protoFilenames: string[] = [];
    for (const proto of this.request.protoFile) {
      if (proto.name) {
        protoFilenames.push(proto.name);
      }
    }
    const protoList =
        plugin.google.protobuf.compiler.CodeGeneratorResponse.File.create();
    protoList.name = 'proto.list';
    protoList.content = protoFilenames.join('\n') + '\n';
    this.response.file.push(protoList);
  }

  async generate() {
    const fileToGenerate = this.request.fileToGenerate;
    console.warn(fileToGenerate);

    this.response =
        plugin.google.protobuf.compiler.CodeGeneratorResponse.create();

    this.addProtosToResponse();

    const outputBuffer = plugin.google.protobuf.compiler.CodeGeneratorResponse
                             .encode(this.response)
                             .finish();
    // @ts-ignore Argument of type 'Uint8Array' is not assignable to parameter of type 'string'.
    process.stdout.write(outputBuffer);
  }
}

{'fraction_non_alphanumeric': 0.11296882060551287, 'fraction_numerical': 0.0038409399005874378, 'mean_word_length': 3.1335200746965453, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5909595', 'n_tokens_mistral': 1201, 'n_tokens_neox': 1182, 'n_words': 349}