|
| 1 | +import { writeFile } from "node:fs/promises" |
| 2 | +import { decodeZip, encodeZip } from "@php-wasm/stream-compression" |
| 3 | + |
| 4 | +const revision = "af451895a9429895e3ad4d9b4e073bfd88873745" |
| 5 | +const archiveUrl = `https://codeload.github.com/Automattic/markdown-database-integration/zip/${revision}` |
| 6 | +const output = new URL("../packages/runtime-cloudflare/assets/markdown-database-integration-runtime.zip", import.meta.url) |
| 7 | +const response = await fetch(archiveUrl) |
| 8 | +if (!response.ok || !response.body) throw new Error(`Unable to fetch Markdown Database Integration: ${response.status}.`) |
| 9 | + |
| 10 | +const runtimePaths = new Set([ |
| 11 | + "db.php", |
| 12 | + "inc/class-wp-markdown-db.php", |
| 13 | + "inc/class-wp-markdown-driver.php", |
| 14 | + "inc/class-wp-markdown-frontmatter-profiles.php", |
| 15 | + "inc/class-wp-markdown-loader.php", |
| 16 | + "inc/class-wp-markdown-search.php", |
| 17 | + "inc/class-wp-markdown-storage.php", |
| 18 | + "inc/class-wp-markdown-write-engine.php", |
| 19 | +]) |
| 20 | +const runtimeFiles = [] |
| 21 | +for await (const entry of decodeZip(response.body)) { |
| 22 | + const separator = entry.name.indexOf("/") |
| 23 | + const relative = separator === -1 ? "" : entry.name.slice(separator + 1) |
| 24 | + if (!runtimePaths.has(relative)) continue |
| 25 | + runtimeFiles.push(new File([await entry.arrayBuffer()], relative, { lastModified: 0 })) |
| 26 | +} |
| 27 | +if (runtimeFiles.length !== runtimePaths.size) throw new Error(`Expected ${runtimePaths.size} MDI runtime files, received ${runtimeFiles.length}.`) |
| 28 | + |
| 29 | +const archive = await new Response(encodeZip(runtimeFiles)).arrayBuffer() |
| 30 | +await writeFile(output, new Uint8Array(archive)) |
| 31 | +console.log(`Bundled ${runtimeFiles.length} MDI runtime files from ${revision} (${archive.byteLength} bytes).`) |
0 commit comments