forked from angular/components
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-versions-file.mts
64 lines (53 loc) · 2.03 KB
/
update-versions-file.mts
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
import * as fs from 'fs';
import * as path from 'path';
import {
ActiveReleaseTrains,
assertValidReleaseConfig,
fetchLongTermSupportBranchesFromNpm,
getConfig,
} from '@angular/ng-dev';
import {sites} from './utils.mjs';
interface VersionEntry {
url: string;
title: string;
}
type VersionList = VersionEntry[];
/** Path to the `versions.json` file in the docs-app. */
const relativeVersionFilePath = 'docs/src/assets/versions.json';
/**
* List of hard-coded major versions which have an archived docs-site,
* but their major is not detectable as active/inactive LTS due to these
* majors being released with the old release tool (not tagging LTS majors).
*/
// TODO: This can be removed at some point in the future if we feel like nobody
// needing these doc-site archives.
const hardcodedOldMajorsWithoutLtsTag = [5, 6, 7, 8, 9, 10, 11];
/**
* Updates the versions list file in the specified docs repo to reflect
* the current active release trains and archived LTS versions.
*/
export async function updateVersionsFile(workspaceDir: string, active: ActiveReleaseTrains) {
const versionFilePath = path.join(workspaceDir, relativeVersionFilePath);
const {release} = await getConfig([assertValidReleaseConfig]);
const ltsBranches = await fetchLongTermSupportBranchesFromNpm(release);
const versions: VersionList = [
{url: sites.next.remoteUrl, title: 'Next'},
{url: sites.rc.remoteUrl, title: 'Release Candidate'},
{url: sites.stable.remoteUrl, title: `${active.latest.version.format()} (latest)`},
];
const archivedMajors = new Set(
[...ltsBranches.active, ...ltsBranches.inactive]
.map(e => e.version.major)
.concat(hardcodedOldMajorsWithoutLtsTag),
);
// Insert archived majors in descending order (i.e. starting with newer ones).
Array.from(archivedMajors)
.sort((a, b) => b - a)
.forEach(major =>
versions.push({
title: `v${major}`,
url: sites.forMajor(major).remoteUrl,
}),
);
await fs.promises.writeFile(versionFilePath, JSON.stringify(versions, null, 2));
}