Repository navigation
Expand file tree
/
Copy pathmain.ts
More file actions
46 lines (39 loc) · 1.39 KB
/
Copy pathmain.ts
File metadata and controls
46 lines (39 loc) · 1.39 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
import * as cli from './cli.js';
import { parseArgv } from './configuration.js';
import * as log from './logger.js';
import * as utils from './utils.js';
import * as yargs from './yargs.js';
export async function main(): Promise<void> {
try {
const argv = await yargs.setup();
const [diff2htmlOptions, configuration] = parseArgv(argv);
const input = await cli.getInput(configuration.inputSource, argv.extraArguments, configuration.ignore);
if (!input && !diff2htmlOptions.renderNothingWhenEmpty) {
process.exitCode = 3;
log.error('The input is empty. Try again.');
return;
}
if (configuration.diffyType !== undefined) {
await cli.postToDiffy(input, configuration.diffyType);
return;
}
const output = cli.getOutput(diff2htmlOptions, configuration, input);
if (configuration.outputDestinationFile) {
utils.writeFile(configuration.outputDestinationFile, output);
} else {
switch (configuration.outputDestinationType) {
case 'preview':
return cli.preview(output, configuration.formatType);
case 'stdout':
return log.print(output);
}
}
} catch (error) {
if (process.exitCode === undefined || process.exitCode === 0) {
process.exitCode = 1;
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const anyError = error as any;
log.error(anyError);
}
}