generated from ztimson/template
Fix install-kwix.js: handle both tar.gz and zip properly, improve error handling
This commit is contained in:
+12
-2
@@ -4,6 +4,7 @@ import path from 'node:path';
|
|||||||
import https from 'node:https';
|
import https from 'node:https';
|
||||||
import {execFileSync} from 'node:child_process';
|
import {execFileSync} from 'node:child_process';
|
||||||
import {fileURLToPath} from 'node:url';
|
import {fileURLToPath} from 'node:url';
|
||||||
|
import {createWriteStream} from 'node:fs';
|
||||||
|
|
||||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||||
|
|
||||||
@@ -56,7 +57,16 @@ async function downloadAndExtract() {
|
|||||||
await fs.promises.mkdir(BIN_DIR, {recursive: true});
|
await fs.promises.mkdir(BIN_DIR, {recursive: true});
|
||||||
|
|
||||||
console.log('Extracting...');
|
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
|
// Archives (tar.gz) may wrap contents in a subdirectory - flatten it into BIN_DIR
|
||||||
const wrapperDir = (await fs.promises.readdir(BIN_DIR, {withFileTypes: true}))
|
const wrapperDir = (await fs.promises.readdir(BIN_DIR, {withFileTypes: true}))
|
||||||
@@ -78,4 +88,4 @@ async function downloadAndExtract() {
|
|||||||
downloadAndExtract().catch(err => {
|
downloadAndExtract().catch(err => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
}).finally(() => process.exit());
|
}).finally(() => process.exit());
|
||||||
Reference in New Issue
Block a user