This repository has been archived by the owner on May 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
routeBuilder.js
45 lines (38 loc) · 1.84 KB
/
routeBuilder.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
45
var fs = require('fs');
var config = require('./config/config');
var _ = require("lodash");
var path = config.thisServer.pluginPath;
var results = fs.readdirSync(path);
var routes = [];
results.forEach(function(result) {
var stats = fs.statSync(path + '/' + result);
if (stats.isDirectory()) {
var dirContents = fs.readdirSync(path + '/' + result);
dirContents.forEach(function(file) {
var stats = fs.statSync(path + '/' + result + '/' + file);
if (stats.isFile() && file === "manifest.json") {
var content = JSON.parse(fs.readFileSync(path + '/' + result + '/' + file));
var entries = _.concat(content);
entries.forEach(function(e, i) {
var obj = {
id: i + 1,
name: e.componentName || e.pluginDir,
stateName: e.stateName || e.componentName || e.pluginDir,
path: "./plugins/" + e.pluginDir + "/routes",
pluginDir: e.pluginDir,
title: e.title,
stage: _.get(e, 'stage', ''),
authentication: _.merge({ enabled: false, roles: [] }, _.get(e, 'authentication')),
inMenu: _.get(e, 'inMenu', true),
clientFiles: e.clientFiles || [],
templateUrl: e.templateUrl || "plugins/" + e.pluginDir + "/index.html",
url: e.url || "/" + (e.componentName || e.pluginDir),
useSocketIO: e.useSocketIO ? true : false
};
if ((content.hasOwnProperty('disabled') && content.disabled !== true) || !(content.hasOwnProperty('disabled'))) routes.push(obj);
})
}
});
}
});
module.exports = routes;