-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
executable file
·61 lines (50 loc) · 1.39 KB
/
index.ts
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
import path from "path";
import fse from "fs-extra";
import sloc from "sloc";
import { analyze } from "./analyze.js";
import { generateReport } from "./generateReport.js";
import * as cache from "./cache.js";
import { InterruptError, UncleanGitWorkingTreeError } from "./errors.js";
import chalk from "chalk";
export * from "./errors.js";
export { generateReport, analyze };
export interface Options {
output: string;
path: string;
start: string;
end: string;
clean?: boolean;
dark?: boolean;
ignore?: string[];
}
export type SlocData = Record<sloc.Key, number>;
export interface Stat {
date: string;
stats: Stats;
}
export interface Stats {
js: SlocData;
ts: SlocData;
}
export default async function run(options: Options) {
const jsonPath = path.resolve(options.output, "data.json");
if (options.clean) fse.removeSync(jsonPath);
const existingStats = await cache.readData(options);
try {
const statsPerDay = await analyze(existingStats, options);
await generateReport(statsPerDay, options);
} catch (e) {
if (e instanceof UncleanGitWorkingTreeError) {
console.log(
chalk.red(
"Repo is not clean! Please cleanup your work before proceeding (`git status`)."
)
);
return;
}
// exit silently, just needed to wait for things to cleanup
if (e instanceof InterruptError) return;
// unknown error
throw e;
}
}