-
Notifications
You must be signed in to change notification settings - Fork 382
/
Copy pathreleaseNotes.js
106 lines (89 loc) · 3.13 KB
/
releaseNotes.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/**
* Copyright (c) Moodle Pty Ltd.
*
* Moodle is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Moodle is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Moodle. If not, see <http://www.gnu.org/licenses/>.
*/
const { existsSync } = require('fs');
const path = require('path');
/** @type {import('@docusaurus/plugin-content-docs').SidebarsConfig} */
/** @type {import('@docusaurus/plugin-content-docs/src/sidebars/types').NormalizedSidebarItem} */
/** @type import('@site/src/utils/SupportedReleases') */
// TODO: This should _ideally_ use the @site/src/utils/SupportedReleases.ts library, but need to solve the inclusion of TS from Docusaurus config files.
const VersionData = require('../data/versions.json');
const Versions = Array(...VersionData.versions);
const today = new Date();
const isSupported = (versionData) => {
if (versionData.extendedSecurityEndDate) {
return (new Date(versionData.extendedSecurityEndDate)) > today;
}
return (new Date(versionData.securityEndDate)) > today;
};
const getTitle = (versionData) => {
if (versionData.isLTS) {
return `Moodle ${versionData.name} (LTS)`;
}
return `Moodle ${versionData.name}`;
};
const getReleaseEntry = (versionData) => ({
label: getTitle(versionData),
type: 'category',
items: [],
link: {
type: 'doc',
id: `releases/${versionData.name}`,
},
});
module.exports = function getReleaseNotes() {
const activeVersions = [];
const archivedVersions = [];
Versions.forEach((versionData) => {
if (!existsSync(path.resolve(__dirname, '..', 'general', 'releases', versionData.name))) {
if (!existsSync(path.resolve(__dirname, '..', 'general', 'releases', `${versionData.name}.md`))) {
return;
}
}
if (versionData.isExperimental) {
return;
}
const entry = getReleaseEntry(versionData);
if (existsSync(path.resolve(__dirname, '..', 'general', 'releases', versionData.name))) {
entry.items.push({
type: 'autogenerated',
dirName: path.join('releases', versionData.name),
});
}
if (isSupported(versionData)) {
activeVersions.push(entry);
} else {
archivedVersions.push(entry);
}
});
const releaseNotes = {
label: 'Releases',
type: 'category',
items: [
...activeVersions,
{
label: 'Archive',
type: 'category',
items: archivedVersions,
},
],
link: {
type: 'doc',
id: 'releases',
},
};
return releaseNotes;
};