UNPKG

1.14 kBJavaScriptView Raw
1var chalk = require('chalk');
2
3function print(msg) {
4 console.error(chalk.red(msg));
5}
6
7var handlers = {
8 MISSING_INPUT_OPTION: () => {
9 print('You must specify an --input (-i) option');
10 },
11
12 MISSING_OUTPUT_DIR: () => {
13 print(
14 'You must specify an --output (-o) option when compiling a directory of files'
15 );
16 },
17
18 MISSING_OUTPUT_FILE: () => {
19 print(
20 'You must specify an --output (-o) option when creating a file with a sourcemap'
21 );
22 },
23
24 ONE_AT_A_TIME: () => {
25 print('Bublé can only compile one file/directory at a time');
26 },
27
28 DUPLICATE_IMPORT_OPTIONS: () => {
29 print('use --input, or pass input path as argument – not both');
30 },
31
32 BAD_TARGET: () => {
33 print('illegal --target option');
34 }
35};
36
37module.exports = function handleError(err) {
38 var handler;
39
40 if ((handler = handlers[err && err.code])) {
41 handler(err);
42 } else {
43 if (err.snippet) print('---\n' + err.snippet);
44 print(err.message || err);
45
46 if (err.stack) {
47 console.error(chalk.grey(err.stack));
48 }
49 }
50
51 console.error(
52 'Type ' +
53 chalk.cyan('buble --help') +
54 ' for help, or visit https://buble.surge.sh/guide/'
55 );
56
57 process.exit(1);
58};