fixed install
All checks were successful
Publish Library / Build NPM Project (push) Successful in 16s
Publish Library / Tag Version (push) Successful in 8s

This commit is contained in:
2026-08-24 20:29:31 -04:00
parent db2b334ed6
commit 7d85031181

View File

@@ -31,19 +31,14 @@ function download(url, dest) {
}); });
} }
/** Recursively search a directory for a file by name. */ /** Recursively chmod all files under a directory. */
function findFile(dir, name) { function chmodRecursive(dir, mode) {
for (const entry of fs.readdirSync(dir, {withFileTypes: true})) { for (const entry of fs.readdirSync(dir, {withFileTypes: true})) {
const full = path.join(dir, entry.name); const full = path.join(dir, entry.name);
if (entry.isDirectory()) { if (entry.isDirectory()) chmodRecursive(full, mode);
const found = findFile(full, name); else fs.chmodSync(full, mode);
if (found) return found;
} else if (entry.name === name) {
return full;
} }
} }
return null;
}
async function downloadAndExtract() { async function downloadAndExtract() {
const platformName = PLATFORM_MAP[process.platform]; const platformName = PLATFORM_MAP[process.platform];
@@ -58,16 +53,23 @@ async function downloadAndExtract() {
console.log('Downloading kiwix-tools from:', url); console.log('Downloading kiwix-tools from:', url);
await download(url, archivePath); await download(url, archivePath);
console.log('Extracting...');
execFileSync('tar', ['-xf', archivePath, '-C', tmpDir]); // bsdtar handles zip too
await fs.promises.mkdir(BIN_DIR, {recursive: true}); await fs.promises.mkdir(BIN_DIR, {recursive: true});
// Copy the binary plus any DLLs sitting alongside it (Windows deps) console.log('Extracting...');
for (const entry of await fs.promises.readdir(tmpDir)) { execFileSync('tar', ['-xf', archivePath, '-C', BIN_DIR]); // bsdtar handles zip too
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}); // Archives (tar.gz) may wrap contents in a subdirectory - flatten it into BIN_DIR
const wrapperDir = (await fs.promises.readdir(BIN_DIR, {withFileTypes: true}))
.find(e => e.isDirectory() && e.name.startsWith('kiwix-tools_'));
if (wrapperDir) {
const wrapperPath = path.join(BIN_DIR, wrapperDir.name);
for (const entry of await fs.promises.readdir(wrapperPath)) {
await fs.promises.rename(path.join(wrapperPath, entry), path.join(BIN_DIR, entry));
} }
await fs.promises.rmdir(wrapperPath);
}
if (process.platform !== 'win32') chmodRecursive(BIN_DIR, 0o755);
await fs.promises.rm(tmpDir, {recursive: true, force: true}); await fs.promises.rm(tmpDir, {recursive: true, force: true});
console.log('Installed to:', BIN_DIR); console.log('Installed to:', BIN_DIR);