Skip to content

Commit 242b43e

Browse files
committed
refactor: separate down getCompatiblePlatforms function
1 parent 6c023cb commit 242b43e

1 file changed

Lines changed: 61 additions & 24 deletions

File tree

apps/site/util/download/archive.tsx

Lines changed: 61 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,44 @@ type CompatibleArtifactOptions = {
4343
};
4444

4545
/**
46-
* Returns a list of compatible artifacts for the given options.
46+
* Creates a download artifact from platform data
4747
*/
48-
const getCompatibleArtifacts = ({
49-
platforms = PLATFORMS,
50-
exclude = [],
51-
versionWithPrefix,
52-
kind = 'binary',
53-
}: CompatibleArtifactOptions): Array<DownloadArtifact> => {
48+
const createDownloadArtifact = (
49+
os: OperatingSystem,
50+
platform: DownloadDropdownItem<Platform>,
51+
versionWithPrefix: string,
52+
kind: DownloadKind
53+
): DownloadArtifact => {
54+
const url = getNodeDownloadUrl({
55+
versionWithPrefix: versionWithPrefix,
56+
os: os,
57+
platform: platform.value,
58+
kind: kind,
59+
});
60+
61+
return {
62+
fileName: url.replace(`${DIST_URL}${versionWithPrefix}/`, ''),
63+
kind: kind,
64+
os: os,
65+
architecture: platform.label,
66+
url: url,
67+
version: versionWithPrefix,
68+
};
69+
};
70+
71+
type CompatiblePlatforms = Array<{
72+
os: OperatingSystem;
73+
platform: DownloadDropdownItem<Platform>;
74+
}>;
75+
76+
/**
77+
* Filters platforms by compatibility and exclusions
78+
*/
79+
const getCompatiblePlatforms = (
80+
platforms: Record<OperatingSystem, Array<DownloadDropdownItem<Platform>>>,
81+
exclude: Array<string>,
82+
versionWithPrefix: string
83+
): CompatiblePlatforms => {
5484
return Object.entries(platforms).flatMap(([os, items]) => {
5585
if (exclude.includes(os)) return [];
5686

@@ -63,26 +93,33 @@ const getCompatibleArtifacts = ({
6393
versionWithPrefix
6494
)
6595
)
66-
.map(({ value, label }) => {
67-
const url = getNodeDownloadUrl({
68-
versionWithPrefix: versionWithPrefix,
69-
os: os as OperatingSystem,
70-
platform: value,
71-
kind: kind,
72-
});
73-
74-
return {
75-
fileName: url.replace(`${DIST_URL}${versionWithPrefix}/`, ''),
76-
kind: kind,
77-
os: os as OperatingSystem,
78-
architecture: label,
79-
url: url,
80-
version: versionWithPrefix,
81-
};
82-
});
96+
.map(platform => ({
97+
os: os as OperatingSystem,
98+
platform: platform,
99+
}));
83100
});
84101
};
85102

103+
/**
104+
* Returns a list of compatible artifacts for the given options.
105+
*/
106+
const getCompatibleArtifacts = ({
107+
platforms = PLATFORMS,
108+
exclude = [],
109+
versionWithPrefix,
110+
kind = 'binary',
111+
}: CompatibleArtifactOptions): Array<DownloadArtifact> => {
112+
const compatiblePlatforms = getCompatiblePlatforms(
113+
platforms,
114+
exclude,
115+
versionWithPrefix
116+
);
117+
118+
return compatiblePlatforms.map(({ os, platform }) =>
119+
createDownloadArtifact(os, platform, versionWithPrefix, kind)
120+
);
121+
};
122+
86123
/**
87124
* Builds the release artifacts for a given Node.js release and version.
88125
* It retrieves binaries, installers, and source files based on the version.

0 commit comments

Comments
 (0)