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,18 +31,13 @@ function download(url, dest) {
});
}
/** Recursively search a directory for a file by name. */
function findFile(dir, name) {
/** Recursively chmod all files under a directory. */
function chmodRecursive(dir, mode) {
for (const entry of fs.readdirSync(dir, {withFileTypes: true})) {
const full = path.join(dir, entry.name);
if (entry.isDirectory()) {
const found = findFile(full, name);
if (found) return found;
} else if (entry.name === name) {
return full;
}
if (entry.isDirectory()) chmodRecursive(full, mode);
else fs.chmodSync(full, mode);
}
return null;
}
async function downloadAndExtract() {
@@ -58,17 +53,24 @@ async function downloadAndExtract() {
console.log('Downloading kiwix-tools from:', url);
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});
// Copy the binary plus any DLLs sitting alongside it (Windows deps)
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});
console.log('Extracting...');
execFileSync('tar', ['-xf', archivePath, '-C', BIN_DIR]); // bsdtar handles zip too
// 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});
console.log('Installed to:', BIN_DIR);
}