-
Notifications
You must be signed in to change notification settings - Fork 2
/
plugins.js
74 lines (59 loc) · 1.27 KB
/
plugins.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
var express = require( "express" );
var fs = require( "fs" );
var app = express();
var pluginFiles = [];
var dashPluginData = "";
function init()
{
app.get( "/" , function( request , response ) {
dashPluginData = loadPlugins( pluginFiles );
response.end( dashPluginData );
} );
pluginFiles = loadPluginFiles();
}
function loadPluginFiles()
{
var pluginFiles = [];
searchDirs = [ __dirname + "/plugins/" ];
while( searchDirs.length > 0 )
{
var dir = searchDirs.shift();
// console.log( "Searching: " + dir );
var files = fs.readdirSync( dir );
for( var i in files )
{
var file = dir + files[i];
if( fs.statSync( file ).isDirectory() )
{
searchDirs.push( file + "/" );
continue;
}
if( file.substring( file.length - 5 ) == ".html" )
{
pluginFiles.push( file );
// console.log( "Added plugin: " + file );
}
}
}
return pluginFiles;
}
function loadPlugins( fileList )
{
var data = "";
for( var i = 0; i < fileList.length; i++ )
{
try
{
data += fs.readFileSync( fileList[i] );
}
catch( e )
{
console.log( "Unable to read " + fileList[i] + ": " + e.message );
}
}
return data;
}
module.exports = {
app : app,
init : init
};