forked from brianchirls/proto-loader
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.js
More file actions
29 lines (22 loc) · 724 Bytes
/
index.js
File metadata and controls
29 lines (22 loc) · 724 Bytes
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
'use strict';
//let fs = require('fs');
let protobuf = require('protobufjs');
let protoTarget = require('protobufjs/cli/targets/json');
//let protoUtil = require('protobufjs/cli/util');
//let path = require("path");
let loaderUtils = require('loader-utils');
module.exports = function (source) {
let options = loaderUtils.parseQuery(this.query) || {};
//let self = this;
let callback = this.async();
if (!callback) {
throw 'proto-loader currently only supports async mode.';
}
if (this.cacheable()) {
this.cacheable();
}
new protobuf.Root().load(this.resourcePath,function(err, root) {
if(err) return callback(err);
protoTarget(root,options,callback);
});
};