-
Notifications
You must be signed in to change notification settings - Fork 34
/
index.js
60 lines (52 loc) · 1.56 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
50
51
52
53
54
55
56
57
58
59
60
// Modul dan dependensi yang diperlukan
require("./config.js");
const handler = require("./handler.js");
const pkg = require("./package.json");
const tools = require("./tools/exports.js");
const CFonts = require("cfonts");
const fs = require("fs");
const http = require("http");
const path = require("path");
const SimplDB = require("simpl.db");
// Buat basis data
const db = new SimplDB();
const dbFile = path.join(__dirname, "database.json");
if (!fs.existsSync(dbFile)) fs.writeFileSync(dbFile, JSON.stringify({}), "utf8");
// Atur konfigurasi ke global
global.handler = handler;
global.config.pkg = pkg;
global.tools = tools;
global.db = db;
// Memulai
console.log(`[${pkg.name}] Starting...`);
// Tampilkan judul menggunakan CFonts
CFonts.say(pkg.name, {
font: "chrome",
align: "center",
gradient: ["red", "magenta"]
});
// Menampilkan informasi paket
const authorName = pkg.author.name || pkg.author;
CFonts.say(
`'${pkg.description}'\n` +
`By ${authorName}`, {
font: "console",
align: "center",
gradient: ["red", "magenta"]
}
);
// Fungsi untuk menjalankan server jika diaktifkan
if (config.system.useServer) {
const port = config.system.port || 3000;
const server = http.createServer((req, res) => {
res.writeHead(200, {
"Content-Type": "text/plain"
});
res.end(`${pkg.name} is running on port ${port}`);
});
server.listen(port, () => {
console.log(`[${pkg.name}] Server is running at http://localhost:${port}`);
});
}
// Impor dan jalankan modul utama
require("./main.js");