-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathparser.js
39 lines (29 loc) · 915 Bytes
/
parser.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
'use strict';
/* middleware and HTTP method routes*/
var routerLevelPattern = /\.(?:all|get|param|post|delete|post|route|use)\('(\/([\w+\-\*\:]|\/?)*)/g;
/* http server*/
var expressInstanciationPattern = /createServer\(/g;
module.exports = function(filepath, source) {
console.log('parsing %s', filepath);
var containsExpressInstance = expressInstanciationPattern.test(source);
var routes = [];
var uses;
var lastIndex = -1;
while ((uses = routerLevelPattern.exec(source)) !== null) {
routes.push(uses[1]);
if (lastIndex < 0) {
lastIndex = routerLevelPattern.lastIndex;
}
}
if (routes.length) {
console.log('routes defined are %s', routes.toString());
}
if (containsExpressInstance) {
console.log('express instance defined in this file');
}
console.log('\n\n');
return {
containsExpressInstance: containsExpressInstance,
routes: routes
};
};