@pqstudio/protobuf_ts_plugin
Version:
The protocol buffer compiler plugin "protobuf-ts" generates TypeScript, gRPC-web, Twirp, and more.
67 lines (66 loc) • 2.74 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.OutFile = void 0;
const protobuf_ts_framework_1 = require("@pqstudio/protobuf_ts_framework");
/**
* A protobuf-ts output file.
*/
class OutFile extends protobuf_ts_framework_1.TypescriptFile {
constructor(name, fileDescriptor, registry, options, type) {
super(name, type);
this.fileDescriptor = fileDescriptor;
this.registry = registry;
this.options = options;
}
getContent() {
var _a;
if (this.isEmpty()) {
return "";
}
let props = [];
if (this.fileDescriptor.package) {
props.push('package "' + this.fileDescriptor.package + '"');
}
props.push('syntax ' + ((_a = this.fileDescriptor.syntax) !== null && _a !== void 0 ? _a : 'proto2'));
let header = [
`/*eslint-disable*/`,
``,
``,
`/**`,
` * PQStudio A group of unknown boys who create happy games`,
` * PQStudio The first stage 2021-2031`,
` */`,
``,
``,
`// @generated ${this.options.pluginCredit}`,
`// @generated from protobuf file "${this.fileDescriptor.name}" (${props.join(', ')})`,
`// @ts-nocheck`,
`// tslint:disable`,
];
if (this.registry.isExplicitlyDeclaredDeprecated(this.fileDescriptor)) {
header.push('// @deprecated');
}
if (this.fileDescriptor.name != "PQMessages.proto") {
if (this.type == "client") {
header.push(`import { register } from "../protobuf/index";`);
header.push(`import { PQMessages } from "./PQMessages";`);
}
else {
header.push(`import { register } from "@xyyx/serizlizer";`);
// typescript esm need js suffix
header.push(`import { PQMessages } from "./PQMessages";`);
}
}
[
...this.registry.sourceCodeComments(this.fileDescriptor, protobuf_ts_framework_1.FileDescriptorProtoFields.syntax).leadingDetached,
...this.registry.sourceCodeComments(this.fileDescriptor, protobuf_ts_framework_1.FileDescriptorProtoFields.package).leadingDetached
].every(block => header.push('//', ...block.split('\n').map(l => '//' + l), '//'));
// 定死协议信息的proto文件为PQMessages
let head = header.join('\n');
if (head.length > 0 && !head.endsWith('\n')) {
head += '\n';
}
return head + super.getContent();
}
}
exports.OutFile = OutFile;