-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcheck-element-changes.js
58 lines (47 loc) · 1.66 KB
/
check-element-changes.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
const exec = require("child_process").exec;
const path = require("path");
//=====================================================
// console log helpers
//=====================================================
const FgBlue = "\x1b[34m";
const FgGreen = "\x1b[32m";
const printLine = () => console.log(FgBlue, "-".repeat(84));
const printTitle = (text = "") => {
console.log(FgGreen, `${text + " ".repeat(84 - text.length)}`);
};
//=====================================================
// Process files
//=====================================================
const args = process.argv.slice(2);
const daysAgo = args[1];
const runGit = function (command, cb) {
var child = exec(command, function (err, stdout, stderr) {
if (err != null) {
return cb(new Error(err), null);
} else if (typeof stderr != "string") {
return cb(new Error(stderr), null);
} else {
return cb(stdout);
}
});
};
const parseDateForGIT = () => {
const d = new Date();
d.setDate(d.getDate() - daysAgo);
return d.getMonth() + 1 + "/" + d.getDate() + "/" + d.getFullYear();
};
const GIT_COMMAND = `git whatchanged --since '${parseDateForGIT()}' --oneline --name-only --pretty=format: | sort | uniq`;
console.log(`Run GIT command '${GIT_COMMAND}'`);
runGit(GIT_COMMAND, (res = "") => {
const fileTemplates = res
.split(/\r\n|\r|\n/)
.filter(elm => elm.match(/.*\.(templates?)/gi));
printLine();
fileTemplates.forEach(filePath => {
const fileName = path.parse(filePath).name;
const packageName = filePath.split(path.sep)[1];
printTitle(`${packageName}: ${fileName}`);
printLine();
});
});
//=====================================================