steamutils 1.4.35 → 1.4.36

Sign up to get free protection for your applications and to get access to all the features.
package/_steamproto.js ADDED
@@ -0,0 +1,29 @@
1
+ import path from "path";
2
+ import { loadProfos } from "./helpers/protos.js";
3
+ import { fileURLToPath } from "url";
4
+ const __filename = fileURLToPath(import.meta.url);
5
+ const __dirname = path.dirname(__filename);
6
+
7
+ export class SteamProto {
8
+ constructor(proto) {
9
+ this._proto = proto;
10
+ }
11
+
12
+ toProto() {
13
+ const file = loadProfos(path.join(`${__dirname}/protos/`, this._proto.filename));
14
+ const root = root.loadSync(file, {
15
+ keepCase: true,
16
+ });
17
+ return root[this._proto.name];
18
+ }
19
+
20
+ protoEncode(obj) {
21
+ const protobuf = this.toProto();
22
+ return protobuf.encode(protobuf.create(obj)).finish();
23
+ }
24
+
25
+ protoDecode(obj) {
26
+ const protobuf = this.toProto();
27
+ return protobuf.toObject(protobuf.decode(obj), { defaults: true });
28
+ }
29
+ }
@@ -0,0 +1,47 @@
1
+ import helpers, { loadProfos } from "./helpers/protos.js";
2
+ import path from "path";
3
+ import { fileURLToPath } from "url";
4
+ import Protobuf from "protobufjs";
5
+ import fs from "fs";
6
+
7
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
8
+
9
+ function main() {
10
+ const rootDir = `${__dirname}/protos/`;
11
+ const Protos = helpers([
12
+ {
13
+ name: "csgo",
14
+ protos: loadProfos(rootDir),
15
+ },
16
+ ]);
17
+
18
+ const fileName = "steamproto.js";
19
+ const content = fs.readFileSync("_steamproto.js", { encoding: "utf8", flag: "r" });
20
+
21
+ fs.writeFileSync(fileName, `${content}\nexport const SteamProtoType = {};export const ESteamProto = {};`);
22
+
23
+ for (const key in Protos.csgo) {
24
+ let csgo = Protos.csgo[key];
25
+ if (typeof csgo === "function" || typeof csgo === "boolean" || typeof csgo === "string" || Array.isArray(csgo) || csgo === null) {
26
+ continue;
27
+ }
28
+
29
+ if (csgo instanceof Protobuf.Type) {
30
+ const fields = {};
31
+ for (const fieldsKey in csgo.fields) {
32
+ fields[fieldsKey] = fieldsKey;
33
+ }
34
+
35
+ const filename = path.relative(rootDir, csgo.filename);
36
+ fs.appendFileSync(fileName, `SteamProtoType.${key} = ${JSON.stringify({ name: csgo.name, filename })};`);
37
+ } else {
38
+ for (const csgoKey in csgo) {
39
+ if (csgo[csgoKey] instanceof Protobuf.Enum) {
40
+ fs.appendFileSync(fileName, `ESteamProto.${csgoKey} = ${JSON.stringify(csgo[csgoKey].values)};`);
41
+ }
42
+ }
43
+ }
44
+ }
45
+ }
46
+
47
+ main();
package/helpers/protos.js CHANGED
@@ -1,54 +1,52 @@
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
-
33
- protobufs[proto.name] = root;
34
- }
35
-
36
- return protobufs;
37
- }
38
-
39
-
40
- export function loadProfos(dir, protos = []) {
41
- const currentDir = fs.readdirSync(dir);
42
- for (const currentFile of currentDir) {
43
- const _dir = path.join(dir, currentFile);
44
- const isDirectory = fs.lstatSync(_dir).isDirectory()
45
- if (isDirectory) {
46
- loadProfos(_dir, protos)
47
- } else {
48
- if (currentFile.endsWith(".proto")) {
49
- protos.push(_dir)
50
- }
51
- }
52
- }
53
- return protos
54
- }
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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "steamutils",
3
- "version": "1.4.35",
3
+ "version": "1.4.36",
4
4
  "main": "index.js",
5
5
  "dependencies": {
6
6
  "alpha-common-utils": "^1.0.6",