MCPcopy
hub / github.com/serverless/serverless / install

Method install

packages/sf-core-installer/binary.js:138–192  ·  view source on GitHub ↗
(suppressLogs = false)

Source from the content-addressed store, hash-verified

136 }
137
138 install(suppressLogs = false) {
139 if (this.exists()) {
140 if (!suppressLogs) {
141 console.error(
142 `${this.name} is already installed, skipping installation.`,
143 )
144 }
145 return Promise.resolve()
146 }
147
148 if (existsSync(this.installDirectory)) {
149 rimraf.sync(this.installDirectory)
150 }
151
152 mkdirSync(this.installDirectory, { recursive: true })
153
154 if (!suppressLogs) {
155 console.error(`Downloading release from ${this.url}`)
156 }
157
158 process.on('SIGINT', () => {
159 error('Could not download Serverless')
160 this.removeBinary()
161 })
162
163 process.on('SIGTERM', () => {
164 error('Could not download Serverless')
165 this.removeBinary()
166 })
167
168 const proxyUrl = getProxyUrl(this.url)
169 const fetchOptions = proxyUrl
170 ? { dispatcher: new ProxyAgent(proxyUrl) }
171 : {}
172
173 return fetch(this.url, fetchOptions)
174 .then((res) => {
175 if (!res.ok) {
176 throw new Error(`HTTP ${res.status}: ${res.statusText}`)
177 }
178 return res.arrayBuffer()
179 })
180 .then((buffer) => {
181 writeFileSync(this.binaryPath, Buffer.from(buffer), { mode: 0o755 })
182 })
183 .then(() => {
184 if (!suppressLogs) {
185 console.error(`${this.name} has been installed!`)
186 }
187 })
188 .catch((e) => {
189 error(`Error fetching release: ${e.message}`)
190 this.removeBinary()
191 })
192 }
193
194 run() {
195 const promise = !this.exists() ? this.install(true) : Promise.resolve()

Callers 2

runMethod · 0.95
installFunction · 0.80

Calls 7

existsMethod · 0.95
removeBinaryMethod · 0.95
writeFileSyncFunction · 0.85
errorMethod · 0.80
resolveMethod · 0.80
errorFunction · 0.70
getProxyUrlFunction · 0.70

Tested by

no test coverage detected