UNPKG

pg-proto-parser

Version:
25 lines (24 loc) 724 B
import { parse } from '@launchql/protobufjs'; import { readFileSync } from 'fs'; import { ProtoStore } from './store'; import { getOptionsWithDefaults } from './options'; export class PgProtoParser { inFile; options; constructor(inFile, options) { this.inFile = inFile; this.options = getOptionsWithDefaults(options); } readProtoFile() { return readFileSync(this.inFile, 'utf-8'); } parseProto(content) { return parse(content, this.options.parser); } write() { const protoContent = this.readProtoFile(); const ast = this.parseProto(protoContent); const store = new ProtoStore(ast.root, this.options); store.write(); } }