|
1 | 1 | import { cpus } from 'os'
|
2 | 2 | import path from 'path'
|
3 | 3 |
|
| 4 | +import { getDeployStore } from '@netlify/blobs' |
4 | 5 | import { NetlifyPluginConstants } from '@netlify/build'
|
5 | 6 | import { copy, move, remove } from 'fs-extra/esm'
|
6 | 7 | import { globby } from 'globby'
|
7 | 8 | import pLimit from 'p-limit'
|
8 | 9 |
|
9 |
| -import { netliBlob } from './blobs.js' |
10 | 10 | import { buildCacheValue } from './cache.js'
|
11 | 11 | import { BUILD_DIR } from './constants.js'
|
12 | 12 |
|
@@ -45,18 +45,28 @@ const getPrerenderedContent = async (cwd: string, get = true): Promise<string[]>
|
45 | 45 | */
|
46 | 46 | export const storePrerenderedContent = async ({
|
47 | 47 | NETLIFY_API_TOKEN,
|
| 48 | + NETLIFY_API_HOST, |
48 | 49 | SITE_ID,
|
49 |
| -}: { |
50 |
| - NETLIFY_API_TOKEN: string |
51 |
| - SITE_ID: string |
52 |
| -}) => { |
53 |
| - const deployID = `${process.env.DEPLOY_ID}` |
54 |
| - const blob = netliBlob(NETLIFY_API_TOKEN, deployID, SITE_ID) |
| 50 | +}: NetlifyPluginConstants & { NETLIFY_API_TOKEN: string; NETLIFY_API_HOST: string }) => { |
| 51 | + if (!process.env.DEPLOY_ID) { |
| 52 | + // TODO: maybe change to logging |
| 53 | + throw new Error( |
| 54 | + 'Could not initizlize the Blob storage as the `DEPLOY_ID` environment variable is missing!', |
| 55 | + ) |
| 56 | + } |
| 57 | + |
| 58 | + const blob = getDeployStore({ |
| 59 | + deployID: process.env.DEPLOY_ID, |
| 60 | + siteID: SITE_ID, |
| 61 | + token: NETLIFY_API_TOKEN, |
| 62 | + apiURL: `https://${NETLIFY_API_HOST}`, |
| 63 | + }) |
| 64 | + |
55 | 65 | // todo: Check out setFiles within Blobs.js to see how to upload files to blob storage
|
56 | 66 | const limit = pLimit(Math.max(2, cpus().length))
|
57 | 67 |
|
58 | 68 | const prerenderedContent = await getPrerenderedContent(`${BUILD_DIR}/.next`)
|
59 |
| - return Promise.all( |
| 69 | + return await Promise.all( |
60 | 70 | prerenderedContent.map(async (rawPath: string) => {
|
61 | 71 | // TODO: test this with files that have a double extension
|
62 | 72 | const ext = path.extname(rawPath)
|
|
0 commit comments