Skip to content

Commit bbb2c53

Browse files
committed
feat(download): externalize labels and constants to JSON file
Moved hardcoded OS, installation methods, and package manager labels from downloadUtils.tsx to a separate downloadConstants.json file for better maintainability. Updated the utility to import and use data from JSON without changing existing behavior. Fixes: nodejs#7561 Signed-off-by: vishal <vishalkumarvkvk988@gmail.com>
1 parent 479f73b commit bbb2c53

File tree

5 files changed

+7793
-2697
lines changed

5 files changed

+7793
-2697
lines changed

.pre-commit-config.yaml

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
repos:
2-
- repo: https://github.com/gitleaks/gitleaks
3-
rev: v8.16.3
4-
hooks:
5-
- id: gitleaks
6-
- repo: https://github.com/jumanjihouse/pre-commit-hooks
7-
rev: 3.0.0
8-
hooks:
9-
- id: shellcheck
10-
- repo: https://github.com/pre-commit/mirrors-eslint
11-
rev: v8.38.0
12-
hooks:
13-
- id: eslint
14-
- repo: https://github.com/pre-commit/pre-commit-hooks
15-
rev: v4.4.0
16-
hooks:
17-
- id: end-of-file-fixer
18-
- id: trailing-whitespace
2+
- repo: https://github.com/gitleaks/gitleaks
3+
rev: v8.16.3
4+
hooks:
5+
- id: gitleaks
6+
- repo: https://github.com/jumanjihouse/pre-commit-hooks
7+
rev: 3.0.0
8+
hooks:
9+
- id: shellcheck
10+
- repo: https://github.com/pre-commit/mirrors-eslint
11+
rev: v8.38.0
12+
hooks:
13+
- id: eslint
14+
- repo: https://github.com/pre-commit/pre-commit-hooks
15+
rev: v4.4.0
16+
hooks:
17+
- id: end-of-file-fixer
18+
- id: trailing-whitespace

apps/site/components/Downloads/Release/PrebuiltDownloadButtons.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ import type { FC } from 'react';
88

99
import Button from '#site/components/Common/Button';
1010
import { ReleaseContext } from '#site/providers/releaseProvider';
11-
import {
12-
OperatingSystemLabel,
13-
OS_NOT_SUPPORTING_INSTALLERS,
14-
} from '#site/util/downloadUtils';
11+
import { OS_NOT_SUPPORTING_INSTALLERS } from '#site/util/downloadUtils';
12+
import { OperatingSystemLabel } from '#site/util/downloadUtils';
1513
import { getNodeDownloadUrl } from '#site/util/getNodeDownloadUrl';
1614

1715
// Retrieves the pure extension piece from the input string

apps/site/util/downloadConstants.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"OperatingSystem": {
3+
"WIN": "Windows",
4+
"MAC": "macOS",
5+
"LINUX": "Linux",
6+
"AIX": "AIX",
7+
"OTHER": "Other",
8+
"LOADING": "N/A"
9+
},
10+
11+
"InstallationMethod": {
12+
"NVM": "nvm",
13+
"FNM": "fnm",
14+
"BREW": "Brew",
15+
"CHOCO": "Chocolatey",
16+
"DEVBOX": "Devbox",
17+
"DOCKER": "Docker",
18+
"N": "n",
19+
"VOLTA": "Volta"
20+
},
21+
"PackageManager": {
22+
"NPM": "npm",
23+
"YARN": "Yarn",
24+
"PNPM": "pnpm"
25+
},
26+
"UserPlatform": [
27+
"arm64",
28+
"armv7l",
29+
"ppc64le",
30+
"ppc64",
31+
"s390x",
32+
"ppc64",
33+
"x64",
34+
"x86"
35+
],
36+
37+
"UserOs": ["MAC", "WIN", "LINUX", "AIX", "OTHER"],
38+
"UserBitness": ["64", "32"],
39+
"UserArchitecture": ["arm", "x86"]
40+
}

apps/site/util/downloadUtils.tsx

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@ import type { NodeReleaseStatus } from '#site/types';
88
import type * as Types from '#site/types/release';
99
import type { UserOS, UserPlatform } from '#site/types/userOS';
1010

11-
// This is a manual list of OS's that do not support/have a way of being installed
11+
import downloadConstants from './downloadConstants.json';
12+
13+
const InstallationMethodLabel = downloadConstants.InstallationMethod;
14+
export const OperatingSystemLabel = downloadConstants.OperatingSystem;
15+
const PackageManagerLabel = downloadConstants.PackageManager;
16+
17+
// This is a manual list of OS's that do not sup
18+
// port/have a way of being installed
1219
// with an executable installer. This is used to disable the installer button.
1320
// Note: Windows has one tiny exception for x64 on Node.js versions < 4.0.0
1421
export const OS_NOT_SUPPORTING_INSTALLERS: Array<UserOS | 'LOADING'> = [
@@ -18,32 +25,6 @@ export const OS_NOT_SUPPORTING_INSTALLERS: Array<UserOS | 'LOADING'> = [
1825
'LOADING',
1926
];
2027

21-
export enum OperatingSystemLabel {
22-
WIN = 'Windows',
23-
MAC = 'macOS',
24-
LINUX = 'Linux',
25-
AIX = 'AIX',
26-
OTHER = 'Other',
27-
LOADING = 'N/A',
28-
}
29-
30-
export enum InstallationMethodLabel {
31-
NVM = 'nvm',
32-
FNM = 'fnm',
33-
BREW = 'Brew',
34-
CHOCO = 'Chocolatey',
35-
DEVBOX = 'Devbox',
36-
DOCKER = 'Docker',
37-
N = 'n',
38-
VOLTA = 'Volta',
39-
}
40-
41-
export enum PackageManagerLabel {
42-
NPM = 'npm',
43-
YARN = 'Yarn',
44-
PNPM = 'pnpm',
45-
}
46-
4728
type DownloadCompatibility = {
4829
os: Array<UserOS | 'LOADING'>;
4930
installMethod: Array<Types.InstallationMethod | ''>;
@@ -125,6 +106,7 @@ export const parseCompat = <
125106
}));
126107
};
127108

109+
// Here the list of Operating System Dropdown items are defined !
128110
export const OPERATING_SYSTEMS: Array<DownloadDropdownItem<UserOS>> = [
129111
{
130112
label: OperatingSystemLabel.WIN,
@@ -152,6 +134,8 @@ export const OPERATING_SYSTEMS: Array<DownloadDropdownItem<UserOS>> = [
152134
},
153135
];
154136

137+
// Here the list of Install Method Dropdown items are defined !
138+
155139
export const INSTALL_METHODS: Array<
156140
DownloadDropdownItem<Types.InstallationMethod> &
157141
// Since the ReleaseCodeBox requires an info key to be provided, we force this
@@ -229,6 +213,8 @@ export const INSTALL_METHODS: Array<
229213
},
230214
];
231215

216+
// Here the list of Package Manager Dropdown items are defined !
217+
232218
export const PACKAGE_MANAGERS: Array<
233219
DownloadDropdownItem<Types.PackageManager>
234220
> = [
@@ -252,6 +238,8 @@ export const PACKAGE_MANAGERS: Array<
252238
},
253239
];
254240

241+
// Here the list Platform and their specific specification items are defined !
242+
255243
export const PLATFORMS: Record<
256244
UserOS,
257245
Array<DownloadDropdownItem<UserPlatform>>

0 commit comments

Comments
 (0)