-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·84 lines (76 loc) · 2.27 KB
/
index.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env node
/**
* remove-console-statements
* Removes console.* statements from your code.
* @author Graham Nessler
*/
import handleError from 'cli-handle-error';
import init from './utils/init.js';
import cli from './utils/cli.js';
import log from './utils/log.js';
import listStatementsInChangedFiles from './core/listStatementsInChangedFiles.js';
import listStatementsInDiffs from './core/listStatementsInDiffs.js';
import removeStatementsFromFile from './core/removeStatementsFromFile.js';
import removeAllStatements from './core/removeAllStatements.js';
import hideAllStatements from './core/hideAllStatements.js';
const { input, flags } = cli;
const { debug, list, diff, file, bulk, hide } = flags;
(async () => {
init();
// show help if requested
input.includes('help') && cli.showHelp(0);
debug && log(flags);
if ((process.argv.includes('-f') || process.argv.includes('--file')) && !file)
handleError('You must enter a valid file path if using the --file flag.', {
message: 'You must enter a valid file path if using the --file flag.',
});
switch (true) {
case list:
try {
await listStatementsInChangedFiles();
} catch (error) {
handleError('Problem listing console statements in files', error);
}
break;
case diff:
try {
await listStatementsInDiffs();
} catch (error) {
handleError('Problem listing console statements in file diffs', error);
}
break;
case !!file:
try {
await removeStatementsFromFile(file);
} catch (error) {
handleError('Problem removing console statements from file', error);
}
break;
case bulk:
try {
await removeAllStatements();
} catch (error) {
handleError(
'Problem removing all console statements in file diffs',
error,
);
}
break;
case hide:
try {
await hideAllStatements();
} catch (error) {
handleError(
'Problem hiding all console statements in file diffs',
error,
);
}
break;
default:
try {
await listStatementsInChangedFiles();
} catch (error) {
handleError('Problem listing console statements in files', error);
}
}
})();