-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
executable file
·96 lines (70 loc) · 1.87 KB
/
app.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
require('babel/register');
var basePath = process.cwd(),
Server = require(basePath + '/web/server/server'),
ManagePlugin = require(basePath + '/core/manager/pluginsManager'),
pluginManager, server;
var fs = require('fs');
// Load config
var ConfigEnv = require(basePath + '/config/web/environnement');
Object.assign(process.env, ConfigEnv);
pluginManager = new ManagePlugin({pathProcess: basePath});
pluginManager
.updateDB()
.loadPlugins('/plugins');
server = new Server();
// server.loadRoutesServer();
// load plugin routes
loadRouteOnServer(pluginManager.plugins);
/**
* add plugin
*/
pluginManager.on('addPlugin', (pluginName) => {
// Get plugin
let plugin = pluginManager.getPlugin(pluginName);
// send to front asset to add
server.io.emit('assets:add', plugin.assets)
// stop server for add routes of plugins
server.stop();
loadRouteOnServer(pluginManager.plugins);
// reload routes server
server.loadRoutesServer();
});
/**
* Delete plugins
*/
pluginManager.on('deletePlugin', (assets) => {
// send to front the asset to delete
server.io.emit('assets:delete', assets)
// stop server for add routes
server.stop();
loadRouteOnServer(pluginManager.plugins);
// delete assets
server.removeAssets(assets);
// reload routes server
server.loadRoutesServer();
})
server.set({pluginManager: pluginManager})
server.start();
function loadRouteOnServer(plugins){
for(let pluginName in plugins){
let plugin = plugins[pluginName];
server.on('socketLoad', ()=>{
for(let routeSocket of plugin.routes.api){
server.addRouteSocket(routeSocket);
}
})
for(let route of plugin.routes.front){
server.addRoute(route);
}
if(-1 === server.assets.indexOf(plugin.assets)){
if(Array.isArray(plugin.assets)){
plugin.assets.forEach((asset)=>{
server.assets.push(asset);
})
}
else{
server.assets.push(plugin.assets);
}
}
}
}