-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Expand file tree
/
Copy pathgetNodeDownloadSnippet.ts
More file actions
110 lines (83 loc) · 4.07 KB
/
getNodeDownloadSnippet.ts
File metadata and controls
110 lines (83 loc) · 4.07 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import dedent from 'dedent';
import type { NodeRelease } from '@/types';
import type { PackageManager } from '@/types/release';
import type { UserOS } from '@/types/userOS';
// @TODO: These snippets should be extracted to i18n (?)
export const getNodeDownloadSnippet = (release: NodeRelease, os: UserOS) => {
const snippets: Record<PackageManager, string> = {
NVM: '',
FNM: '',
BREW: '',
DOCKER: '',
CHOCO: '',
};
if (os === 'WIN' || os === 'MAC' || os === 'LINUX') {
snippets.DOCKER = dedent`
# NOTE:
# Docker is not a Node.js package manager. Please ensure it is already installed
# on your system. Follow official instructions at https://docs.docker.com/desktop/
# Docker images are provided officially at https://github.com/nodejs/docker-node/
# pulls the Node.js Docker image
docker pull node:${release.major}-${release.major >= 4 ? 'alpine' : 'slim'}
# verifies the right Node.js version is in the environment
docker run node:${release.major}-${release.major >= 4 ? 'alpine' : 'slim'} node -v # should print \`${release.versionWithPrefix}\`
# verifies the right NPM version is in the environment
docker run node:${release.major}-${release.major >= 4 ? 'alpine' : 'slim'} npm -v # should print \`${release.npm}\``;
}
if (os === 'MAC' || os === 'LINUX') {
snippets.NVM = dedent`
# installs NVM (Node Version Manager)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
# download and install Node.js
nvm install ${release.major}
# verifies the right Node.js version is in the environment
node -v # should print \`${release.versionWithPrefix}\`
# verifies the right NPM version is in the environment
npm -v # should print \`${release.npm}\``;
snippets.FNM = dedent`
# installs fnm (Fast Node Manager)
curl -fsSL https://fnm.vercel.app/install | bash
# download and install Node.js
fnm use --install-if-missing ${release.major}
# verifies the right Node.js version is in the environment
node -v # should print \`${release.versionWithPrefix}\`
# verifies the right NPM version is in the environment
npm -v # should print \`${release.npm}\``;
snippets.BREW = dedent`
# NOTE:
# Homebrew is not a Node.js package manager. Please ensure it is already installed
# on your system. Follow official instructions at https://brew.sh/
# Homebrew only supports installing major Node.js versions and might not support
# the latest Node.js version from the ${release.major} release line.
# download and install Node.js
brew install node@${release.major}
# verifies the right Node.js version is in the environment
node -v # should print \`${release.versionWithPrefix}\`
# verifies the right NPM version is in the environment
npm -v # should print \`${release.npm}\``;
}
if (os === 'WIN') {
snippets.FNM = dedent`
# installs fnm (Fast Node Manager)
winget install Schniz.fnm
# download and install Node.js
fnm use --install-if-missing ${release.major}
# verifies the right Node.js version is in the environment
node -v # should print \`${release.versionWithPrefix}\`
# verifies the right NPM version is in the environment
npm -v # should print \`${release.npm}\``;
snippets.CHOCO = dedent`
# NOTE:
# Chocolatey is not a Node.js package manager. Please ensure it is already installed
# on your system. Follow official instructions at https://chocolatey.org/
# Chocolatey is not officially maintained by the Node.js project and might not
# support the ${release.versionWithPrefix} version of Node.js
# download and install Node.js
choco install nodejs${release.isLts ? '-lts' : ''} --version="${release.version}"
# verifies the right Node.js version is in the environment
node -v # should print \`${release.major}\`
# verifies the right NPM version is in the environment
npm -v # should print \`${release.npm}\``;
}
return snippets;
};