forked from Neeraj-x0/X-Asena
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
44 lines (36 loc) · 1.19 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
const fs = require("fs").promises;
const path = require("path");
const config = require("./config");
const connect = require("./lib/connection");
const { getandRequirePlugins } = require("./assets/database/plugins");
global.__basedir = __dirname;
const readAndRequireFiles = async (directory) => {
try {
const files = await fs.readdir(directory);
return Promise.all(
files
.filter((file) => path.extname(file).toLowerCase() === ".js")
.map((file) => require(path.join(directory, file)))
);
} catch (error) {
console.error("Error reading and requiring files:", error);
throw error;
}
};
async function initialize() {
console.log("X-Asena");
try {
await readAndRequireFiles(path.join(__dirname, "/assets/database/"));
console.log("Syncing Database");
await config.DATABASE.sync();
console.log("⬇ Installing Plugins...");
await readAndRequireFiles(path.join(__dirname, "/assets/plugins/"));
await getandRequirePlugins();
console.log("✅ Plugins Installed!");
return await connect();
} catch (error) {
console.error("Initialization error:", error);
return process.exit(1); // Exit with error status
}
}
initialize();