1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | Object.defineProperty(exports, "__esModule", { value: true });
|
16 | exports.load = exports.loadSync = exports.GoogleProtoFilesRoot = void 0;
|
17 | const path = require("path");
|
18 | const protobuf = require("protobufjs");
|
19 | const walk = require("walkdir");
|
20 | let COMMON_PROTO_FILES;
|
21 | class GoogleProtoFilesRoot extends protobuf.Root {
|
22 | constructor(options) {
|
23 | super(options);
|
24 | }
|
25 |
|
26 |
|
27 | static getCommonProtoFiles() {
|
28 | const commonProtoDirs = [
|
29 |
|
30 |
|
31 | 'api',
|
32 | path.join('logging', 'type'),
|
33 | path.join('cloud', 'speech', 'v1'),
|
34 | 'longrunning',
|
35 | 'protobuf',
|
36 |
|
37 | 'rpc',
|
38 | 'type',
|
39 | ].map(dir => path.join(__dirname, '..', '..', 'google', dir));
|
40 | if (!COMMON_PROTO_FILES) {
|
41 | COMMON_PROTO_FILES = commonProtoDirs
|
42 | .map(dir => {
|
43 | return walk.sync(dir)
|
44 | .filter(f => path.extname(f) === '.proto')
|
45 | .map(path.normalize);
|
46 | })
|
47 | .reduce((a, c) => a.concat(c), []);
|
48 | }
|
49 | return COMMON_PROTO_FILES;
|
50 | }
|
51 |
|
52 |
|
53 | resolvePath(_, includePath, alreadyNormalized) {
|
54 | includePath = path.normalize(includePath);
|
55 |
|
56 | if (path.isAbsolute(includePath)) {
|
57 | return includePath;
|
58 | }
|
59 | const fullIncludePath = path.join(__dirname, '..', '..', includePath);
|
60 | const commonProtoFiles = GoogleProtoFilesRoot.getCommonProtoFiles();
|
61 | if (commonProtoFiles.indexOf(fullIncludePath) > -1) {
|
62 | return fullIncludePath;
|
63 | }
|
64 | return protobuf.util.path.resolve(_, includePath, alreadyNormalized);
|
65 | }
|
66 | }
|
67 | exports.GoogleProtoFilesRoot = GoogleProtoFilesRoot;
|
68 | function loadSync(filename, options) {
|
69 | const root = new GoogleProtoFilesRoot();
|
70 | return root.loadSync(filename, options);
|
71 | }
|
72 | exports.loadSync = loadSync;
|
73 | function load(filename, options) {
|
74 | const root = new GoogleProtoFilesRoot();
|
75 | return root.load(filename, options);
|
76 | }
|
77 | exports.load = load;
|
78 |
|
\ | No newline at end of file |