|
| 1 | +import * as fs from "fs/promises"; |
| 2 | +import * as path from "path"; |
| 3 | + |
| 4 | +const copyFiles = async (srcDir: string, destDir: string) => { |
| 5 | + await fs.mkdir(destDir, { recursive: true }); |
| 6 | + const files = await fs.readdir(srcDir); |
| 7 | + for (const file of files) { |
| 8 | + if (file.startsWith(".")) { |
| 9 | + continue; |
| 10 | + } |
| 11 | + const srcFile = path.join(srcDir, file); |
| 12 | + const destFile = path.join(destDir, file); |
| 13 | + const stat = await fs.stat(srcFile); |
| 14 | + if (stat.isFile()) { |
| 15 | + await fs.copyFile(srcFile, destFile); |
| 16 | + console.log(`Copied ${srcFile} to ${destFile}`); |
| 17 | + } |
| 18 | + } |
| 19 | +}; |
| 20 | + |
| 21 | +async function main() { |
| 22 | + // pg_dump is not yet available from CI, so we download as precompiled |
| 23 | + try { |
| 24 | + await fs.access("./release"); |
| 25 | + } catch { |
| 26 | + await fs.mkdir("./release", { recursive: true }); |
| 27 | + } |
| 28 | + |
| 29 | + try { |
| 30 | + await fs.access("./release/pg_dump.wasm"); |
| 31 | + console.log("pg_dump.wasm already exists in release directory"); |
| 32 | + } catch { |
| 33 | + const response = await fetch("https://static.pglite.dev/pg_tools/pg_dump_26-11-24.wasm"); |
| 34 | + const wasmBuffer = await response.arrayBuffer(); |
| 35 | + |
| 36 | + await fs.writeFile("./release/pg_dump.wasm", new Uint8Array(wasmBuffer)); |
| 37 | + console.log("Downloaded pg_dump.wasm to release directory"); |
| 38 | + } |
| 39 | + |
| 40 | + await copyFiles("./release", "./dist"); |
| 41 | +} |
| 42 | + |
| 43 | +main(); |
0 commit comments