-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtemplate-parser.js
More file actions
29 lines (24 loc) · 822 Bytes
/
template-parser.js
File metadata and controls
29 lines (24 loc) · 822 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
const Mustache = require("mustache");
const fs = require("fs");
function api(root, svc, wsproto) {
var output = "var " + svc + " = {}; \n" + svc + ".metadata = {}; \n";
const template = fs.readFileSync(__dirname + '/template.txt', 'utf8');
const svcdata = root.lookup(svc);
const methods = svcdata["methods"];
const methodNames = Object.keys(methods);
methodNames.forEach( (name,idx) => {
const method = methods[name];
const requestType = method["requestType"];
const requestStream = method["requestStream"];
const responseStream = method["responseStream"];
const responseType = method["responseType"];
var view = {
method: name,
service: svc,
ws: wsproto
};
output += Mustache.render(template, view);
});
return { 'output': output, 'methods': methodNames };
}
module.exports = api;