refactor download node-sqlite to common
This commit is contained in:
parent
1724b1343a
commit
3722b8c4f8
|
@ -8,41 +8,34 @@ const {
|
|||
const { downloadRipgrep } = require("./ripgrep");
|
||||
const { TARGET_TO_LANCEDB } = require("../utils/targets");
|
||||
const fs = require("fs");
|
||||
const {
|
||||
downloadSqlite,
|
||||
} = require("../../extensions/vscode/scripts/install-copy-sqlite-esbuild");
|
||||
|
||||
async function downloadNodeSqlite(target, targetDir) {
|
||||
return new Promise((resolve) => {
|
||||
const [currentPlatform, currentArch] = autodetectPlatformAndArch();
|
||||
const [currentPlatform, currentArch] = autodetectPlatformAndArch();
|
||||
|
||||
// Download and unzip prebuilt sqlite3 binary for the target
|
||||
console.log("[info] Downloading node-sqlite3");
|
||||
// Download and unzip prebuilt sqlite3 binary for the target
|
||||
console.log("[info] Downloading node-sqlite3");
|
||||
|
||||
const downloadUrl =
|
||||
// node-sqlite3 doesn't have a pre-built binary for win32-arm64
|
||||
target === "win32-arm64"
|
||||
? "https://continue-server-binaries.s3.us-west-1.amazonaws.com/win32-arm64/node_sqlite3.tar.gz"
|
||||
: `https://github.com/TryGhost/node-sqlite3/releases/download/v5.1.7/sqlite3-v5.1.7-napi-v6-${
|
||||
target
|
||||
}.tar.gz`;
|
||||
await downloadSqlite(target, `${targetDir}/build.tar.gz`);
|
||||
|
||||
execCmdSync(`curl -L -o ${targetDir}/build.tar.gz ${downloadUrl}`);
|
||||
execCmdSync(`cd ${targetDir} && tar -xvzf build.tar.gz`);
|
||||
execCmdSync(`cd ${targetDir} && tar -xvzf build.tar.gz`);
|
||||
|
||||
// Copy to build directory for testing
|
||||
try {
|
||||
const [platform, arch] = target.split("-");
|
||||
if (platform === currentPlatform && arch === currentArch) {
|
||||
fs.copyFileSync(
|
||||
`${targetDir}/build/Release/node_sqlite3.node`,
|
||||
`build/node_sqlite3.node`,
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
console.log("[warn] Could not copy node_sqlite to build");
|
||||
console.log(error);
|
||||
// Copy to build directory for testing
|
||||
try {
|
||||
const [platform, arch] = target.split("-");
|
||||
if (platform === currentPlatform && arch === currentArch) {
|
||||
fs.copyFileSync(
|
||||
`${targetDir}/build/Release/node_sqlite3.node`,
|
||||
`build/node_sqlite3.node`,
|
||||
);
|
||||
}
|
||||
fs.unlinkSync(`${targetDir}/build.tar.gz`);
|
||||
resolve();
|
||||
});
|
||||
} catch (error) {
|
||||
console.log("[warn] Could not copy node_sqlite to build");
|
||||
console.log(error);
|
||||
}
|
||||
fs.unlinkSync(`${targetDir}/build.tar.gz`);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
const { fork, execSync } = require("child_process");
|
||||
const { fork } = require("child_process");
|
||||
const fs = require("fs");
|
||||
const https = require("https");
|
||||
const path = require("path");
|
||||
|
@ -80,23 +80,27 @@ async function downloadFile(url, outputPath, maxRedirects = 5) {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} target platform specific target
|
||||
* @param {string} targetDir the directory to download into
|
||||
*/
|
||||
async function downloadSqlite(target, targetDir) {
|
||||
const downloadUrl =
|
||||
// node-sqlite3 doesn't have a pre-built binary for win32-arm64
|
||||
target === "win32-arm64"
|
||||
? "https://continue-server-binaries.s3.us-west-1.amazonaws.com/win32-arm64/node_sqlite3.tar.gz"
|
||||
: `https://github.com/TryGhost/node-sqlite3/releases/download/v5.1.7/sqlite3-v5.1.7-napi-v6-${
|
||||
target
|
||||
}.tar.gz`;
|
||||
await downloadFile(downloadUrl, targetDir);
|
||||
}
|
||||
|
||||
async function installAndCopySqlite(target) {
|
||||
// Replace the installed with pre-built
|
||||
console.log("[info] Downloading pre-built sqlite3 binary");
|
||||
rimrafSync("../../core/node_modules/sqlite3/build");
|
||||
const downloadUrl = {
|
||||
"darwin-arm64":
|
||||
"https://github.com/TryGhost/node-sqlite3/releases/download/v5.1.7/sqlite3-v5.1.7-napi-v6-darwin-arm64.tar.gz",
|
||||
"linux-arm64":
|
||||
"https://github.com/TryGhost/node-sqlite3/releases/download/v5.1.7/sqlite3-v5.1.7-napi-v3-linux-arm64.tar.gz",
|
||||
// node-sqlite3 doesn't have a pre-built binary for win32-arm64
|
||||
"win32-arm64":
|
||||
"https://continue-server-binaries.s3.us-west-1.amazonaws.com/win32-arm64/node_sqlite3.tar.gz",
|
||||
}[target];
|
||||
await downloadFile(
|
||||
downloadUrl,
|
||||
"../../core/node_modules/sqlite3/build.tar.gz",
|
||||
);
|
||||
await downloadSqlite(target, "../../core/node_modules/sqlite3/build.tar.gz");
|
||||
execCmdSync("cd ../../core/node_modules/sqlite3 && tar -xvzf build.tar.gz");
|
||||
fs.unlinkSync("../../core/node_modules/sqlite3/build.tar.gz");
|
||||
}
|
||||
|
@ -179,6 +183,7 @@ async function copyEsbuild(target) {
|
|||
}
|
||||
|
||||
module.exports = {
|
||||
downloadSqlite,
|
||||
copySqlite,
|
||||
copyEsbuild,
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue