( fullPath: string, resolveUrl: () => Promise<string>, )
| 68 | } |
| 69 | |
| 70 | async function downloadAsset( |
| 71 | fullPath: string, |
| 72 | resolveUrl: () => Promise<string>, |
| 73 | ) { |
| 74 | try { |
| 75 | const result = await stat(fullPath); |
| 76 | // Skip existing files |
| 77 | if (result.isFile()) return; |
| 78 | } catch { |
| 79 | // ignore |
| 80 | } |
| 81 | const url = await resolveUrl(); |
| 82 | let body: ReadableStream; |
| 83 | if (url.startsWith('/')) { |
| 84 | body = createStreamBody(createReadStream(url)); |
| 85 | } else { |
| 86 | const res = await fetch(url); |
| 87 | if (!res.ok || !res.body) throw new Error(`Failed to download: ${url}`); |
| 88 | body = res.body; |
| 89 | } |
| 90 | await mkdir(dirname(fullPath), { recursive: true }); |
| 91 | await pipeline(body, createWriteStream(fullPath)); |
| 92 | } |
| 93 | |
| 94 | async function main() { |
| 95 | await fetchAssets({ verbose: true }); |
no test coverage detected