UNPKG

@whisklabs/grpc

Version:

gRPC generator and http library for typescript

82 lines 2.54 kB
"use strict"; 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)); }; Object.defineProperty(exports, "__esModule", { value: true }); var typeguards_1 = require("@whisklabs/typeguards"); var fs_1 = require("fs"); var path_1 = require("path"); var cli_1 = require("protobufjs/cli"); var _a = process.env, PROTO_DIR = _a.PROTO_DIR, PROTO_OUT = _a.PROTO_OUT; if (!(0, typeguards_1.isText)(PROTO_DIR)) { throw new Error('No PROTO_DIR path'); } if (!(0, typeguards_1.isText)(PROTO_OUT)) { throw new Error('No PROTO_OUT path'); } (0, fs_1.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); cli_1.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)); cli_1.pbjs.main(__spreadArray([ '-t', 'json', '-w', 'es6', '--es6', '-o', "".concat(PROTO_OUT, "/json.json"), '--no-delimited', '--no-create', '--no-convert', '--no-verify' ], files, true)); cli_1.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)); cli_1.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 = (0, fs_1.readdirSync)(directory); for (var _i = 0, dirFiles_1 = dirFiles; _i < dirFiles_1.length; _i++) { var filename = dirFiles_1[_i]; var filepath = (0, path_1.join)(directory, filename); if ((0, fs_1.statSync)(filepath).isDirectory()) { walk(filepath, filepaths); } else if ((0, path_1.extname)(filename) === '.proto' && !exclude.test(filepath)) { filepaths.push(filepath); } } return filepaths; } //# sourceMappingURL=protobufjs.js.map