Skip to content

Commit a533c13

Browse files
committed
add ability to skip debug-level logs
1 parent 1d1627f commit a533c13

File tree

5 files changed

+37
-6
lines changed

5 files changed

+37
-6
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
.idea
12
node_modules
23
coverage

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22

33
Module to collect data from a git repository.
44

5+
## How to run:
6+
7+
```
8+
SOURCE_DIR=<PATH TO LOCAL GIT REPO> npm run run-dev
9+
```
10+
11+
Set `NODE_ENV=production` if you want to skip debug-level logs:
12+
13+
```
14+
SOURCE_DIR=<PATH TO LOCAL GIT REPO> NODE_ENV=production npm run run-dev
15+
```
16+
517
## Collected data:
618

719
### The most changed files

src/git-reader/git-repository.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fs from "fs";
22
import git from "isomorphic-git";
33
import { Readable } from "stream";
44

5-
import { log, time, timeLog } from "../index.js";
5+
import { debug, log, time, timeLog } from "../index.js";
66
import { ChangedFile, Commit, ExpandedCommit } from "../interfaces.js";
77

88
interface GitReadOptions {
@@ -39,7 +39,7 @@ export class GitRepository {
3939
continue;
4040
}
4141

42-
log("Getting files diff between two commits", {
42+
debug("Getting files diff between two commits", {
4343
progress: `${i} of ${commits.length}`,
4444
commitDate: new Date(c.commit.author.timestamp * 1000).toISOString(),
4545
});

src/index.ts

+19-4
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,26 @@ export function log(arg1: string, arg2: object) {
1212
// eslint-disable-next-line no-console
1313
console.log(arg1, arg2);
1414
}
15+
export function debug(arg1: string, arg2: object) {
16+
if (process.env.NODE_ENV !== "production") {
17+
// eslint-disable-next-line no-console
18+
console.debug(arg1, arg2);
19+
}
20+
}
1521
export function time(timerName: string) {
1622
// eslint-disable-next-line no-console
1723
console.time(timerName);
1824
}
1925
export function timeLog(timerName: string) {
26+
if (process.env.NODE_ENV !== "production") {
27+
// eslint-disable-next-line no-console
28+
console.timeLog(timerName);
29+
}
30+
}
31+
function clearConsole() {
32+
process.stdout.write("\u001b[3J\u001b[2J\u001b[1J");
2033
// eslint-disable-next-line no-console
21-
console.timeLog(timerName);
34+
console.clear();
2235
}
2336

2437
async function collectCommitsByAuthor(repo: GitRepository) {
@@ -67,7 +80,7 @@ async function main() {
6780
}
6881

6982
const repo = new GitRepository(dir);
70-
log("Getting a list of changed files", { dir });
83+
debug("Getting a list of changed files", { dir });
7184
const commitsStream = new Readable({
7285
objectMode: true,
7386
read() {
@@ -88,9 +101,11 @@ async function main() {
88101
intermediateAggregateMonthly.addCommit(commit);
89102
intermediateAggregateQuarterly.addCommit(commit);
90103

91-
log("monthly data: ", intermediateAggregateMonthly.getData());
104+
clearConsole();
105+
106+
// log("monthly data: ", intermediateAggregateMonthly.getData());
92107
log("quarterly data: ", {
93-
data: JSON.stringify(intermediateAggregateQuarterly.getData()),
108+
data: JSON.stringify(intermediateAggregateQuarterly.displayReport()),
94109
});
95110
});
96111
commitsStream.on("end", () => {

src/stats/aggregate/aggregate.ts

+3
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,7 @@ export abstract class Aggregate<T> {
8181
public getValue(filePath: FilePath, aggregateKey: AggregateKey): T {
8282
return this.files[filePath][aggregateKey];
8383
}
84+
public displayReport(): string {
85+
return "TODO: report will be here";
86+
}
8487
}

0 commit comments

Comments
 (0)