steamutils 1.4.47 → 1.4.49

Sign up to get free protection for your applications and to get access to all the features.
package/helpers/protos.js CHANGED
@@ -1,52 +1,48 @@
1
- import Protobuf from "protobufjs";
2
- import fs from "fs";
3
- import path from "path";
4
- import { fileURLToPath } from "url";
5
-
6
- const __filename = fileURLToPath(import.meta.url);
7
- const __dirname = path.dirname(__filename);
8
-
9
- export default function Protos(protos, ignoreErrors = true) {
10
- const protobufs = {};
11
-
12
- for (let proto of protos) {
13
- let root = new Protobuf.Root();
14
- let files = Array.isArray(proto.protos) ? proto.protos : fs.readdirSync(proto.protos).map((file) => path.join(proto.protos, file));
15
-
16
- for (let file of files) {
17
- if (!file.endsWith(".proto") || !fs.existsSync(file)) {
18
- continue;
19
- }
20
-
21
- try {
22
- root = root.loadSync(file, {
23
- keepCase: true,
24
- });
25
- } catch (err) {
26
- if (!ignoreErrors) {
27
- throw err;
28
- }
29
- }
30
- }
31
-
32
- protobufs[proto.name] = root;
33
- }
34
-
35
- return protobufs;
36
- }
37
-
38
- export function loadProfos(dir, protos = []) {
39
- const currentDir = fs.readdirSync(dir);
40
- for (const currentFile of currentDir) {
41
- const _dir = path.join(dir, currentFile);
42
- const isDirectory = fs.lstatSync(_dir).isDirectory();
43
- if (isDirectory) {
44
- loadProfos(_dir, protos);
45
- } else {
46
- if (currentFile.endsWith(".proto")) {
47
- protos.push(_dir);
48
- }
49
- }
50
- }
51
- return protos;
52
- }
1
+ import Protobuf from "protobufjs";
2
+ import fs from "fs";
3
+ import path from "path";
4
+
5
+ export default function Protos(protos, ignoreErrors = true) {
6
+ const protobufs = {};
7
+
8
+ for (let proto of protos) {
9
+ const root = new Protobuf.Root();
10
+ const files = Array.isArray(proto.protos) ? proto.protos : fs.readdirSync(proto.protos).map((file) => path.join(proto.protos, file));
11
+
12
+ for (const file of files) {
13
+ if (!file.endsWith(".proto") || !fs.existsSync(file)) {
14
+ continue;
15
+ }
16
+
17
+ const childRoot = new Protobuf.Root().loadSync(file, {
18
+ keepCase: true,
19
+ });
20
+
21
+ for (const child of childRoot.nestedArray) {
22
+ try {
23
+ root.add(child);
24
+ } catch (e) {}
25
+ }
26
+ }
27
+
28
+ protobufs[proto.name] = root;
29
+ }
30
+
31
+ return protobufs;
32
+ }
33
+
34
+ export function loadProfos(dir, protos = []) {
35
+ const currentDir = fs.readdirSync(dir);
36
+ for (const currentFile of currentDir) {
37
+ const _dir = path.join(dir, currentFile);
38
+ const isDirectory = fs.lstatSync(_dir).isDirectory();
39
+ if (isDirectory) {
40
+ loadProfos(_dir, protos);
41
+ } else {
42
+ if (currentFile.endsWith(".proto")) {
43
+ protos.push(_dir);
44
+ }
45
+ }
46
+ }
47
+ return protos;
48
+ }