-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.ts
72 lines (55 loc) · 2 KB
/
index.ts
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
61
62
63
64
65
66
67
68
69
70
71
72
import { existsSync } from 'fs'
import LevelingError from './src/classes/LevelingError'
import errors from './src/structures/Errors'
import modulePackage from './package.json'
const colors = {
red: '\x1b[31m',
green: '\x1b[32m',
yellow: '\x1b[33m',
blue: '\x1b[34m',
magenta: '\x1b[35m',
cyan: '\x1b[36m',
white: '\x1b[37m',
reset: '\x1b[0m'
}
function moduleVersion(moduleName: string) {
const modulePath = __dirname.includes('\\')
? __dirname.split('\\').slice(0, -1).join('\\') + `\\${moduleName}`
: __dirname.split('/').slice(0, -1).join('/') + `/${moduleName}`
if (!modulePackage.dependencies) return {
status: false,
version: null,
error: errors.noDependencies
}
if (!existsSync(modulePath)) return {
status: false,
version: null,
error: errors.noDiscordJS
}
const nodeModulePackage = require(modulePath)
return {
status: true,
version: nodeModulePackage.version,
error: null
}
}
function sendError(err: string) {
const error = new LevelingError(err)
console.log(`${colors.red}Failed to start the module:${colors.cyan}`)
console.log(error, colors.reset)
process.exit(1)
}
const djsVersion = moduleVersion('discord.js')
const nodeVersionNumbers = process.version.slice(1).split('.').map(x => Number(x))
function start() {
if (nodeVersionNumbers[0] < 16 && nodeVersionNumbers[1] < 6) return sendError(errors.oldNodeVersion + process.version)
if (djsVersion.error) return sendError(djsVersion.error)
const djsVersionNumbers = djsVersion.version.split('.').map(x => Number(x))
if (djsVersionNumbers[0] < 13 && djsVersionNumbers[1] < 1) return sendError(errors.oldDJSVersion + djsVersion.version)
const Leveling = require('./src/index')
module.exports = Object.assign(Leveling, {
version: modulePackage.version,
docs: 'https://dls-docs.tk'
})
}
start()