forked from DeviaVir/zenbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zenbot.js
56 lines (45 loc) · 1.46 KB
/
zenbot.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
var semver = require('semver')
var path = require('path')
var version = require('./package.json').version
var program = require('commander')
program.version(version)
program._name = 'zenbot'
var versions = process.versions
if (semver.gt('8.3.0', versions.node)) {
console.log('You are running a node.js version older than 8.3.x, please upgrade via https://nodejs.org/en/')
process.exit(1)
}
var fs = require('fs')
, boot = require('./boot')
boot(function (err, zenbot) {
var command_name = process.argv[2]
if (err) {
throw err
}
var command_directory = './commands'
fs.readdir(command_directory, function(err, files){
if (err) {
throw err
}
var commands = files.map((file)=>{
return path.join(command_directory, file)
}).filter((file)=>{
return fs.statSync(file).isFile()
})
if(command_name)
var command_found = (commands.indexOf(path.join(command_directory, command_name)+'.js') !== -1)
if(command_found) {
var command = require(path.resolve(__dirname, `./commands/${command_name}`))
command(program, zenbot.conf)
}
if(command_name === 'new_backfill'){
command_found = true
command = require(path.resolve(__dirname,'./commands/backfill/backfill'))
command(program, zenbot.conf)
}
if (!command_name || !command_found && (!process.argv[2] || !process.argv[2].match(/^-V|--version$/))) {
program.help()
}
program.parse(process.argv)
})
})