-
Notifications
You must be signed in to change notification settings - Fork 57
/
pre-download-build.js
111 lines (96 loc) · 3 KB
/
pre-download-build.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/**
* Copyright 2023 Continue
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const fs = require("fs");
const { execSync } = require("child_process");
fs.mkdirSync("bin", { recursive: true });
const targetToLanceDb = {
"darwin-arm64": "@lancedb/vectordb-darwin-arm64",
"darwin-x64": "@lancedb/vectordb-darwin-x64",
"linux-arm64": "@lancedb/vectordb-linux-arm64-gnu",
"linux-x64": "@lancedb/vectordb-linux-x64-gnu",
"win32-x64": "@lancedb/vectordb-win32-x64-msvc",
};
const platforms = ["darwin", "linux", "win32"];
const architectures = ["x64", "arm64"];
function download(base) {
let targets = platforms.flatMap((platform) =>
architectures.map((arch) => `${platform}-${arch}`),
);
console.log("[info] Building binaries with pkg...");
for (const target of targets) {
const targetDir = `bin/${target}`;
fs.mkdirSync(targetDir, { recursive: true });
console.log(`[info] Building ${target}...`);
// execSync(
// `npx pkg --no-bytecode --public-packages "*" --public pkgJson/${target} --out-path ${targetDir}`,
// );
// Download and unzip prebuilt sqlite3 binary for the target
const downloadUrl = `${base}/releases/download/v5.1.7/sqlite3-v5.1.7-napi-v6-${
target === "win32-arm64" ? "win32-ia32" : target
}.tar.gz`;
execSync(`curl -L -o ${targetDir}/build.tar.gz ${downloadUrl}`);
execSync(`cd ${targetDir} && tar -xvzf build.tar.gz`);
fs.copyFileSync(
`${targetDir}/build/Release/node_sqlite3.node`,
`${targetDir}/node_sqlite3.node`,
);
fs.unlinkSync(`${targetDir}/build.tar.gz`);
fs.rmSync(`${targetDir}/build`, {
recursive: true,
force: true,
});
}
console.log("[info] Downloading prebuilt lancedb...");
for (const target of targets) {
if (targetToLanceDb[target]) {
console.log(`[info] Downloading ${target}...`);
execSync(`npm install -f ${targetToLanceDb[target]}@0.4.20 --no-save`);
}
}
}
getSqliteRepoUrl().then(repoUrl => {
console.log("[info] Downloading sqlite3 from", repoUrl)
download(repoUrl);
})
function getSqliteRepoUrl() {
const github = 'https://github.com/TryGhost/node-sqlite3'
const gitee = 'https://gitee.com/Ypeng/node-sqlite3' // china proxy repo
// Like any
const promise = new Promise((resolve) => {
let counter = 0;
function fallback() {
counter++;
if (counter === 2) {
resolve(github);
}
}
function ping(url) {
return fetch(url).then(
res => {
if (res.ok) {
resolve(url)
} else {
fallback()
}
},
fallback
)
}
ping(github)
ping(gitee)
})
return promise
}