UNPKG

@whisklabs/grpc

Version:

gRPC generator and http library for typescript

80 lines 2.39 kB
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i); ar[i] = from[i]; } } return to.concat(ar || Array.prototype.slice.call(from)); }; import { isText } from '@whisklabs/typeguards'; import { mkdirSync, readdirSync, statSync } from 'fs'; import { extname, join } from 'path'; import { pbjs, pbts } from 'protobufjs/cli'; var _a = process.env, PROTO_DIR = _a.PROTO_DIR, PROTO_OUT = _a.PROTO_OUT; if (!isText(PROTO_DIR)) { throw new Error('No PROTO_DIR path'); } if (!isText(PROTO_OUT)) { throw new Error('No PROTO_OUT path'); } mkdirSync(PROTO_OUT, { recursive: true }); // dublicate bugs var exclude = /google\/api\/http\.proto|google\/protobuf\/(descriptor|type|source_context|api).proto|bugs\//; var files = walk(PROTO_DIR); pbjs.main(__spreadArray([ '-t', 'static-module', '-w', 'es6', '--es6', '-o', "".concat(PROTO_OUT, "/out.js"), '--no-delimited', '--no-create', '--no-convert', '--no-verify' ], files, true)); pbjs.main(__spreadArray([ '-t', 'json', '-w', 'es6', '--es6', '-o', "".concat(PROTO_OUT, "/json.json"), '--no-delimited', '--no-create', '--no-convert', '--no-verify' ], files, true)); pbjs.main(__spreadArray([ '-t', 'json-module', '-w', 'es6', '--es6', '-o', "".concat(PROTO_OUT, "/json-module.js"), '--no-delimited', '--no-create', '--no-convert', '--no-verify' ], files, true)); pbts.main(__spreadArray(['-o', "".concat(PROTO_OUT, "/out.d.ts"), "".concat(PROTO_OUT, "/out.js")], files, true)); function walk(directory, filepaths) { if (filepaths === void 0) { filepaths = []; } var dirFiles = readdirSync(directory); for (var _i = 0, dirFiles_1 = dirFiles; _i < dirFiles_1.length; _i++) { var filename = dirFiles_1[_i]; var filepath = join(directory, filename); if (statSync(filepath).isDirectory()) { walk(filepath, filepaths); } else if (extname(filename) === '.proto' && !exclude.test(filepath)) { filepaths.push(filepath); } } return filepaths; } //# sourceMappingURL=protobufjs.js.map