-
Notifications
You must be signed in to change notification settings - Fork 4
/
log.js
61 lines (49 loc) 路 1.82 KB
/
log.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
#!/usr/bin/env node
(function () {
'use strict';
var childProcess = require('child_process'),
configParser = require('turbo-git-config').parser,
utils = require('turbo-git-config').utils,
colors = require('colors/safe'),
gitLogTitles;
(function executePreGitLog() {
var gitLogCommand = "git --no-pager log --pretty='%s' -n100";
childProcess.exec(gitLogCommand, executeGitPreLogCallback);
})();
function executeGitPreLogCallback(err, gitTitles) {
var gitLogUserCommand;
if (err) { utils.showError(err); return; }
gitLogTitles = gitTitles;
gitLogUserCommand = configParser.getLogCommand();
childProcess.exec(gitLogUserCommand, executeGitLogCallback);
}
function executeGitLogCallback(err, gitLogFull) {
if (err) {
utils.showError(err);
return;
}
parseLog(gitLogFull, gitLogTitles);
}
function escapeSpecialCharactersRegex(text) {
return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
}
function parseLog(gitLogFull, gitLogTitles) {
var commitConf = configParser.getCommitConf();
function getRegex(tag) {
return new RegExp(escapeSpecialCharactersRegex(tag) + '.*$', 'mg');
}
function getRegexMatch(gitLog, regex) {
return gitLog.match(regex);
}
commitConf.forEach(function (prop) {
var ArrayCommitsType = getRegexMatch(gitLogTitles, getRegex(prop.tag)) || [];
ArrayCommitsType.forEach(function (commitMsg) {
gitLogFull = gitLogFull.replace(getRegex(commitMsg), colors[prop.color](commitMsg));
});
});
printColorLog(gitLogFull);
}
function printColorLog (gitParsedLog) {
console.log(gitParsedLog);
}
}());