-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
init.js
53 lines (35 loc) · 1.4 KB
/
init.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
const pfs = require(`./util/promisifiedFS`)
module.exports = () => new Promise(async res => {
const initStart = Date.now();
console.log(`Initializing...`);
const path = await require(`./util/getPath`)(`./init`, true, false, true)
const initScripts = (await pfs.readdirSync(path)).filter(f => f.endsWith(`.js`));
console.log(`Scripts: ${initScripts.join(`, `)}`)
const scripts = [];
for(const file of initScripts) {
try {
scripts.push(new Promise(async res => {
const start = Date.now();
console.log(`Running init script ${file}...`)
const result = await require(`./init/${file}`)();
console.log(`init script ${file} completed in ${Date.now() - start}ms`)
return res({
script: file.split(`.`).slice(0, -1).join(`.`),
time: Date.now() - start,
result
});
}));
} catch(e) {
console.log(`Failed to run init script ${file}! -- ${e}`);
}
};
const times = await Promise.all(scripts);
console.log(times.map(o => `${o.script} / ${o.time}ms`));
let obj = {};
for(const script of times) {
obj[script.script] = script.result;
};
console.log(`Completed init scripts in ${Date.now() - initStart}ms`)
global.init = obj;
return res(obj);
})