-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.ts
40 lines (32 loc) · 993 Bytes
/
run.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
require('dotenv').config();
require('./src/sentry');
const path = require('path');
const fs = require('fs');
const { argv } = process;
function help() {
const commands = fs
.readdirSync(path.join(__dirname, 'src/commands/'))
.filter(
(file: string) => file.indexOf('.') !== 0 && file.slice(-3) === '.js',
)
.map((file: string) => path.basename(file, path.extname(file)));
/* eslint-disable-next-line */
console.log(`
Usage : node run.js <command> <...>
Commands : ${Object.keys(commands).join(', ')}`);
process.exit(1);
}
if (argv.includes('--help') || argv.length <= 2) {
help();
}
const commandFile = path.join(__dirname, 'src/commands', `${argv[2]}.js`);
if (!fs.existsSync(commandFile)) {
console.log(`Command ${argv[2]} not found`); // eslint-disable-line
help();
}
/* eslint-disable-next-line */
const exported = require(commandFile);
exported.default().catch((e: any) => {
console.log(e); // eslint-disable-line
process.exit(1);
});