/
index.js
72 lines (60 loc) · 2.31 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
#!/usr/bin/env node
const prompts = require('prompts');
const fs = require('fs');
const {
checkIfDirectoryExistsAndCreateIfNeeded,
getFirstDayOfMonth,
getLastDayOfMonth,
isDirectoryExist,
isDirectoryChecker,
returnMonthFolderName,
runCommandOnPath,
saveFileWithContent,
} = require('./utils/utils.js');
const questions = require('./utils/questions.js');
(async () => {
const response = await prompts(questions);
const {
dateOfReport,
gitAuthorName,
projectFolderPath,
gitReportFolderPath,
} = response;
const gitReportFolderName = returnMonthFolderName(dateOfReport);
if (!fs.existsSync(projectFolderPath)) {
console.error('Passed projects folder path does not exists.');
return 0;
}
const listOfProjects = fs.readdirSync(projectFolderPath);
if (listOfProjects.length === 0) {
console.error('Projects folder is empty. Try to use different projects path.');
return;
}
checkIfDirectoryExistsAndCreateIfNeeded(gitReportFolderPath);
checkIfDirectoryExistsAndCreateIfNeeded(gitReportFolderPath + "/" + gitReportFolderName);
const afterDate = getFirstDayOfMonth(dateOfReport);
const beforeDate = getLastDayOfMonth(dateOfReport);
const gitLogBashCommand = `git log --reverse --all --after=${afterDate} --before=${beforeDate} --author="${gitAuthorName}" -p`;
listOfProjects.forEach(async (file) => {
const fullFilePath = `${projectFolderPath}/${file}`;
const isDirectory = await isDirectoryChecker(fullFilePath);
if (isDirectory) {
if (!isDirectoryExist(`${fullFilePath}/.git`)) {
console.log(`Not checking: ${fullFilePath} - .git folder does not exists!`);
return 0;
}
console.log(`Checking: ${fullFilePath}`);
runCommandOnPath(gitLogBashCommand, fullFilePath)
.then((resultOfCommand) => {
saveFileWithContent(
`${gitReportFolderPath + "/" + gitReportFolderName}/${file}.txt`,
resultOfCommand
);
})
.catch((err) => {
console.log('ERROR IN: ', fullFilePath);
throw new Error(err);
});
}
});
})();