From 6a18838d12c69f13733966b04dc1b766f113da02 Mon Sep 17 00:00:00 2001 From: benk10 Date: Sun, 6 Oct 2024 17:15:23 +0400 Subject: [PATCH] Fix HWI download on windows --- package.json | 2 +- scripts/get-hwi.ts | 21 ++++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 7470895..674c3f6 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "lint:fix": "eslint 'src/**/*.{js,jsx,ts,tsx}' --fix", "format": "prettier --write 'src/**/*.{js,jsx,ts,tsx,json,css,md}'", "format:check": "prettier --check 'src/**/*.{js,jsx,ts,tsx,json,css,md}'", - "get-hwi": "rimraf src-tauri/binaries/hwi-* && tsx scripts/get-hwi.ts", + "get-hwi": "tsx scripts/get-hwi.ts --cleanup", "postinstall": "tsx scripts/get-hwi.ts", "tauri:lint": "cd src-tauri && cargo clippy --all-targets --all-features -- -D warnings", "tauri:format": "cd src-tauri && cargo fmt", diff --git a/scripts/get-hwi.ts b/scripts/get-hwi.ts index 04f52cb..ebd59a7 100644 --- a/scripts/get-hwi.ts +++ b/scripts/get-hwi.ts @@ -182,10 +182,19 @@ async function shouldDownloadBinaries(): Promise { } } -async function main() { +async function main(shouldCleanup: boolean = false) { + console.log("Starting HWI binary process..."); try { - const isEmpty = await shouldDownloadBinaries(); - if (!isEmpty) { + if (shouldCleanup) { + console.log("Cleanup flag set. Cleaning up old binaries..."); + await cleanDirectory(BINARY_DIR); + console.log("Cleanup completed."); + } else { + console.log("Skipping cleanup."); + } + + const shouldDownload = await shouldDownloadBinaries(); + if (!shouldDownload) { console.log( "src-tauri/binaries already has all HWI binaries. Skipping download.", ); @@ -282,8 +291,10 @@ async function main() { } } -if (import.meta.url === `file://${encodeURI(process.argv[1])}`) { - main().catch((error) => { +if (import.meta.url.startsWith("file:")) { + const args = process.argv.slice(2); + const shouldCleanup = args.includes("--cleanup"); + main(shouldCleanup).catch((error) => { console.error("An error occurred:", error); process.exit(1); });