(target, targetDir)
| 15 | const { fork } = require("child_process"); |
| 16 | |
| 17 | async function downloadNodeSqlite(target, targetDir) { |
| 18 | const [currentPlatform, currentArch] = autodetectPlatformAndArch(); |
| 19 | |
| 20 | // Download and unzip prebuilt sqlite3 binary for the target |
| 21 | console.log("[info] Downloading node-sqlite3"); |
| 22 | |
| 23 | await downloadSqlite(target, `${targetDir}/build.tar.gz`); |
| 24 | |
| 25 | execCmdSync(`cd ${targetDir} && tar -xvzf build.tar.gz`); |
| 26 | |
| 27 | // Copy to build directory for testing |
| 28 | try { |
| 29 | const [platform, arch] = target.split("-"); |
| 30 | if (platform === currentPlatform && arch === currentArch) { |
| 31 | fs.copyFileSync( |
| 32 | `${targetDir}/build/Release/node_sqlite3.node`, |
| 33 | `build/node_sqlite3.node`, |
| 34 | ); |
| 35 | } |
| 36 | } catch (error) { |
| 37 | console.log("[warn] Could not copy node_sqlite to build"); |
| 38 | console.log(error); |
| 39 | } |
| 40 | fs.unlinkSync(`${targetDir}/build.tar.gz`); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * @param {string} target the platform to build for |
no test coverage detected