refactor: knowledge base database engine
This commit is contained in:
@@ -9,29 +9,34 @@ exports.default = async function (context) {
|
||||
const arch = context.arch
|
||||
|
||||
if (platform === 'mac') {
|
||||
const nodeModulesPath = path.join(
|
||||
const node_modules_path = path.join(
|
||||
context.appOutDir,
|
||||
'Cherry Studio.app',
|
||||
'Contents',
|
||||
'Resources',
|
||||
'app.asar.unpacked',
|
||||
'node_modules',
|
||||
'@libsql'
|
||||
'node_modules'
|
||||
)
|
||||
|
||||
keepLibsqlNodeModules(nodeModulesPath, arch === Arch.arm64 ? ['darwin-arm64'] : ['darwin-x64'])
|
||||
removeDifferentArchNodeFiles(
|
||||
node_modules_path,
|
||||
'@lancedb',
|
||||
arch === Arch.arm64 ? ['lancedb-darwin-arm64'] : ['lancedb-darwin-x64']
|
||||
)
|
||||
}
|
||||
|
||||
if (platform === 'linux') {
|
||||
const nodeModulesPath = path.join(context.appOutDir, 'resources', 'app.asar.unpacked', 'node_modules', '@libsql')
|
||||
keepLibsqlNodeModules(
|
||||
nodeModulesPath,
|
||||
arch === Arch.arm64 ? ['linux-arm64-gnu', 'linux-arm64-musl'] : ['linux-x64-gnu', 'linux-x64-musl']
|
||||
)
|
||||
const node_modules_path = path.join(context.appOutDir, 'resources', 'app.asar.unpacked', 'node_modules')
|
||||
const _arch =
|
||||
arch === Arch.arm64
|
||||
? ['lancedb-linux-arm64-gnu', 'lancedb-linux-arm64-musl']
|
||||
: ['lancedb-linux-x64-gnu', 'lancedb-linux-x64-musl']
|
||||
removeDifferentArchNodeFiles(node_modules_path, '@lancedb', _arch)
|
||||
}
|
||||
}
|
||||
|
||||
function keepLibsqlNodeModules(modulePath, arch) {
|
||||
function removeDifferentArchNodeFiles(nodeModulesPath, packageName, arch) {
|
||||
const modulePath = path.join(nodeModulesPath, packageName)
|
||||
const dirs = fs.readdirSync(modulePath)
|
||||
dirs
|
||||
.filter((dir) => !arch.includes(dir))
|
||||
|
||||
28
scripts/build-npm.js
Normal file
28
scripts/build-npm.js
Normal file
@@ -0,0 +1,28 @@
|
||||
const { downloadNpmPackage } = require('./utils')
|
||||
|
||||
async function downloadNpm(platform) {
|
||||
if (!platform || platform === 'mac') {
|
||||
downloadNpmPackage(
|
||||
'@lancedb/lancedb-darwin-arm64',
|
||||
'https://registry.npmjs.org/@lancedb/lancedb-darwin-arm64/-/lancedb-darwin-arm64-0.14.0.tgz'
|
||||
)
|
||||
downloadNpmPackage(
|
||||
'@lancedb/lancedb-darwin-x64',
|
||||
'https://registry.npmjs.org/@lancedb/lancedb-darwin-x64/-/lancedb-darwin-x64-0.14.0.tgz'
|
||||
)
|
||||
}
|
||||
|
||||
if (!platform || platform === 'linux') {
|
||||
downloadNpmPackage(
|
||||
'@lancedb/lancedb-linux-arm64-gnu',
|
||||
'https://registry.npmjs.org/@lancedb/lancedb-linux-arm64-gnu/-/lancedb-linux-arm64-gnu-0.14.0.tgz'
|
||||
)
|
||||
downloadNpmPackage(
|
||||
'@lancedb/lancedb-linux-x64-gnu',
|
||||
'https://registry.npmjs.org/@lancedb/lancedb-linux-x64-gnu/-/lancedb-linux-x64-gnu-0.14.0.tgz'
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
const platformArg = process.argv[2]
|
||||
downloadNpm(platformArg)
|
||||
@@ -1,14 +0,0 @@
|
||||
const { downloadNpmPackage } = require('./utils')
|
||||
|
||||
async function downloadNpm(platform) {
|
||||
if (!platform || platform === 'darwin') {
|
||||
downloadNpmPackage('@libsql', '0.4.7', 'darwin', ['arm64', 'x64'])
|
||||
}
|
||||
|
||||
if (!platform || platform === 'linux') {
|
||||
downloadNpmPackage('@libsql', '0.4.7', 'linux', ['arm64-gnu', 'x64-gnu'])
|
||||
}
|
||||
}
|
||||
|
||||
const platformArg = process.argv[2]
|
||||
downloadNpm(platformArg)
|
||||
@@ -2,37 +2,33 @@ const fs = require('fs')
|
||||
const path = require('path')
|
||||
const os = require('os')
|
||||
|
||||
function downloadNpmPackage(package, version, platform, architectures = ['x64', 'arm64']) {
|
||||
function downloadNpmPackage(packageName, url) {
|
||||
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'npm-download-'))
|
||||
|
||||
for (const arch of architectures) {
|
||||
const targetDir = path.join('./node_modules/', package, `${platform}-${arch}`)
|
||||
const targetDir = path.join('./node_modules/', packageName)
|
||||
const filename = packageName.replace('/', '-') + '.tgz'
|
||||
|
||||
// Skip if directory already exists
|
||||
if (fs.existsSync(targetDir)) {
|
||||
console.log(`${targetDir} already exists, skipping download...`)
|
||||
continue
|
||||
}
|
||||
|
||||
const filename = path.join(tempDir, `${platform}-${arch}-${version}.tgz`)
|
||||
const url = `https://registry.npmjs.org/${package}/${platform}-${arch}/-/${platform}-${arch}-${version}.tgz`
|
||||
|
||||
try {
|
||||
console.log(`Downloading ${filename}...`, url)
|
||||
const { execSync } = require('child_process')
|
||||
execSync(`curl --fail -o ${filename} ${url}`)
|
||||
|
||||
console.log(`Extracting ${filename}...`)
|
||||
execSync(`tar -xvf ${filename}`)
|
||||
execSync(`rm -rf ${filename}`)
|
||||
execSync(`mv package ${targetDir}`)
|
||||
} catch (error) {
|
||||
console.error(`Error processing ${filename}: ${error.message}`)
|
||||
if (fs.existsSync(filename)) {
|
||||
fs.unlinkSync(filename)
|
||||
}
|
||||
throw error
|
||||
// Skip if directory already exists
|
||||
if (fs.existsSync(targetDir)) {
|
||||
console.log(`${targetDir} already exists, skipping download...`)
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
console.log(`Downloading ${packageName}...`, url)
|
||||
const { execSync } = require('child_process')
|
||||
execSync(`curl --fail -o ${filename} ${url}`)
|
||||
|
||||
console.log(`Extracting ${filename}...`)
|
||||
execSync(`tar -xvf ${filename}`)
|
||||
execSync(`rm -rf ${filename}`)
|
||||
execSync(`mv package ${targetDir}`)
|
||||
} catch (error) {
|
||||
console.error(`Error processing ${packageName}: ${error.message}`)
|
||||
if (fs.existsSync(filename)) {
|
||||
fs.unlinkSync(filename)
|
||||
}
|
||||
throw error
|
||||
}
|
||||
|
||||
fs.rmSync(tempDir, { recursive: true, force: true })
|
||||
|
||||
Reference in New Issue
Block a user