Migrated to kiwix-serve
Some checks failed
Publish Library / Build NPM Project (push) Failing after 21s
Publish Library / Tag Version (push) Has been skipped

This commit is contained in:
2026-08-24 20:05:56 -04:00
parent 7d376c90b4
commit db2b334ed6
10 changed files with 545 additions and 723 deletions

View File

@@ -11,9 +11,7 @@ const VERSION = '3.8.1';
const BASE_URL = 'https://download.kiwix.org/release/kiwix-tools';
const PLATFORM_MAP = {linux: 'linux', darwin: 'macos', win32: 'win'};
const BIN_NAME = process.platform === 'win32' ? 'kiwix-search.exe' : 'kiwix-search';
const BIN_DIR = path.join(__dirname, '..', 'bin'); // project root/bin
const BIN_PATH = path.join(BIN_DIR, BIN_NAME);
/** Download a file, following redirects. */
function download(url, dest) {
@@ -63,22 +61,16 @@ async function downloadAndExtract() {
console.log('Extracting...');
execFileSync('tar', ['-xf', archivePath, '-C', tmpDir]); // bsdtar handles zip too
const extractedBin = findFile(tmpDir, BIN_NAME);
if (!extractedBin) throw new Error(`Could not find ${BIN_NAME} in extracted archive`);
const extractedDir = path.dirname(extractedBin);
await fs.promises.mkdir(BIN_DIR, {recursive: true});
// Copy the binary plus any DLLs sitting alongside it (Windows deps)
for (const entry of await fs.promises.readdir(extractedDir)) {
if (entry === BIN_NAME || entry.toLowerCase().endsWith('.dll')) {
await fs.promises.copyFile(path.join(extractedDir, entry), path.join(BIN_DIR, entry));
}
for (const entry of await fs.promises.readdir(tmpDir)) {
if(!/\.(tar|gz|zip)$/.test(entry)) await fs.promises.copyFile(path.join(tmpDir, entry), path.join(BIN_DIR, entry));
if(process.platform !== 'win32') await fs.promises.chmod(BIN_DIR, 0o755, {recursive: true});
}
if (process.platform !== 'win32') await fs.promises.chmod(BIN_PATH, 0o755);
await fs.promises.rm(tmpDir, {recursive: true, force: true});
console.log('Installed to:', BIN_PATH);
console.log('Installed to:', BIN_DIR);
}
downloadAndExtract().catch(err => {