|
13 | 13 | - [Best practices when creating a Component](#best-practices-when-creating-a-component)
|
14 | 14 | - [How a new Component should look like when freshly created](#how-a-new-component-should-look-like-when-freshly-created)
|
15 | 15 | - [Best practices for Component development in general](#best-practices-for-component-development-in-general)
|
| 16 | +- [The new Downloads page](#the-new-downloads-page) |
| 17 | + - [Adding a Download Installation Method](#adding-a-download-installation-method) |
| 18 | + - [Adding a Download Package Manager](#adding-a-download-package-manager) |
16 | 19 | - [Unit Tests and Storybooks](#unit-tests-and-storybooks)
|
17 | 20 | - [General Guidelines for Unit Tests](#general-guidelines-for-unit-tests)
|
18 | 21 | - [General Guidelines for Storybooks](#general-guidelines-for-storybooks)
|
@@ -259,6 +262,117 @@ export default MyComponent;
|
259 | 262 | Use utilities or Hooks when you need a Reactive state
|
260 | 263 | - Avoid making your Component too big. Deconstruct it into smaller Components/Hooks whenever possible
|
261 | 264 |
|
| 265 | +## The new Downloads page |
| 266 | + |
| 267 | +### Adding a Download Installation Method |
| 268 | + |
| 269 | +To add a new download installation method, follow these steps: |
| 270 | + |
| 271 | +1. **Update `INSTALL_METHODS` in `apps/site/util/downloadUtils.tsx`:** |
| 272 | + |
| 273 | + - Add a new entry to the `INSTALL_METHODS` array. |
| 274 | + - Each entry should have the following properties: |
| 275 | + - `iconImage`: The React component of the icon image for the installation method. This should be an SVG component stored within `apps/site/components/Icons/InstallationMethod` and must follow the other icon component references (being a `FC` supporting `SVGSVGElement` props). |
| 276 | + - Don't forget to add it on the `index.tsx` file from the `InstallationMethod` folder. |
| 277 | + - `recommended`: A boolean indicating if this method is recommended. This property is available only for official installation methods. |
| 278 | + - `url`: The URL for the installation method. |
| 279 | + - `value`: The key of the installation method, which must be unique. |
| 280 | + |
| 281 | + Example: |
| 282 | + |
| 283 | + ```javascript |
| 284 | + // filepath: /nodejs.org/apps/site/util/downloadUtils.tsx |
| 285 | + // See full reference of INSTALL_METHODS within `downloadUtils.tsx` |
| 286 | + export const INSTALL_METHODS = [ |
| 287 | + // ...existing methods... |
| 288 | + { |
| 289 | + iconImage: <InstallMethodIcons.YourIconImage width={16} height={16} />, |
| 290 | + url: 'https://example.com/install', |
| 291 | + value: 'exampleMethod', |
| 292 | + }, |
| 293 | + ]; |
| 294 | + ``` |
| 295 | + |
| 296 | +2. **Add translation key in `packages/i18n/locales/en.json`:** |
| 297 | + |
| 298 | + - Add an entry under `layouts.download.codeBox.platformInfo` for the `info` property of the new installation method. |
| 299 | + |
| 300 | + Example: |
| 301 | + |
| 302 | + ```json |
| 303 | + // filepath: /nodejs.org/packages/i18n/locales/en.json |
| 304 | + { |
| 305 | + "layouts": { |
| 306 | + "download": { |
| 307 | + "codeBox": { |
| 308 | + "platformInfo": { |
| 309 | + "exampleMethod": "Example installation method description." |
| 310 | + } |
| 311 | + } |
| 312 | + } |
| 313 | + } |
| 314 | + } |
| 315 | + ``` |
| 316 | + |
| 317 | +3. **Update `InstallationMethodLabel` and `InstallationMethod` in `@/types/release.ts`:** |
| 318 | + |
| 319 | + - Add the new method to the `InstallationMethodLabel` and `InstallationMethod` types. |
| 320 | + |
| 321 | + Example: |
| 322 | + |
| 323 | + ```typescript |
| 324 | + // filepath: /nodejs.org/apps/site/types/release.ts |
| 325 | + export type InstallationMethod = 'exampleMethod' | 'anotherMethod' | ...; |
| 326 | + |
| 327 | + export const InstallationMethodLabel: Record<InstallationMethod, string> = { |
| 328 | + exampleMethod: 'Example Method', |
| 329 | + anotherMethod: 'Another Method', |
| 330 | + // ...existing methods... |
| 331 | + }; |
| 332 | + ``` |
| 333 | + |
| 334 | +4. **Add a snippet in `apps/site/snippets/en/download`:** |
| 335 | + |
| 336 | + - Create a new file with the same key as the `value` property (e.g., `exampleMethod.bash`). |
| 337 | + - Add the installation instructions in this file. |
| 338 | + - The snippet file can use JavaScript template syntax and has access to a `props` variable of type `ReleaseContextType`. |
| 339 | + |
| 340 | + Example: |
| 341 | + |
| 342 | + ```bash |
| 343 | + // filepath: /nodejs.org/apps/site/snippets/en/download/exampleMethod.bash |
| 344 | + echo "Installing Node.js version ${props.version} using Example Method" |
| 345 | + ``` |
| 346 | + |
| 347 | +5. **Configure `compatibility` within the `INSTALL_METHODS` object in `downloadUtils.ts`:** |
| 348 | + |
| 349 | +- Use the `compatibility` property to enable/list the installation method for specific OSs, Node.js version ranges, or architectures/platforms. |
| 350 | + |
| 351 | +Example: |
| 352 | + |
| 353 | +```javascript |
| 354 | +// filepath: /nodejs.org/apps/site/util/downloadUtils.tsx |
| 355 | +// See full reference of compatibility property within `downloadUtils.tsx` |
| 356 | +export const INSTALL_METHODS = [ |
| 357 | + { |
| 358 | + iconImage: 'path/to/icon.svg', |
| 359 | + url: 'https://example.com/install', |
| 360 | + value: 'exampleMethod', |
| 361 | + compatibility: { |
| 362 | + os: ['LINUX', 'MAC'], |
| 363 | + semver: ['>=14.0.0'], |
| 364 | + platform: ['x64', 'arm64'], |
| 365 | + }, |
| 366 | + }, |
| 367 | +]; |
| 368 | +``` |
| 369 | + |
| 370 | +By following these steps, you can successfully add a new download installation method to the Node.js website. |
| 371 | + |
| 372 | +### Adding a Download Package Manager |
| 373 | + |
| 374 | +You can add a PACKAGE_MANAGER the same way as adding an INSTALLATION_METHOD (from the section above, "Adding a Download Installation Method") but it should be added to the PACKAGE_MANAGERS object in `apps/site/util/downloadUtils.tsx`. |
| 375 | + |
262 | 376 | ## Unit Tests and Storybooks
|
263 | 377 |
|
264 | 378 | Each new feature or bug fix should be accompanied by a unit test (when deemed valuable).
|
|
0 commit comments