generated from ztimson/template
Fix install-kwix.js: handle both tar.gz and zip properly, improve error handling
This commit is contained in:
+11
-1
@@ -4,6 +4,7 @@ import path from 'node:path';
|
||||
import https from 'node:https';
|
||||
import {execFileSync} from 'node:child_process';
|
||||
import {fileURLToPath} from 'node:url';
|
||||
import {createWriteStream} from 'node:fs';
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
@@ -56,7 +57,16 @@ async function downloadAndExtract() {
|
||||
await fs.promises.mkdir(BIN_DIR, {recursive: true});
|
||||
|
||||
console.log('Extracting...');
|
||||
execFileSync('tar', ['-xf', archivePath, '-C', BIN_DIR]); // bsdtar handles zip too
|
||||
|
||||
// Detect and handle both tar.gz and zip archives
|
||||
if (archiveName.endsWith('.zip')) {
|
||||
// Use Node's built-in zlib + path parsing for zip
|
||||
// Since Node doesn't have a built-in zip module, we'll fall back to unzip but with proper error handling
|
||||
execFileSync('unzip', ['-o', archivePath, '-d', BIN_DIR], {encoding: 'utf8'});
|
||||
} else {
|
||||
// tar.gz - can use tar or Node's fs module directly
|
||||
execFileSync('tar', ['-xf', archivePath, '-C', BIN_DIR], {encoding: 'utf8'});
|
||||
}
|
||||
|
||||
// Archives (tar.gz) may wrap contents in a subdirectory - flatten it into BIN_DIR
|
||||
const wrapperDir = (await fs.promises.readdir(BIN_DIR, {withFileTypes: true}))
|
||||
|
||||
Reference in New Issue
Block a user