The Node.js® Website
at main 3.9 kB view raw
1import dedent from 'dedent'; 2 3import type { NodeRelease } from '@/types'; 4import type { PackageManager } from '@/types/release'; 5import type { UserOS } from '@/types/userOS'; 6 7export const getNodeDownloadSnippet = (release: NodeRelease, os: UserOS) => { 8 const snippets: Record<PackageManager, string> = { 9 NVM: '', 10 BREW: '', 11 DOCKER: '', 12 CHOCO: '', 13 }; 14 15 if (os === 'LINUX' || os === 'MAC') { 16 snippets.NVM = dedent` 17 # installs NVM (Node Version Manager) 18 curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash 19 20 # download and install Node.js 21 nvm install ${release.major} 22 23 # verifies the right Node.js version is in the environment 24 node -v # should print \`${release.versionWithPrefix}\` 25 26 # verifies the right NPM version is in the environment 27 npm -v # should print \`${release.npm}\``; 28 29 snippets.BREW = dedent` 30 # download and installs Homebrew (macOS/Linux Package Manager) 31 curl -o- https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh | bash 32 33 # download and install Node.js 34 brew install node@${release.major} 35 36 # verifies the right Node.js version is in the environment 37 node -v # should print \`${release.versionWithPrefix}\` 38 39 # verifies the right NPM version is in the environment 40 npm -v # should print \`${release.npm}\``; 41 } 42 43 if (os === 'MAC') { 44 snippets.DOCKER = dedent` 45 # installs Homebrew (macOS/Linux Package Manager) 46 curl -o- https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh | bash 47 48 # installs Docker Desktop 49 brew install docker --cask 50 51 # pulls the Node.js Docker image 52 docker pull node:${release.major}-${release.major >= 4 ? 'alpine' : 'slim'} 53 54 # verifies the right Node.js version is in the environment 55 docker run node:${release.major}-${release.major >= 4 ? 'alpine' : 'slim'} node -v # should print \`${release.versionWithPrefix}\` 56 57 # verifies the right NPM version is in the environment 58 docker run node:${release.major}-${release.major >= 4 ? 'alpine' : 'slim'} npm -v # should print \`${release.npm}\``; 59 } 60 61 if (os === 'WIN') { 62 snippets.CHOCO = dedent` 63 # installs Chocolatey (Windows Package Manager) 64 Set-ExecutionPolicy Bypass -Scope Process -Force; 65 [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; 66 iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')); 67 68 # download and install Node.js 69 choco install nodejs --version="${release.version}" 70 71 # verifies the right Node.js version is in the environment 72 node -v # should print \`${release.versionWithPrefix}\` 73 74 # verifies the right NPM version is in the environment 75 npm -v # should print \`${release.npm}\``; 76 77 snippets.DOCKER = dedent` 78 # installs Chocolatey (Windows Package Manager) 79 Set-ExecutionPolicy Bypass -Scope Process -Force; 80 [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; 81 iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')); 82 83 # installs Docker Desktop 84 choco install docker-desktop 85 86 # pulls the Node.js Docker image 87 docker pull node:${release.major}-${release.major >= 4 ? 'alpine' : 'slim'} 88 89 # verifies the right Node.js version is in the environment 90 docker run node:${release.major}-${release.major >= 4 ? 'alpine' : 'slim'} node -v # should print \`${release.versionWithPrefix}\` 91 92 # verifies the right NPM version is in the environment 93 docker run node:${release.major}-${release.major >= 4 ? 'alpine' : 'slim'} npm -v # should print \`${release.npm}\``; 94 } 95 96 return snippets; 97};