forked from seishun/node-steam-resources
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
44 lines (37 loc) · 1.04 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
var fs = require('fs');
var parse = require('csv-parse/lib/sync');
var ProtoBuf = require('protobufjs');
var Steam = exports;
var protos = parse(fs.readFileSync(__dirname + '/protobuf_gen/protos.csv', {
encoding: 'ascii'
}), {
columns: true
});
// one-off
Steam.GC = {
Internal: loadProtoFiles(['../protobuf_gen/gc.proto'])
};
var namespaces = {};
protos.forEach(function(proto) {
if (!namespaces[proto.Namespace])
namespaces[proto.Namespace] = [];
namespaces[proto.Namespace].push(proto.ProtoDir + '/' + proto.ProtoFileName);
});
for (var namespace in namespaces) {
var obj = Steam;
var prop = namespace.split('.').slice(1).reduce(function(last, next) {
if (!obj[last])
obj[last] = {};
obj = obj[last];
return next;
});
obj[prop] = loadProtoFiles(namespaces[namespace]);
}
require('./steam_language_parser');
function loadProtoFiles(paths) {
var builder = ProtoBuf.newBuilder();
paths.forEach(function(path) {
ProtoBuf.loadProtoFile(__dirname + '/protobufs/' + path, builder);
});
return builder.build();
}