Repository navigation
Expand file tree
/
Copy pathmain.js
More file actions
50 lines (40 loc) · 1.45 KB
/
Copy pathmain.js
File metadata and controls
50 lines (40 loc) · 1.45 KB
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
/* @flow */
import colors from 'colors/safe';
import {format} from 'util';
import commandFinder from './command/finder';
function cleanUp() {
process.stdout.write('\x1B[?25h') // Show terminal cursor
process.stdout.write(colors.rainbow("Cleaning up...\n"));
process.exit(1);
}
process.on('unhandledRejection', function (err, p) {
process.stderr.write(format("uncaught rejection\n%s\n%s\n", err, err.stack));
cleanUp();
});
process.on('uncaughtException', function (err) {
process.stderr.write(format("uncaught exception", err, err.stack, "\n"));
cleanUp();
});
process.on('SIGINT', () => {
process.stderr.write("\n\nCaught SIGINT\n");
cleanUp();
});
export async function run(): Promise<void> {
process.stderr.write("Starting tool...\n");
const commandMap = await commandFinder(__dirname);
const command = process.argv[2];
const commandModulePath = commandMap.get(command);
if (command == undefined || commandModulePath == undefined) {
const HelpCommand = require('./help/helpCommand').default;
if (command == undefined) {
await HelpCommand.showGeneralUsage(HelpCommand.BAD_ARGS);
} else {
process.stderr.write(format("Unsupported command `%s`\n", command));
await HelpCommand.showGeneralUsage(HelpCommand.BAD_ARGS);
}
} else {
/* $FlowFixMe - Babel transforms when things are required, so we only want to require the
* command we're running */
await require(commandModulePath).default.go();
}
}