const stripComments = require("strip-json-comments");
const endpointRE = /@endpoint\s*\((url:.+)\s*(method:(?:[ \t]*)(?:get|put|post|delete))\s*(name:.+)?\s*\)[\s\n]*([a-zA-Z0-9_]*)\([a-zA-Z0-9 ,]*\)/gim
const classNameRE = /class ([a-zA-Z-0-9_ ]+) *{/;
module.exports = class ES6HandlerParser {
static parseString(fpath, content, cb) {
let classNameParts = content.match(classNameRE);
let handlerClassName = classNameParts[1].trim();
let matches = [];
content = content.replace(/\/\/\s*@/g, "@") //We allow commenting the line of the endpoint for correct editor syntax coloring
content = stripComments(content) //we remove the comments so we don't deal with commented out endpoints
let paths = [];
while( (matches = endpointRE.exec(content)) !== null) {
console.log(matches)
var params = matches.slice(1,4);
var currentPath = {};
params.forEach(function(p) {
var parts = p.split(":"),
key = parts.shift(),
value = parts.join(":").trim();
Eif(value)
currentPath[key] = value;
})
/**/
let actionStr = matches[4],
handlerName = handlerClassName;
currentPath['action'] = actionStr.trim();
currentPath['handlerPath'] = fpath;
currentPath['handlerName'] = handlerName
currentPath.method = currentPath.method.toUpperCase()
paths.push(currentPath);
// */
}
cb(null, paths);
}
static parse(dir, cb) {
}
} |