-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
49 lines (44 loc) · 1.25 KB
/
index.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
'use strict';
const fs = require('fs');
const path = require('path');
const extType = require('config')('extension');
const driver = {};
let tmp;
/* original driver. */
fs.readdirSync(__dirname)
.filter(m => {
return fs.statSync(path.join(__dirname, m)).isDirectory() && m !== '.git' && m !== 'tests';
})
.forEach( m => {
driver[m] = {};
fs.readdirSync(path.join(__dirname, m)).forEach( s => { // snapshot ...
if (s !== '.DS_Store' && path.extname(s) !== '.json') {
tmp = require(path.join(__dirname, m, s));
tmp.ref = driver;
driver[m][path.basename(s, '.js')] = tmp;
}
});
});
/* driver with extensions. */
if (extType) {
const extPath = path.join(__dirname, 'extensions', extType);
let extPathList = [];
try {
extPathList = fs.readdirSync(extPath);
} catch (err) {
console.log();
}
extPathList.filter( m => { // cinder ...
return fs.statSync(path.join(extPath, m)).isDirectory();
}).forEach( m => {
if ( !driver[m] ) {
driver[m] = {};
}
fs.readdirSync(extPath + '/' + m).forEach( s => { // snapshot ...
if (s !== '.DS_Store') {
driver[m][path.basename(s, '.js')] = require(extPath + '/' + m + '/' + s);
}
});
});
}
module.exports = driver;