-
Notifications
You must be signed in to change notification settings - Fork 114
/
deploy-helper.js
57 lines (44 loc) · 1.96 KB
/
deploy-helper.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
let getCompilationQuarterValue = function (d, strict, includePrevious) {
d = d || new Date();
let quarterIndex = (Math.ceil((d.getMonth() + 1) / 3)),
nextQuarter = (quarterIndex <= 3) ? d.getFullYear() + "-0" + (quarterIndex + 1) : (d.getFullYear() + 1) + "-01";
let ret = `+(${includePrevious ? getPreviousQuarter() + "|" : ''}${d.getFullYear()}-0${quarterIndex}|${nextQuarter})`;
if (!strict) {
ret = `${ret}*`
}
return ret
};
let getCurrentQuarter = function () {
let d = new Date();
let quarterIndex = (Math.ceil((d.getMonth() + 1) / 3));
return `${d.getFullYear()}-0${quarterIndex}`;
};
let getCurrentQuarterWithOffset = function (offset) {
let d = new Date();
d.setDate(d.getDate() + offset);
let quarterIndex = (Math.ceil((d.getMonth() + 1) / 3));
return `${d.getFullYear()}-0${quarterIndex}`;
};
let getNextQuarter = function () {
let d = new Date();
let quarterIndex = (Math.ceil((d.getMonth() + 1) / 3));
let nextQuarter = (quarterIndex <= 3) ? d.getFullYear() + "-0" + (quarterIndex + 1) : (d.getFullYear() + 1) + "-01";
return `${nextQuarter}`;
};
let getPreviousQuarter = function () {
let d = new Date();
let quarterIndex = (Math.ceil((d.getMonth() + 1) / 3));
let prevQuarter = (quarterIndex === 1) ? (d.getFullYear() - 1) + "-04" : (d.getFullYear()) + `-0${(quarterIndex - 1)}`;
return `${prevQuarter}`;
};
let getInfoFromPath = function (path) {
let infoRegExp = /src\/([a-z]{2,3})?\/?([a-z0-9-]{6,})?\/?([0-9a-z\-]{2,})?\/?([a-z0-9-]{2,}(\.md)?)?\/?/g,
matches = infoRegExp.exec(path),
info = {};
info.language = matches[1] || null;
info.quarterly = matches[2] || null;
info.lesson = matches[3] || null;
info.day = (matches[4]) ? matches[4].replace(".md", "") : null;
return info;
};
module.exports = { getCompilationQuarterValue, getCurrentQuarter, getNextQuarter, getPreviousQuarter, getInfoFromPath, getCurrentQuarterWithOffset }