forked from evancohen/smart-mirror
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.schema.js
29 lines (26 loc) · 1.14 KB
/
config.schema.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
const fs = require('fs');
const pluginDir = __dirname + '/plugins';
//TODO get general schema, then plugin schema
function getConfigSchema(cb) {
let configSchema = { schema: {}, form: [], value: {} };
fs.readdir(pluginDir, function (err, files) {
let l = files.length - 1;
for (var index = 0; index < files.length; ++index) {
var file = files[index];
if (file[0] !== '.') {
var filePath = pluginDir + '/' + file + '/config.schema.json';
fs.readFile(filePath, 'utf8', function(err, data) {
--l;
if (!err) {
let pluginConfigSchema = JSON.parse(data);
Object.assign(configSchema.schema, pluginConfigSchema.schema)
if (pluginConfigSchema.form){configSchema.form = configSchema.form.concat(pluginConfigSchema.form)}
if (pluginConfigSchema.value){Object.assign(configSchema.value,pluginConfigSchema.value)}
}
!l && cb (configSchema)
});
}
}
});
}
module.exports = getConfigSchema