(args)
| 129 | * @param {DeployArgs} args |
| 130 | */ |
| 131 | export async function deploy(args) { |
| 132 | const authHeaders = buildAuthHeaders(args.apiKey, args.accountEmail); |
| 133 | |
| 134 | logger.progress('Getting zone...'); |
| 135 | let response = await fetch(`${apiBase}/zones/${args.zoneId}`, { |
| 136 | method: 'GET', |
| 137 | headers: authHeaders |
| 138 | }); |
| 139 | if (!response.ok) { |
| 140 | throw new Error( |
| 141 | `GET zone failed.\n${response.status}: ${ |
| 142 | response.statusText |
| 143 | }\n${await response.text()}` |
| 144 | ); |
| 145 | } |
| 146 | /** @type {string} */ |
| 147 | const zoneName = (await response.json()).result.name; |
| 148 | |
| 149 | const site = await getSiteBindings(args); |
| 150 | const kv = await getKVBindings(args); |
| 151 | |
| 152 | logger.progress('Deploying script...'); |
| 153 | const form = new FormData(); |
| 154 | const body_part = args.name; |
| 155 | const metadata = { |
| 156 | body_part, |
| 157 | bindings: [...site.bindings, ...kv.bindings] |
| 158 | }; |
| 159 | form.append('metadata', JSON.stringify(metadata), { |
| 160 | contentType: 'application/json', |
| 161 | filename: 'metadata.json' |
| 162 | }); |
| 163 | if (site.manifest) { |
| 164 | form.append('manifest', site.manifest, { |
| 165 | contentType: 'text/plain', |
| 166 | filename: 'manifest.json' |
| 167 | }); |
| 168 | } |
| 169 | form.append(body_part, args.code, { |
| 170 | contentType: 'application/javascript', |
| 171 | filename: body_part |
| 172 | }); |
| 173 | |
| 174 | response = await fetch( |
| 175 | `${apiBase}/accounts/${args.accountId}/workers/scripts/${args.name}`, |
| 176 | { |
| 177 | method: 'PUT', |
| 178 | headers: Object.assign( |
| 179 | {}, |
| 180 | form.getHeaders(), |
| 181 | buildAuthHeaders(args.apiKey, args.accountEmail) |
| 182 | ), |
| 183 | body: form.getBuffer() |
| 184 | } |
| 185 | ); |
| 186 | |
| 187 | if (!response.ok) { |
| 188 | throw new Error( |
no test coverage detected