-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathindex.ts
More file actions
40 lines (37 loc) · 1.4 KB
/
index.ts
File metadata and controls
40 lines (37 loc) · 1.4 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
import chalk from 'chalk';
import { exec } from 'child_process';
import * as process from 'process';
import terminalSize from 'terminal-size';
import * as util from 'util';
import { getContextForConfig } from './context';
import { getGitConfig } from './getGitConfig';
import { transformContentsStreaming } from './transformContentsStreaming';
import { getConfig } from './getConfig';
const execAsync = util.promisify(exec);
async function main() {
const { stdout: gitConfigString } = await execAsync('git config -l');
const gitConfig = getGitConfig(gitConfigString);
const config = getConfig(gitConfig);
const context = await getContextForConfig(
config,
chalk,
terminalSize().columns
);
await transformContentsStreaming(context, process.stdin, process.stdout);
// Ensure stdout is fully flushed before exiting
// This is critical when piping to `less` - if we exit before stdout is drained,
// less may not receive all data or may receive it in a broken state
if (process.stdout.writableNeedDrain) {
await new Promise<void>((resolve) => {
process.stdout.once('drain', resolve);
});
}
}
main().catch((err) => {
// Don't print errors if stdout pipe was closed (EPIPE)
// This happens when less quits before we finish processing
if (err.code !== 'EPIPE') {
console.error(err);
process.exit(1);
}
});